Article ID: 140590
Article Last Modified on 11/21/2006
APPLIES TO
- Microsoft Visual Basic 4.0 Standard Edition
- Microsoft Visual Basic 4.0 Professional Edition
- Microsoft Foundation Class Library 4.2, when used with:
- Microsoft Visual C++ 1.5 Professional Edition
- Microsoft Visual C++ 1.51
- Microsoft Visual C++ 1.52 Professional Edition
- Microsoft Visual C++ 2.0 Professional Edition
- Microsoft Visual C++ 4.0 Standard Edition
This article was previously published under Q140590
SYMPTOMS
In an MFC application, AfxThrowOleDispatchException is used to throw an
exception from within an OLE Automation function. When Microsoft Visual
Basic is used as the automation client application, it will not be able to
correctly interpret the error code passed to AfxThrowOleDispatchException.
CAUSE
AfxThrowOleDispatchException constructs and throws a COleDispatchException
object, which is used to handle exceptions specific to the OLE IDispatch
interface. The constructor of COleDispatchException incorrectly initializes
the COleDispatchException object, resulting in the Visual Basic client
being unable to interpret the error code of the exception.
RESOLUTION
To implement the proper behavior for throwing an OLE dispatch exception
from an MFC server, do not use AfxThrowOleDispatchException. Instead,
construct your own COleDispatchException, set m_scError = 0, and throw the
exception yourself as illustrated in the sample code in this article.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products
listed at the beginning of this article. This bug was corrected in
Visual C++ 4.1.
REFERENCES
"Inside OLE" second edition by Kraig Brockschmidt, published by Microsoft
Press, Chapter 14, pages 658 - 660.
Additional query words: kbVC400bug 1.50 1.51 1.52 2.00 2.10 2.20 2.50 2.51 2.52 3.00 3.10 3.20 4.00 2.0 2.1 2.2 4.10
Keywords: kbautomation kbbug kbfix kbnoupdate kbvc410fix KB140590