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

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -