Docsity

Microsoft COM Variant Data Type and Safe Array Structures - Prof. James Fawcett, Study notes of Engineering

Partial preview of the text

Download Microsoft COM Variant Data Type and Safe Array Structures - Prof. James Fawcett and more Study notes Engineering in PDF only on Docsity!

Variant - Discriminated Union

struct tagVARIANT { union { struct __tagVARIANT { VARTYPE vt; /* holds a VT_XXX tag / WORD wReserved1; WORD wReserved2; WORD wReserved3; union { LONG lVal; / VT_I4 / BYTE bVal; / VT_UI1 / SHORT iVal; / VT_I2 / FLOAT fltVal; / VT_R4 / DOUBLE dblVal; / VT_R8 / VARIANT_BOOL boolVal; / VT_BOOL / _VARIANT_BOOL bool; / (obsolete) / SCODE scode; / VT_ERROR / CY cyVal; / VT_CY / DATE date; / VT_DATE / BSTR bstrVal; / VT_BSTR / IUnknown * punkVal; / VT_UNKNOWN / IDispatch * pdispVal; / VT_DISPATCH / SAFEARRAY * parray; / VT_ARRAY / BYTE * pbVal; / VT_BYREF|VT_UI1 / SHORT * piVal; / VT_BYREF|VT_I2 / LONG * plVal; / VT_BYREF|VT_I4 / FLOAT * pfltVal; / VT_BYREF|VT_R4 / DOUBLE * pdblVal; / VT_BYREF|VT_R8 */ VARIANT_BOOL pboolVal; / VT_BYREF|VT_BOOL */ _VARIANT_BOOL pbool; / (obsolete) / SCODE * pscode; / VT_BYREF|VT_ERROR / CY * pcyVal; / VT_BYREF|VT_CY / DATE * pdate; / VT_BYREF|VT_DATE / BSTR * pbstrVal; / VT_BYREF|VT_BSTR / IUnknown ** ppunkVal; / VT_BYREF|VT_UNKNOWN / IDispatch ** ppdispVal; / VT_BYREF|VT_DISPATCH / SAFEARRAY ** pparray; / VT_BYREF|VT_ARRAY / VARIANT * pvarVal; / VT_BYREF|VT_VARIANT / PVOID byref; / Generic ByRef / CHAR cVal; / VT_I1 / USHORT uiVal; / VT_UI2 / ULONG ulVal; / VT_UI4 / INT intVal; / VT_INT / UINT uintVal; / VT_UINT / DECIMAL * pdecVal; / VT_BYREF|VT_DECIMAL / CHAR * pcVal; / VT_BYREF|VT_I1 / USHORT * puiVal; / VT_BYREF|VT_UI2 / ULONG * pulVal; / VT_BYREF|VT_UI4 / INT * pintVal; / VT_BYREF|VT_INT / UINT * puintVal; / VT_BYREF|VT_UINT / struct __tagBRECORD { / used for UDT’s in VB / PVOID pvRecord; IRecordInfo * pRecInfo; } __VARIANT_NAME_4; / VT_RECORD */ } __VARIANT_NAME_3; } __VARIANT_NAME_2; DECIMAL decVal; } __VARIANT_NAME_1; }; typedef VARIANT * LPVARIANT; typedef VARIANT VARIANTARG; typedef VARIANT * LPVARIANTARG;

Variant Access Functions

#define V_UNION(X, Y) ((X)->n1.n2.n3.Y)

#define V_VT(X) ((X)->n1.n2.vt)

#define V_RECORDINFO(X) ((X)->n1.n2.n3.brecVal.pRecInfo)

#define V_RECORD(X) ((X)->n1.n2.n3.brecVal.pvRecord)

/* Variant access macros */

#define V_ISBYREF(X) (V_VT(X)&VT_BYREF)

#define V_ISARRAY(X) (V_VT(X)&VT_ARRAY)

#define V_ISVECTOR(X) (V_VT(X)&VT_VECTOR)

#define V_NONE(X) V_I2(X)

#define V_UI1(X) V_UNION(X, bVal)

#define V_UI1REF(X) V_UNION(X, pbVal)

#define V_I2(X) V_UNION(X, iVal)

#define V_I2REF(X) V_UNION(X, piVal)

#define V_I4(X) V_UNION(X, lVal)

#define V_I4REF(X) V_UNION(X, plVal)

#define V_R4(X) V_UNION(X, fltVal)

#define V_R4REF(X) V_UNION(X, pfltVal)

#define V_R8(X) V_UNION(X, dblVal)

#define V_R8REF(X) V_UNION(X, pdblVal)

#define V_I1(X) V_UNION(X, cVal)

