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.
 
Back
Top