title: Converting contents of a byte array to wchar_t*
body: <p>I seem to be having an issue converting a byte array (containing the text from a word document) to a LPTSTR (wchar_t *) object. Every time the code executes, I am getting a bunch of unwanted Unicode characters returned.</p>
  
  <p>I figure it is because I am not making the proper calls somewhere, or not using the variables properly, but not quite sure how to approach this. Hopefully someone here can guide me in the right direction.</p>
  
  <p>The first thing that happens in we call into C# code to open up Microsoft Word and convert the text in the document into a byte array. </p>
  
  <pre><code>byte document __gc[];
  document = word-&gt;ConvertToArray(filename);
  </code></pre>
  
  <p>The contents of document are as follows:</p>
  
  <pre><code>{84, 101, 115, 116, 32, 68, 111, 99, 117, 109, 101, 110, 116, 13, 10}
  </code></pre>
  
  <p>Which ends up being the following string: "Test Document".</p>
  
  <p>Our next step is to allocate the memory to store the byte array into a LPTSTR variable,</p>
  
  <pre><code>byte __pin * value;
  
  value = &amp;document[0];
  
  LPTSTR image;
  image = (LPTSTR)malloc( document-&gt;Length + 1 );
  </code></pre>
  
  <p>Once we execute the line where we start allocating the memory, our image variable gets filled with a bunch of unwanted Unicode characters:</p>
  
  <pre><code>췍췍췍췍췍췍췍췍﷽﷽����˿於潁
  </code></pre>
  
  <p>And then we do a memcpy to transfer over all of the data</p>
  
  <pre><code>memcpy(image,value,document-&gt;Length);
  </code></pre>
  
  <p>Which just causes more unwanted Unicode characters to appear:</p>
  
  <pre><code>敔瑳䐠捯浵湥൴촊﷽﷽����˿於潁
  </code></pre>
  
  <p>I figure the issue that we are having is either related to how we are storing the values in the byte array, or possibly when we are copying the data from the byte array to the LPTSTR variable. Any help with explaining what I'm doing wrong, or anything to point me in the right direction will be greatly appreciated.</p>