title: Which is better code for converting BSTR parameters to ANSI in C/C++?
body: <p>So far I've discovered I can convert incoming BSTRs to ANSI in two (of many?) ways, and I'm curious to know whether one is "better" than the other with respect to speed / efficiency etc.</p>
  
  <p>The way I've been using for a while is use the <code>USES_CONVERSION</code> and <code>W2A</code> macros, e.g.</p>
  
  <pre><code>BSTR __stdcall F(BSTR p1, BSTR p2 ) {
      USES_CONVERSION;
  
      LPSTR sNum1 = W2A( p1 );
      LPSTR sNum2 = W2A( p2 );
  </code></pre>
  
  <p>Recently, however, I came across another technique:</p>
  
  <pre><code>BSTR __stdcall F(BSTR p1, BSTR p2 ) {
      long amt = wcstombs( NULL, p1, 1 );
      sNum1 = (char *) malloc( amt ); 
      wcstombs( sNum1, p1, amt );
      *(sNum1 + amt) = '\0';
  
      amt = wcstombs( NULL, p2, 1 );
      sNum2 = (char *) malloc( amt ); 
      wcstombs( sNum2, p2, amt );
      *(sNum2 + amt) = '\0';
  </code></pre>
  
  <p>Now I grant you, it's wordier, and has two calls to <code>wcstombs</code> but for all I know the <code>USES_CONVERSION</code> and <code>W2A</code> macros may be hiding all sorts of fun and games.</p>
  
  <p>Which is the more efficient / faster code? Or, is there another technique I could use that would do the job better?</p>