4

I am trying to construct a Platform::String from the results of a method that returns const char*

I simply cannot get this to work, and have been scratching my head for ages.

Im not a very experienced c++ developer, so the answer may be obvious, but I just cant seem to work it out.

Thanks for any help.

Dean Chalk
  • 19,361
  • 6
  • 58
  • 86

2 Answers2

4

You can use mbstowcs http://www.cplusplus.com/reference/cstdlib/mbstowcs/ to fill a wchar_t buffer then pass it to the Platform::String constructor to create an instance with the data you want.

static wchar_t buffer[ MAX_BUFFER ];
mbstowcs( buffer, source, MAX_BUFFER );
platformString = ref new Platform::String( buffer );
jheriko
  • 2,988
  • 1
  • 20
  • 28
3

Platform::String uses char16 internally, and takes a char16* in its constructor. You need to convert your char* text to char16* text using MultiByteToWideChar. This question talks about going from Platform::String to char*, and to go from char* to Platform::String the reverse path should be followed.

Community
  • 1
  • 1
Cornstalks
  • 35,769
  • 16
  • 74
  • 137