Managed String to char * conversion

G

Guest

I've been battling with this a little bit.
The Marshal class Copy method should do this. but......

I have the following (simple - not real code)

String * strString = DotNetMethodReturnValue(...);
char * pszString = new char[strString->Length + 1];

Now, using the marshal->copy method, I get various different errors
depending on how i try to convert it, but I can't seem to get my head around
the correct conversion.

Surely there is a simpler method than having to do the Marshal->Copy(...)
thing each time?

I have about a million lines of code which is partly in .net, and is slowly
being converted to full .net as time permits. Customer's don't like to wait
for 'conversions' so this is being done slowly.
Thus, I am in the position of having DotNet and Standard C++ mixed together
and conversions need to be done in places.

Thanks in advnace for the help.
 

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