Meysam
0
Q:

c++ convert const char* to LPCWSTR

  const char *p = "D:\\";
  const WCHAR *pwcsName; //LPCWSTR
  
  // required size
  int size = MultiByteToWideChar(CP_ACP, 0, p, -1, NULL, 0);
  // allocate it
  pwcsName = new WCHAR[nChars];
  MultiByteToWideChar(CP_ACP, 0, p, -1, (LPWSTR)pwcsName, size);
  // use it....
    
  // delete it
  delete [] pwcsName;
}
1
String^ test = L"I am a .Net string of type System::String";
IntPtr ptrToNativeString = Marshal::StringToHGlobalAnsi(test);
char* nativeString = static_cast<char*>(ptrToNativeString.ToPointer());
-1

New to Communities?

Join the community