Marshal C# String to ActiveX DLL

B

Binder

I have an VB ActiveX DLL with a function the receives a string parameter.
I want to call this function from C#.
I made a reference to the DLL in my VS 2003 project.

DLL Function
--------------
public function ShowMsg (strIn as String)
msgbox strIn
end function


C# Function Call
------------------

string str1 = "ABCD";

Class7 s = new Class7Class();

s.ShowMsg(str1);


When I call the function from C#, I get an error:

Argument '1': cannot convert from 'byte[]' to 'ref string'

How do I marshal a C# string to an ActiveX DLL string?

Thanks,

Rg
 
G

Guest

try this mate:


DLL Function
--------------
public function ShowMsg (BYVAL strIn as String)
msgbox strIn
end function


C# Function Call
------------------

string str1 = "ABCD";

Class7 s = new Class7Class();

s.ShowMsg(str1);



You will find that declaring the DLL variable by value will solve this
problem since you are not modifying the variable.

Shane
 
A

Ankur

Adding a ref before str1 should solve your problem but I've doubts about the
code you have posted here because the error msg you have posted here shows
that you are trying to pass a byte[].

Ankur
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top