DispGetParam
dispparams, iPosition, vt, pvarResult, puArgErr)
DISPPARAMS FAR* dispparams
unsigned int iPosition
VARTYPE vt
VARIANT FAR* pvarResult
unsigned int FAR* puArgErr
Retrieves a parameter from the DISPPARAMS structure, checking both named
parameters and positional parameters, and coerces it to the specified type.
Parameters
dispparams
Pointer to the parameters passed to
IDispatch::Invoke.
iPosition
The position of the parameter in the parameter list.
DispGetParam starts at the end of the array, so if
iPosition is 0, the last parameter in the array is returned.
The type to which the argument should be coerced.
pvarResult
Pointer to the variant into which to pass the parameter.
puArgErr
On return, pointer to the index of the argument that caused a
DISP_E_TYPEMISMATCH error. This pointer should be returned to
Invoke to indicate the position of the argument in DISPPARAMS that caused the error.
Return Value
The SCODE obtained from the HRESULT is one of the following:
SCODE
| Meaning
|
S_OK
| Success.
|
DISP_E_BADVARTYPE
| The variant type vt is not supported.
|
DISP_E_OVERFLOW
| The retrieved parameter could not be
coerced to the specified type.
|
DISP_E_PARAMNOTFOUND
| The parameter indicated by iPosition
could not be found.
|
DISP_E_TYPEMISMATCH
| The argument could not be coerced to the specified type.
|
E_INVALIDARG
| One of the arguments was invalid.
|
E_OUTOFMEMORY
| Insufficient memory to complete operation.
|
Comments
The output parameter
pvarResult must be a valid VARIANT; any existing contents will be released in the
standard way. The contents of the VARIANT should be freed with
VariantFree.
If
DispGetParam is used to get the right side of a property put operation, the second
parameter should be DISPID_PROPERTYPUT. For example:
DispGetParam(&dispparams, DISPID_PROPERTYPUT, VT_BOOL, &varResult)
Note also that named parameters can't be accessed positionally, and vice versa.
Example
The following example uses
DispGetParam to set X and Y properties:
STDMETHODIMP
CPoint::Invoke(
DISPID dispidMember,
REFIID riid,
LCID lcid,
unsigned short wFlags,
DISPPARAMS FAR* pdispparams,
VARIANT FAR* pvarResult,
EXCEPINFO FAR* pexcepinfo,
unsigned int FAR* puArgErr)
{
unsigned int uArgErr;
HRESULT hresult;
VARIANTARG varg0;
VARIANT varResultDummy;
UNUSED(lcid);
UNUSED(pexcepinfo);
// Make sure the wFlags are legal
if(wFlags & ~(DISPATCH_METHOD | DISPATCH_PROPERTYGET |
DISPATCH_PROPERTYPUT | DISPATCH_PROPERTYPUTREF))
return ResultFromScode(E_INVALIDARG);
// This object only exposes a "default" interface.
if(!IsEqualIID(riid, IID_NULL))
return ResultFromScode(DISP_E_UNKNOWNINTERFACE);
// It simplifies the following code if the caller
// ignores the return value.
if(puArgErr == NULL)
puArgErr = &uArgErr;
if(pvarResult == NULL)
pvarResult = &varResultDummy;
VariantInit(&varg0);
// Assume the return type is void, unless we find otherwise.
VariantInit(pvarResult);
switch(dispidMember){
case IDMEMBER_CPOINT_GETX:
V_VT(pvarResult) = VT_I2;
V_I2(pvarResult) = GetX();
break;
case IDMEMBER_CPOINT_SETX:
hresult = DispGetParam(pdispparams, 0, VT_I2, &varg0, puArgErr);
if(hresult != NOERROR)
return hresult;
SetX(V_I2(&varg0));
break;
case IDMEMBER_CPOINT_GETY:
V_VT(pvarResult) = VT_I2;
V_I2(pvarResult) = GetY();
break;
case IDMEMBER_CPOINT_SETY:
hresult = DispGetParam(pdispparams, 0, VT_I2, &varg0, puArgErr);
if(hresult != NOERROR)
return hresult;
SetY(V_I2(&varg0));
break;
default:
return ResultFromScode(DISP_E_MEMBERNOTFOUND);
}
return NOERROR;
}
See Also
CreateStdDispatch,
IDispatch::Invoke
- Software for developers
-
Delphi Components
.Net Components
Software for Android Developers
- More information resources
-
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
- Databases for Amazon shops developers
-
Amazon Categories Database
Browse Nodes Database