#define V_I1REF(X) V_UNION(X, pcVal)

#define V_UI2(X) V_UNION(X, uiVal)

#define V_UI2REF(X) V_UNION(X, puiVal)

#define V_UI4(X) V_UNION(X, ulVal)

#define V_UI4REF(X) V_UNION(X, pulVal)

#define V_INT(X) V_UNION(X, intVal)

#define V_INTREF(X) V_UNION(X, pintVal)

#define V_UINT(X) V_UNION(X, uintVal)

#define V_UINTREF(X) V_UNION(X, puintVal)

#define V_CY(X) V_UNION(X, cyVal)

#define V_CYREF(X) V_UNION(X, pcyVal)

#define V_DATE(X) V_UNION(X, date)

#define V_DATEREF(X) V_UNION(X, pdate)

#define V_BSTR(X) V_UNION(X, bstrVal)

#define V_BSTRREF(X) V_UNION(X, pbstrVal)

#define V_DISPATCH(X) V_UNION(X, pdispVal)

#define V_DISPATCHREF(X) V_UNION(X, ppdispVal)

#define V_ERROR(X) V_UNION(X, scode)

#define V_ERRORREF(X) V_UNION(X, pscode)

#define V_BOOL(X) V_UNION(X, boolVal)

#define V_BOOLREF(X) V_UNION(X, pboolVal)

#define V_UNKNOWN(X) V_UNION(X, punkVal)

#define V_UNKNOWNREF(X) V_UNION(X, ppunkVal)

#define V_VARIANTREF(X) V_UNION(X, pvarVal)

#define V_ARRAY(X) V_UNION(X, parray)

#define V_ARRAYREF(X) V_UNION(X, pparray)

#define V_BYREF(X) V_UNION(X, byref)

#define V_DECIMAL(X) V_UNION(X, decVal)

#define V_DECIMALREF(X) V_UNION(X, pdecVal)

Safe Array

typedef struct tagSAFEARRAY { USHORT cDims; /* number of array dimensions / USHORT fFeatures; / used by safe array API / ULONG cbElements; / size of each element / ULONG cLocks; / count of current locks / PVOID pvData; / pointer to data valid when cLocks > 0 / SAFEARRAYBOUND rgsabound[]; / bounds for each dimensions / } SAFEARRAY; typedef struct tagSAFEARRAYBOUND { ULONG cElements; / number of elements in dimension * / long LBound; / * dimensio lower bound, usually zero */ } SAFEARRAYBOUND

Array manipulation

SafeArrayAccessData Increments the lock count of an array and returns a pointer

to array data.

SafeArrayAllocData Allocates memory for a safe array based on a descriptor

created with SafeArrayAllocDescriptor.

SafeArrayAllocDescriptor Allocates memory for a safe array descriptor.

SafeArrayCopy Copies an existing array.

SafeArrayCopyData Copies a source array to a target array after releasing source

resources.

SafeArrayCreate Creates a new array descriptor.

SafeArrayCreateVector Creates a one-dimensional array whose lower bound is

always zero.

SafeArrayDestroy Destroys an array descriptor.

SafeArrayDestroyData Frees memory used by the data elements in a safe array.

SafeArrayDestroyDescriptor

Frees memory used by a safe array descriptor.

SafeArrayGetDim Returns the number of dimensions in an array.

SafeArrayGetElement Retrieves an element of an array.

SafeArrayGetElemsize Returns the size of an element.

SafeArrayGetLBound Retrieves the lower bound for a given dimension.

SafeArrayGetUBoundRetrieves the upper bound for a given dimension. SafeArrayLock

Increments the lock count of an array.

SafeArrayPtrOfIndex Returns a pointer to an array element.

SafeArrayPutElement Assigns an element into an array.

SafeArrayRedim Resizes a safe array.

SafeArrayUnaccessData Frees a pointer to array data and decrements the lock count

of the array.

SafeArrayUnlock Decrements the lock count of an array.

DISPPARAMS

typedef struct tagDISPPARAMS { [size_is(cArgs)] VARIANTARG * rgvarg; [size_is(cNamedArgs)] DISPID * rgdispidNamedArgs; UINT cArgs; UINT cNamedArgs; } DISPPARAMS;

EXCEPINFO

typedef struct tagEXCEPINFO { WORD wCode; /* An error code describing the error. / WORD wReserved; BSTR bstrSource; / A source of the exception / BSTR bstrDescription; / A description of the error / BSTR bstrHelpFile; / Fully qualified drive, path, and file name / DWORD dwHelpContext; / help context of topic within the help file */ ULONG pvReserved; ULONG pfnDeferredFillIn; SCODE scode; } EXCEPINFO;

