Home   Index   About
Ultimate Pack


Custom Search
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.

  • t

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


Last news from Greatis Software

Nostalgia .Net     Nostalgia .Net     .Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes.  More »

Recommended software for developers

Ultimate Pack for Delphi and C++ Builder     Ultimate Pack     Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price.  More »

Form Designer .Net     Form Designer .Net     Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro!  More »

Print Suite .Net     Print Suite .Net     Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available  More »

Gradient Controls .Net     Gradient Controls .Net     Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available  More »

iGrid     Greatis iGrid     iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors.  More »


All the contacts and projects

Dmitry Vasiliev (just.dmitry)

Related Links

Software for Visual Studio .NET developers
Software for Delphi and C++ Builder developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET

More Online Helps

Win32 Programmer's Reference
Win32 Multimedia Programmer's Reference
OLE Programmer's Reference
Microsoft Windows Pen API Programmer's Reference
Microsoft Windows Sockets 2 Reference
Microsoft Windows Telephony API (TAPI) Programmer's Reference
Unix Manual Pages

Free Tech Secrets ;) Copyright © 2008-2012 Free Tech Secrets ;) greatis just4fun network just4fun