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.
The way I've been using for a while is use the USES_CONVERSION
and W2A
macros, e.g.
BSTR __stdcall F(BSTR p1, BSTR p2 ) {
USES_CONVERSION;
LPSTR sNum1 = W2A( p1 );
LPSTR sNum2 = W2A( p2 );
Recently, however, I came across another technique:
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';
Now I grant you, it's wordier, and has two calls to wcstombs
but for all I know the USES_CONVERSION
and W2A
macros may be hiding all sorts of fun and games.
Which is the more efficient / faster code? Or, is there another technique I could use that would do the job better?