Compartir a través de


Returning Errors

Invoke returns DISP_E_MEMBERNOTFOUND if one of the following conditions occurs:

  • A member or parameter with the specified DISPID and matching cArgs cannot be found, and the parameter is not optional.

  • The member is a void function, and the caller did not set pVarResult to Null.

  • The member is a read-only property, and the caller set wFlags to DISPATCH_PROPERTYPUT or DISPATCH_PROPERTYPUTREF.

If Invoke finds the member, but uncovers errors in the argument list, it returns one of several other errors. DISP_E_BAD_PARAMCOUNT means that the DISPPARAMS structure contains an incorrect number of parameters for the property or method. DISP_E_NONAMEDARGS means that Invoke received named arguments, but they are not supported by the member.

DISP_E_PARAMNOTFOUND means that the correct number of parameters was passed, but the DISPID for one or more parameters was incorrect. If Invoke cannot convert one of the arguments to the desired type, it returns DISP_E_TYPEMISMATCH. In these two cases, if it can identify which argument is incorrect, Invoke sets *puArgErr to the index within rgvarg of the argument with the error. For example, if an Automation method expects a reference to a double-precision number as an argument, but receives a reference to an integer, the argument is coerced. However, if the method receives a date, Invoke returns DISP_E_TYPEMISMATCH and sets *puArgErr to the index of the integer in the argument array.

Automation provides functions to perform standard conversions of VARIANT, and these functions should be used for consistent operation. DISP_E_TYPEMISMATCH is returned only when these functions fail. For more information about converting arguments, see Conversion and Manipulation Functions.

Example

This code from the Lines sample file Lines.cpp implements the Invoke member function for the CLines class.

STDMETHODIMP
CLines::Invoke(
 DISPID dispidMember,
 REFIID riid,
 LCID lcid,
 WORD wFlags,
 DISPPARAMS * pDispParams,
 VARIANT * pVarResult,
 EXCEPINFO * pExcepInfo,
 UINT * puArgErr)
{ 
  return DispInvoke(
   this, m_ptinfo,
   dispidMember, wFlags, pDispParams,
   pVarResult, pExcepInfo, puArgErr
  ); 
}

The next code example calls the CLines::Invoke member function to get the value of the Color property:

HRESULT hr;
EXCEPINFO excepinfo;
UINT nArgErr;
VARIANT vRet;
DISPPARAMS * pdisp;
OLECHAR * szMember;
DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};

// Initialization code omitted for brevity.
szMember = "Color";
hr = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1, LOCALE_USER_DEFAULT, &dispid);

// Get Color property.
hr = pdisp->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_PROPERTYGET, &dispparams, &vRet, &excepinfo, &nArgErr);

CreateStdDispatch

DispInvoke

DispGetParam

ITypeInfo::Invoke

IDispatch