Tuesday, June 7, 2016

C: char* conversion to LPCWSTR

#include <string.h>
#include <strlib.h>

LPCWSTR c2ws(const char* s){
 int len;
 int slength = strlen(s)+1;
 len = MultiByteToWideChar(CP_ACP, 0, s, slength, 0, 0);
 wchar_t* buf = new wchar_t[len];
 MultiByteToWideChar(CP_ACP, 0, s, slength, buf, len);
 LPCWSTR r(buf);
 delete[] buf;
 return r;
}

No comments:

Post a Comment