title: How to set a LPWSTR pointer which has been provided by reference to a function?
body: <p>I am replacing an old DLL which has a function, passing an LPWSTR by reference. 
  The functions should create a new wchar buffer and return the newly created LPWSTR pointer. I found a solution, but I think it could be solved better!?</p>
  
  <p>By the main proramm the DLL function is called like this:</p>
  
  <pre><code>LPWSTR data = null;
  funcA(&amp;data);
  </code></pre>
  
  <p>The function shoud creat a new wchar buffer and return the address.</p>
  
  <p>So here is what I do (it works):</p>
  
  <pre><code>void funcA(LPWSTR szData)
  {
    LPWSTR newData = L"DEMODATA";
    LPWSTR newBuffer = new TCHAR[9];
    wmemcpy(newBuffer, newData, 9);
  
    memcpy(szData, (LPWSTR)&amp;newBuffer , sizeof(LPWSTR));  
  }
  </code></pre>
  
  <p>Is it possibe to write the last line better readable?
  I tried to assign the new pointer but this does not work:</p>
  
  <pre><code>szData = (LPWSTR)&amp;newBuffer; // not working!
  </code></pre>