dumb question about String

  • Thread starter Thread starter TGF
  • Start date Start date
T

TGF

How do you copy a String type into a native char buffer[256]? Dumb
question, but not sure how to do it :(

TGF
 
TGF,
How do you copy a String type into a native char buffer[256]? Dumb
question, but not sure how to do it :(

If you don't mind an extra buffer copy, you can use the Marshal class in the
System::Runtime::InteropServices namespace, with the StringToAnsiHGlobal(),
then just use strncpy or another like method.

Otherwise, another option would be to use PtrToStringChars() in vcclr.h, pin
the returned pointer, and then use a Unicode-to-ansi conversion function
(such as WideCharToMultiByte) directly unto your array.
 

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

Back
Top