I'm having a problem returning a native string in the correct character-set. I convert from a string to a wstring to an LPCWSTR to pass back to managed. For the string to wide-string, the s2ws method produces a very small string return because it seems to stop at my first would-be terminator (in managed), which is ';'. So, before you mention s2ws, I've alreday tried it to no avail.
String stuff:
char target[1024];
sprintf_s(target, 1024, "%s %s%s%s",
mac,
" (",
pWLanBssList->wlanBssEntries[t].dot11Ssid.ucSSID,
");");
std::string targetString = std::string(target);
targetWString.append(targetString.begin(), targetString.end());
Later string stuff:
std::wstring returnWString = L"";
returnWString.append(SomeMthod().c_str());
//wprintf_s(returnWString.c_str()); // Works - Data is in the string.
LPCWSTR returnLpcuwstr = returnWString.c_str();
return returnLpcuwstr;
How do I know it's a character set/encoding problem? Well, when the LPCWSTR is returned to managed and I use Marshal to Unicode string, I get a wall of null/empty characters. When I try it in ANSI, this is what I get (reduced in size/scale for readability):
ÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝ
The s2ws method is supposed to address the ANSI/UNICODE nightmare that is std::string->std::wstring but that makes the return far too short - far shorter than it should be - but doesn't address the actual charset problem.
Result (to ANSI, again - no reducing done on my part): ÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝÝ
When I check in native, wprintf_s shows me that the string is valid/good before the LPCWSTR conversion happens in the export method; so, I need to understand:
- Is there a way for me to tell what the byte size of the characters actually are? (I'm thinking that this is an 8byte versus 16byte scenario?)
- Since wprintf_s works on the wide string, I checked it against the LPCWSTR and it printed the same (expected) data; so, the issue doesn't appear to be in the .ctor() of the LPCWSTR. Yet, I want to double-check my maths: Am I LPCWSTR'ing correctly?
- Since everything in native is telling me that the string is good, how can I check it's character-set (in native)?
The return, itself, is about 8 lines of text, with a delimiter ';' used so that I can split the string in managed and do magic with it. The only issue is getting the string to render as a valid string in managed, with the correct characters in it.
I feel like, maybe, I'm missing something obvious here but I cannot figure out what it is and just need a fresh pair of eyes to tell me where and how I'm failing at life.