PRB: How to Use Automation Error Code & Help from Visual BasicLast reviewed: July 10, 1997Article ID: Q122488 |
1.00 1.50 3.00 | 2.00
WINDOWS | WINDOWS NTkbole kbtshoot kbprg kbinterop kbprb The information in this article applies to:
SYMPTOMSVisual Basic version 3.0 does not report automation errors that result from OLE automation exceptions. Instead, it reports an err value of 440 and a description string of "OLE Automation exception." The actual wCode passed by the automation server is lost.
WORKAROUNDThe More Information section in this article explains and illustrates a method you can use to use the error information and help context code returned by Visual Basic version 3.0 to start WinHelp from an MFC OLE automation server.
STATUSThis behavior is by design in Visual Basic version 3.0. Visual Basic for Applications, included in Excel version 5.0 and other Microsoft products, returns the wCode correctly.
MORE INFORMATIONWhen an MFC automation server throws an OLE dispatch exception by calling AfxThrowOleDispatchException, an object of class COleDispatchException is built. Its member variables include an OLE SCODE, a help context, string error description, and wCode (an integer code used by Visual Basic). The only information that the Visual Basic automation controller preserves is the string description. However, the MFC OLE automation server can preserve the information used in the call to AfxThrowOleDispatchException() and expose an additional "Help" method that uses this information to provide help to the user. From within the Visual Basic error handling code, Err is 440, Error(Err) is "OLE Dispatch Exception" and Error$ is the actual string passed by the server.
Sample Code Snippets
/* Compile options needed: standard MFC OLE project generated by AppWizard*/
void CMyObject::Exception() { m_nIDContext = <some context>; m_nSomeCode = <some code>; AfxThrowOleDispatchException(m_nSomeCode,"String",m_nIDContext); } short CMyObject::GetError() { // From here you can use the member variable code // and context to start WinHelp or do whatever // help code you need to do ... AfxGetApp()->WinHelp(m_nIDContext); return m_nSomeCode;}
Sub Command1_Click () On Error GoTo EHandle Dim a As object Set a = CreateObject("TestAuto") ' Next line causes exception: a.exception EHandle: Msg = "The error message for error number " Msg = Msg & Err & " is:" & NL & NL Msg = Msg & """" & Error(Err) & """" MsgBox Msg ' Display message. ' Next line starts WinHelp engine by calling method in server. a.GetError Exit Sub End Sub |
Additional reference words: 1.00 1.50 2.00 2.50 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |