Hi Will,
Thanks for the reply. The following line:
wchar_t __pin *p = PtrToStringChars(my_string);
now generates the error: "p is an undeclared indentifier (error C2065)". I
did include the 'vcclr.h' include. I've never used pinning before, though I
vaguely know what it's for (GC can move things around in memory, pin
prevents this, just not sure yet when this is necessary and when it isn't).
Also, I'm trying to get the result into a char[33] array, so is wchar_t*
compatible with this for direct copying?
Also, when you say 'copy them to target' (i.e., the char[33] variable) could
you give me an idea how to do this (e.g., use strcpy?). Thanks again!
[==Peteroid==]
PS - It's weird that String* my_string = "HELLO" ; works (i.e. direct
assignment from a char string to a String) but the reverse doesn't (probably
because char came before String* in C(++) laguage development). But it
really shouldn't be this complicated to get a char[] copied to a String
(IMHO), as the requirement for such a conversion to make old code using
char[] more easily modernizable (i.e., String should have come with a built
in conversion tool, which I thought was the purpose of ToCharArray() (which
seems to not do what it looks like it should be doing, as what it outputs
does not act like a char[])...
William DePalo said:
Peteroid said:
How the heck does one convert a String* to char[]? Specifically:
String* my_string = "HELLO" ;
char m_char_array[32+1] ;
...
First pin the sting object (prevent it from being moved by the GC), and
get a pointer to the first character of the string
#include <vcclr.h>
wchar_t __pin *p = PtrToStringChars(my_string);
then for as many characters as you have got, copy them to the target
Regards,
Will