DispInvoke Function
Automatically calls member functions on an interface, given the type information for the interface. You can describe an interface with type information and implement IDispatch::Invoke for the interface using this single call.
HRESULT DispInvoke( void FAR* _this, ITypeInfo FAR* ptinfo, DISPID dispidMember, unsigned short wFlags, DISPPARAMS FAR* pparams, VARIANT FAR* pvarResult, EXCEPINFO pexcepinfo, unsigned int FAR* puArgErr );
The return value obtained from the returned HRESULT is one of the following:
Return value | Meaning |
|---|---|
S_OK | Success. |
DISP_E_BADPARAMCOUNT | The number of elements provided in DISPPARAMS is different from the number of arguments accepted by the method or property. |
DISP_E_BADVARTYPE | One of the arguments in DISPPARAMS is not a valid variant type. |
DISP_E_EXCEPTION | The application needs to raise an exception. In this case, the structure passed in pexcepinfo should be filled in. |
DISP_E_MEMBERNOTFOUND | The requested member does not exist. |
DISP_E_NONAMEDARGS | This implementation of IDispatch does not support named arguments. |
DISP_E_OVERFLOW | One of the arguments in DISPPARAMS could not be coerced to the specified type. |
DISP_E_PARAMNOTFOUND | One of the parameter IDs does not correspond to a parameter on the method. In this case, puArgErr is set to the first argument that contains the error. |
DISP_E_PARAMNOTOPTIONAL | A required parameter was omitted. |
DISP_E_TYPEMISMATCH | One or more of the arguments could not be coerced. The index of the first parameter with the incorrect type within rgvarg is returned in puArgErr. |
E_INVALIDARG | One of the arguments is invalid. |
E_OUTOFMEMORY | Insufficient memory to complete the operation. |
Other return codes | Any of the ITypeInfo::Invoke errors can also be returned. |
The following code from the Lines sample file Lines.cpp implements IDispatch::Invoke using DispInvoke. This implementation relies on DispInvoke to validate input arguments. To help minimize security risks, include code that performs more robust validation of the input arguments.
STDMETHODIMP
CLines::Invoke(
DISPID dispidMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS FAR* pdispparams,
VARIANT FAR* pvarResult,
EXCEPINFO FAR* pexcepinfo,
UINT FAR* puArgErr)
{
return DispInvoke(
this, m_ptinfo,
dispidMember, wFlags, pdispparams,
pvarResult, pexcepinfo, puArgErr);
}