Smart Device Functions:
Changes an oleautomation variant (.NET an object) to a specific oleautomation compliant type, e.g. VT_BSTR (vbString) .
Very handy to convert a reference to a Dispatch interface to a string (which is in fact the result of recursive Invoke(s) to the DISPID(0).
private extern static int VariantChangeTypeEx([MarshalAs(UnmanagedType.Struct)]out object pvargDest,
Declare Function VariantChangeTypeEx Lib "oleaut32.dll" (TODO) As TODO
Alternative Managed API:
The alternative would be lots of invokes on an imported IDispatch interface if the source type is an object (Dispatch) and lots of conversion checks. Some of them could be converted using Convert.ToString(), however Convert.ToString() would not deal with Dispatch types.
See also VarBstrFromDisp
Tips & Tricks:
There is a lot to write about automation variables. E.g. a parameter can be optional and thus, have a default value which is in the TYpeLib. Or VT_ERROR | DISP_E_PARAMNOTFOUND (which is equivalent to VarType() = vbMissing). This is passed to .NET as Type.Missing. See sample code.
The SetLastError API
6/17/2013 1:06:05 PM - -18.104.22.168
Handy function Invoke the default value(s) on a ComObject reference within C#/VB.NET. The full code to retrieve DispId(0) (Default Value) from a Dispatch interface is ugly. This pinvoke is elegant and quick. Also supported on 64 bit of course.
3/17/2012 10:29:13 AM - -22.214.171.124
Please edit this page!
Do you have...