visual c++ - C# program calls vc++ function which has BSTR as input parameter -
from c# program, calling vc++ function has bstr input parameter. not getting return value. c# application crashes.
c# : samplecs,
var value = object.getvalue(10, "test");
vc++ : samplecpp,
getvalue(long index, bstr key, double * value) { cstring str = key; .. .. }
any idea if missing or doing wrong?
note : if call getvalue function of vc++ vb6 works properly.
the marshal
class has methods working bstr
s managed code. try this:
// note bstr parameter in c++ becomes // intptr in pinvoke declaration. [dllimport("your.dll")] private void getvalue(long index, intptr key, ref double value);
to use method:
double result = 0; var stringvalue = "foo"; var bstrvalue = marshal.stringtobstr(stringvalue); try { getvalue(0, bstrvalue, ref result); } { marshal.freebstr(bstrvalue); }
Comments
Post a Comment