다음을 통해 공유


DispGetParam (Windows Embedded CE 6.0)

1/6/2010

This function does the following:

  • Retrieves a parameter from the DISPPARAMS structure.
  • Checks named parameters and positional parameters.
  • Coerces the parameter to the specified type.

Syntax

HRESULT DispGetParam(
  DISPPARAMS FAR* pdispparams, 
  unsigned int position, 
  VARTYPE vtTarg, 
  VARIANT FAR* pvarResult, 
  unsigned int FAR* puArgErr 
);

Parameters

  • position
    [in] Position of the parameter in the parameter list.

    DispGetParam starts at the end of the array, so if the position is 0, the last parameter in the array is returned.

  • vtTarg
    [in] Type the argument should be coerced to.
  • pvarResult
    [out] Pointer to the variant to pass the parameter into.
  • puArgErr
    [out] On return, pointer to the index of the argument that caused a DISP_E_TYPEMISMATCH error. This pointer is returned to Invoke to indicate the position of the argument in DISPPARAMS that caused the error.

Return Value

Returns the HRESULT values shown in the following table.

Value Description

S_OK

Success.

DISP_E_BADVARTYPE

The variant type vtTarg is not supported.

DISP_E_OVERFLOW

The retrieved parameter could not be coerced to the specified type.

DISP_E_PARAMNOTFOUND

The parameter indicated by position could not be found.

DISP_E_TYPEMISMATCH

The argument could not be coerced to the specified type.

E_INVALIDARG

An argument is invalid.

E_OUTOFMEMORY

Insufficient memory to complete operation.

Remarks

The output parameter pvarResult must be a valid variant. Existing contents are released in the standard way. The contents of the variant are freed with VariantFree.

Passing invalid (and under some circumstances NULL) pointers to this function causes an unexpected termination of the application.

If you use DispGetParam 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)

Named parameters cannot be accessed positionally, and vice versa.

Example

The following code 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 valid.
  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 otherwise is found.
  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;
}

Requirements

Header oleauto.h
Library oleaut32.lib
Windows Embedded CE Windows CE 2.0 and later

See Also

Reference

Automation Functions