HighTechTalks DotNet Forums  

InvokeMember passing null for IDispatch* param fails, Type Mismatc

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss InvokeMember passing null for IDispatch* param fails, Type Mismatc in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
TomCat
 
Posts: n/a

Default InvokeMember passing null for IDispatch* param fails, Type Mismatc - 05-01-2007 , 08:20 PM






Seems like there is no way to enable this using .NET interop

COM method signature:
HRESULT CSomething:ut_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

Reply With Quote
  #2  
Old   
TomCat
 
Posts: n/a

Default Re: InvokeMember passing null for IDispatch* param fails, Type Mis - 05-03-2007 , 01:44 AM






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

"Mattias Sjögren" wrote:

Quote:
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.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.