com - How do you instantiate an IDispatchEx in C#? -


this first question! instantiate com object , cast idispatchex can enumerate members. here example:

     type _comtype = system.type.gettypefromprogid("scripting.filesystemobject");     var _comobject = (idispatchex)activator.createinstance(_comtype); 

my idispatchex identical 1 on website (not website), except getnextdispid , getmembername return int (which wish use hresult described on msdn).

the example above not work. there way instantiate com objects active scripting cast idispatchex interface?

thanks , help/suggestions!

this operation failed because queryinterface call on com component interface iid '{a6ef9860-c720-11d0-9337-00a0c90dcaa9}' failed due following error: no such interface supported (exception hresult: 0x80004002 (e_nointerface)).

the exception message clear bell, scripting.filesystemobject doesn't implement idispatchex interface. idispatch. works fine:

        type t = system.type.gettypefromprogid("scripting.filesystemobject");         var obj = activator.createinstance(t);         var iobj = (stdole.idispatch)obj; 

you're done, cannot force com coclass implement interface. not expect many com classes implement it, idispatchex pretty obscure. fits jscript mold.


Comments