title: Converting std::string to a const WCHAR *string required by a GDI+ parameter
body: <p><strong>Short version</strong> I am using unicode. I am attempting to use a std::string, to a function that requires a const WCHAR <em>string; DrawString(const WCHAR</em>, ...</p>
  
  <p>I compile with GCC. Everything is unicode, I have specified.</p>
  
  <p>I have been trying to convert a string, into a wchar_t*. The purpose is so that I can output using a GDI+ function, its parameters require it so.</p>
  
  <p>Here is how I have outputted string literals, no problems, debugs fine, works fine.
  <a href="http://msdn.microsoft.com/en-us/library/ms535991%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms535991%28v=vs.85%29.aspx</a> for reference why:</p>
  
  <pre><code>// works fine
  wchar_t* wcBuff;
  wcBuff = (wchar_t*)L"Some text here.\0"; 
  AddString(wcBuff, wcslen(wcBuff), &amp;gFontFamilyInfo, FontStyleBold, 20, ptOrg_Controls, &amp;strFormat_Info);
  </code></pre>
  
  <p>Now this is what I have been trying, all day, and a side note: my conversion function works fine, it is not an issue, nor creating one.</p>
  
  <pre><code>// problems
  string s = "Level " + convert::intToString(6) + "\0"; 
  
  // try 1 - Segfault
  wchar_t* wcBuff = new wchar_t[s.length() + 1]; 
  copy(s.begin(), s.end(), wcBuff);
  
  // random tries, compiles, but access violations (my conversion function here has worked other places, do not know for sure here.
  wchar_t* wcBuff;
  wstring wstr = convert::stringToWideChar(s);
  wstring strvalue = convert::stringToWideChar(s);           
  wcBuff = (wchar_t*)strvalue.c_str(); 
  wcBuff = (wchar_t*)wstr.c_str();
  
  wstring foo;
  foo.assign(s.begin(), s.end());
  wcBuff = (wchar_t*)foo.c_str();
  </code></pre>
  
  <p>Everything compiles, but then presents problems. Some runtime errors as soon as it reaches that point. Others access violations and segfaults. Some compiles and debugs no problem, but the strings output constantly changes with random characters.</p>
  
  <p>Any ideas?</p>