ITypeInfo

[

object, uuid(00020401-0000-0000-C000-000000000046), pointer_default(unique) ] interface ITypeInfo : IUnknown { typedef [unique] ITypeInfo * LPTYPEINFO; [local] HRESULT GetTypeAttr( [out] TYPEATTR ** ppTypeAttr ); [call_as(GetTypeAttr)] HRESULT RemoteGetTypeAttr( [out] LPTYPEATTR * ppTypeAttr, [out] CLEANLOCALSTORAGE * pDummy ); HRESULT GetTypeComp( [out] ITypeComp ** ppTComp ); [local] HRESULT GetFuncDesc( [in] UINT index, [out] FUNCDESC ** ppFuncDesc ); [call_as(GetFuncDesc)] HRESULT RemoteGetFuncDesc( [in] UINT index, [out] LPFUNCDESC * ppFuncDesc, [out] CLEANLOCALSTORAGE * pDummy ); [local] HRESULT GetVarDesc( [in] UINT index, [out] VARDESC ** ppVarDesc ); [call_as(GetVarDesc)] HRESULT RemoteGetVarDesc( [in] UINT index, [out] LPVARDESC * ppVarDesc, [out] CLEANLOCALSTORAGE * pDummy ); [local] HRESULT GetNames( [in] MEMBERID memid, [out,size_is(cMaxNames),length_is(pcNames)] BSTR * rgBstrNames, [in] UINT cMaxNames, [out] UINT * pcNames ); [call_as(GetNames)] HRESULT RemoteGetNames( [in] MEMBERID memid, [out,size_is(cMaxNames),length_is(pcNames)] BSTR * rgBstrNames, [in] UINT cMaxNames, [out] UINT * pcNames ); HRESULT GetRefTypeOfImplType( [in] UINT index, [out] HREFTYPE * pRefType ); HRESULT GetImplTypeFlags( [in] UINT index, [out] INT * pImplTypeFlags );

ITypeInfo (continued)

[local] HRESULT AddressOfMember( [in] MEMBERID memid, [in] INVOKEKIND invKind, [out] PVOID * ppv ); [call_as(AddressOfMember)] HRESULT LocalAddressOfMember( void ); [local] HRESULT CreateInstance( [in] IUnknown * pUnkOuter, [in] REFIID riid, [out, iid_is(riid)] PVOID * ppvObj ); [call_as(CreateInstance)] HRESULT RemoteCreateInstance( [in] REFIID riid, [out, iid_is(riid)] IUnknown ** ppvObj ); HRESULT GetMops( [in] MEMBERID memid, [out] BSTR * pBstrMops ); [local] HRESULT GetContainingTypeLib( [out] ITypeLib ** ppTLib, [out] UINT * pIndex ); [call_as(GetContainingTypeLib)] HRESULT RemoteGetContainingTypeLib( [out] ITypeLib ** ppTLib, [out] UINT * pIndex ); [local] void ReleaseTypeAttr( [in] TYPEATTR * pTypeAttr ); [call_as(ReleaseTypeAttr)] HRESULT LocalReleaseTypeAttr( void ); [local] void ReleaseFuncDesc( [in] FUNCDESC * pFuncDesc ); [call_as(ReleaseFuncDesc)] HRESULT LocalReleaseFuncDesc( void ); [local] void ReleaseVarDesc( [in] VARDESC * pVarDesc ); [call_as(ReleaseVarDesc)] HRESULT LocalReleaseVarDesc( void ); }

IErrorInfo Interface

[

object, uuid(1CF2B120-547D-101B-8E65-08002B2BD119), pointer_default(unique) ] interface IErrorInfo: IUnknown { typedef [unique] IErrorInfo * LPERRORINFO; HRESULT GetGUID( [out] GUID * pGUID ); HRESULT GetSource( [out] BSTR * pBstrSource ); HRESULT GetDescription( [out] BSTR * pBstrDescription ); HRESULT GetHelpFile( [out] BSTR * pBstrHelpFile ); HRESULT GetHelpContext( [out] DWORD * pdwHelpContext ); }

ICreateErrorInfo Interface

[

object, uuid(22F03340-547D-101B-8E65-08002B2BD119), pointer_default(unique) ] interface ICreateErrorInfo: IUnknown { typedef [unique] ICreateErrorInfo * LPCREATEERRORINFO; HRESULT SetGUID( [in] REFGUID rguid ); HRESULT SetSource( [in] LPOLESTR szSource ); HRESULT SetDescription( [in] LPOLESTR szDescription ); HRESULT SetHelpFile( [in] LPOLESTR szHelpFile ); HRESULT SetHelpContext( [in] DWORD dwHelpContext ); }