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

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

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