Use a BSTR as string in C# COM method -
my project control device software working on. doing vendor provides com library. have problem calling 1 method library:
in (unfortunately shortly written) documentation of com library method have call defined this:
xclass *getdeviceinterface(bstr p_serialnumber)
but: visual studio tells me have put string method:
public virtual xclass getdeviceinterface(string p_serialnumber)
so able compile program if plug in device's serial number string , not bstr. test purposes calling method in if case (i check if returned).
intptr serialbstr = marshal.stringtobstr(serialno); if (obj1.getdeviceinterface(marshal.ptrtostringbstr(serialbstr)) != null) { messagebox.show("fine"); }
but if invalidcastexception:
system.invalidcastexception: return argument has invalid type. @ system.runtime.remoting.proxies.realproxy.validatereturnarg(object arg, type paramtype) @ system.runtime.remoting.proxies.realproxy.propagateoutparameters(imessage msg, object[] outargs, object returnvalue) @ system.runtimetype.forwardcalltoinvokemember(string membername, bindingflags flags, object target, int32[] awrappertypes, messagedata& msgdata) @ theusedcomlib.class1.getinterface(string serialno) @ myproject.form1.initialize() in path/to/my/file.cs:line 00
i think work fine, if able compile bstr argument. can somehow trick compiling process? or ignore information (that says need string method) visual studio reads library?
thank help!
Comments
Post a Comment