title: LPWSTR to wstring c++
body: <p>I would like to read utf-8 test from a .dll string table.
  something like this</p>
  
  <pre><code>LPWSTR nnW;
  LoadStringW(hMod, id, nnW, MAX_PATH);
  </code></pre>
  
  <p>and after that I would like to convert the <code>LPWSTR nnW</code> to <code>std::wstring nnWstring</code>.
  I tried in this way:
     LPWSTR nnW;
  LoadStringW(hMod, id, nnW, MAX_PATH);</p>
  
  <pre><code>const int length = MultiByteToWideChar(CP_UTF8,
                                         0,   // no flags required
                                         (LPCSTR)nnW,
                                         -1,  // automatically determine length
                                         NULL,
                                         0);
  
  std::wstring nnWstring(length, L'\0');
  
  if (!MultiByteToWideChar(CP_UTF8,
                           0,
                           (LPCSTR)nnW,
                           -1,
                           &amp;nnWstring[0],
                           length))
  
  MessageBoxW(NULL, (LPCWSTR)nnWstring.c_str(),  L"wstring", MB_OK | MB_ICONERROR);
  </code></pre>
  
  <p>After that in the MessageBoxW only shows the first letter.</p>