Marshal C# String to ActiveX DLL

  • Thread starter Thread starter Binder
  • Start date Start date
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
 
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
 
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
 
Back
Top