다음을 통해 공유


AfxThrowOleDispatchException

Use this function to throw an exception within an OLE automation function.

void AFXAPI AfxThrowOleDispatchException( 
   WORD wCode, 
   LPCSTR lpszDescription, 
   UINT nHelpID = 0  
); 
void AFXAPI AfxThrowOleDispatchException( 
   WORD wCode, 
   UINT nDescriptionID, 
   UINT nHelpID =   -1  
);

Parameters

  • wCode
    An error code specific to your application.

  • lpszDescription
    Verbal description of the error.

  • nDescriptionID
    Resource ID for the verbal error description.

  • nHelpID
    A help context for your application's help (.HLP) file.

Remarks

The information provided to this function can be displayed by the driving application (Microsoft Visual Basic or another OLE automation client application).

Example

// Sort is method of automation class CStrArrayDoc 
long CStrArrayDoc::Sort(VARIANT* vArray)
{
   USES_CONVERSION;

   // Type check VARIANT parameter. It should contain a BSTR array 
   // passed by reference. The array must be passed by reference; it is 
   // an in-out-parameter. 

   // throwing COleDispatchException allows the EXCEPINFO structure of  
   // IDispatch::Invoke() to set 
   if (V_VT(vArray) != (VT_ARRAY | VT_BSTR))
      AfxThrowOleDispatchException(1001, 
         _T("Type Mismatch in Parameter. Pass a string array by reference"));

   // ... 
   // ... 

   return 0;
}

Requirements

Header: <afxdisp.h>

See Also

Reference

COleException Class

Concepts

MFC Macros and Globals