[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

InvokeMember passing null for IDispatch* param fails, Type Mismatc

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
2 Answers

(Mattias Sjögren)

5/2/2007 5:20:00 AM

0

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

Check out the DispatchWrapper class.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.n... | http://www.dotneti...
Please reply only to the newsgroup.

TomCat

5/3/2007 5:45:00 AM

0

Thank you. That works. Also tried BstrWrapper and CurrencyWrapper. They do
exactly what I needed.

"Mattias Sjögren" wrote:

> >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.
>
> Check out the DispatchWrapper class.
>
>
> Mattias
>
> --
> Mattias Sjögren [C# MVP] mattias @ mvps.org
> http://www.msjogren.n... | http://www.dotneti...
> Please reply only to the newsgroup.
>