Passing a string br reference from c# to c++

  • Thread starter Thread starter Steven Blair
  • Start date Start date
S

Steven Blair

Hi,

I am having problem passing a string by reference to some C++ code.

Wondered if anyone could help me out.

C# code:

myFunc(str);

C++ code:

myFunc(String &str)
{
str.Copy("Test");
}

This doesnt work tho :(

Steven
www.stevenblair.com
 
Steven,

Is the String that you are using in C++ a managed String, or is it some
other string class? If it is a managed string, then you need to declare it
like this:

void myFunc(String **str)

This will allow you to pass the string by reference. Managed code
doesn't support the concept of passing a c-style reference, but rather, you
have to work with pointers.

If this is some other kind of string class, then you will have to change
the function definition so that it takes a character array or a managed
string.

Hope this helps.
 
Back
Top