471,328 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,328 software developers and data experts.

Managed String to char * conversion

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.
Jul 21 '05 #1
1 4949
Surely there is a simpler method than having to do the Marshal->Copy(...)
thing each time?


See

How To Convert from System::String* to Char* in Visual C++ .NET
http://support.microsoft.com/?kbid=311259

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Marcin Kalicinski | last post: by
10 posts views Thread by Bonj | last post: by
3 posts views Thread by richard.usenet | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.