Error while compiling C2664

Hi,

I have this piece of code which I am trying to compile in VS 2005.

/////////////////////////////////////////////////////////

CComBSTR combstrEventGroup = bstrEventGroup;

hResult = ::UuidFromString(combstrEventGroup, &uuidEventGroupNr );

//////////////////////////////////////////////////////////////

Error:

error C2664: 'UuidFromStringW' : cannot convert parameter 1 from 'ATL::CComBSTR' to 'unsigned short *'

This compiles OK in VS 6.00 but it gives an error in VS 2005 (The project setiings has _UNICODE & UNICODE defined).

I am using VS2005 Version 8.0.50727.42.



Answer this question

Error while compiling C2664

  • .seb

    There was a recent thread on this topic.  There's a bug in the SDK headers where RPC_WSTR was defined as unsigned short* rather than wchar_t*. 

    CComBSTR has a conversion operator to wchar_t* which would have been implicitly used if RPC_WSTR were defined correctly.  In my workaround, I manually invoke that conversion operator, and then do the cast to RPC_WSTR.  This workaround assumes that _UNICODE is defined.  If it isn't, or you want portability, you'll need to provide an alternative version that converts wchar_t* to char* using the W2A conversion macro.

    ::UuidFromString( (RPC_WSTR)(TCHAR*)combstrEventGroup, &uuidEventGroupNr );

    The reason your code worked under VC6 was because wchar_t was typedefed to unsigned short.  Under VC8, wchar_t is its own native type. (This behavior is controlled by the compliler flag /Zc:wchar_t).

    Brian

     


  • zuchbinder

    I filed a bug on this issue. It was reported to have been fixed post-Beta 2, but that's not the case.


  • jbrunken

    i am sorry for wrong error description:

    Error:

    error C2664: 'UuidFromStringW' : cannot convert parameter 1 from 'ATL::CComBSTR' to 'RPC_WSTR'


  • Error while compiling C2664