TomCat
5/2/2007 12:20:00 AM
Seems like there is no way to enable this using .NET interop
COM method signature:
HRESULT CSomething::put_IDispProp (IDispatch* obj)
..NET InvokeMember call:
object[] args = new object[] { null }; // <-- passing null IDispatch*
comObject.GetType().InvokeMember("IDispProp", flags, null, comObject,
args,
Thread.CurrentThread.CurrentCulture);
Issue:
the invoke causes a DISP_E_TYPEMISMATCH error in oleaut IDispatch
implementation in my COM object
This issue is not restricted to IDispatch*. If you make LATE BOUND call on
any COM method with a pointer parameter AND pass null for that parameter, you
will run into it.
Why?
For the null parameter, interop is passing a VT = 0 (VT_EMPTY) parameter to
IDispatch implementation. The oleaut IDispatch implementation seems to be
written to return failure during invoke if the parameter's VT type (in this
case VT_EMPTY) does not match expected VT type (VT_DISPATCH in this case)
Question:
How can I make late bound call from .NET on a COM interface and control the
VT type of VARIANT that is passed to the COM invoke?
E.g. I want to tell InvokeMember that although the argument is NULL, the
Variant passed to COM should have vt = VT_DISPATCH.
ParameterModifier is of no help here.
Thanks in advance for your help