Managed String to char * conversion

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