title: converting void* pointing to char* to a std::string in c++
body: <p>From the wincrypt api I am receiving a void* pointing to a char*.
  This char* is pointing to the start of a char[]. I am also receiving a <code>void*</code> pointing to a int with the size of the <code>char*</code>.</p>
  
  <p>Regarding pvData and cbData I have the following documentation from Microsoft.</p>
  
  <blockquote>
    <p>Data type of pvData: A pointer to an array of BYTE values. The size of this array is specified in the cbData parameter. Returns a null-terminated Unicode character string that contains the display name for the certificate.</p>
  </blockquote>
  
  <p>I want to convert this <code>void*</code> to a <code>std::string</code> but so far all I am getting when outputting my <code>std::string</code> is the first character.</p>
  
  <p>I have read: <a href="https://stackoverflow.com/questions/3076968/converting-a-void-to-a-stdstring">Converting a void* to a std::string</a> but since my <code>void*</code> is pointing to a <code>char*</code> instead of <code>std::string</code> the <code>static_cast</code> in the accepted answer fails and the returned <code>std::string*</code> triggers a null pointer exception.</p>
  
  <p>So far I have the following:</p>
  
  <pre><code>// pvData = void* pointing to char*
  // cbData = void* pointing to int*
  std::string tempName;
  tempName.assign(static_cast&lt;char*&gt;(pvData), static_cast&lt;int*&gt;(cbData));
  printf("%S \n", pvData); // entire string is shown
  printf("%s \n", tempName.c_str()); // only first character is shown
  </code></pre>
  
  <p>I have also tried</p>
  
  <pre><code>tempName = static_cast&lt;char*&gt;(pvData); // only single character returned
  
  tempName.assign(static_cast&lt;char*&gt;(pvData)); // only single character returned
  
  char* arr = static_cast&lt;char*&gt;(pvData);
  std::string tempName(arr); // only single character returned empty with printf must 
  // use std::cout
  </code></pre>