C ++ / CX - I need to instantiate Platform :: String from const char *

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

I just can't get it to work, and with whole tables I'm scratching my head.

I'm not a very experienced C ++ developer, so the answer may be obvious, but I just can't handle it.

Thanks for any help.

+4
source share
2 answers

You can use mbstowcs http://www.cplusplus.com/reference/cstdlib/mbstowcs/ to populate the wchar_t buffer and 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 ); 
+4
source

Platform::String uses char16 internally and accepts char16* in its constructor. You need to convert char* text to char16* text using MultiByteToWideChar . This question speaks of the transition from Platform::String to char* , and to switch from char* to Platform::String should follow the reverse path.

+3
source

Source: https://habr.com/ru/post/1448120/


All Articles