Convert BSTR(OLECHAR*) to LPWSTR (WCHAR)???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nabil035
    New Member
    • Mar 2008
    • 34

    Convert BSTR(OLECHAR*) to LPWSTR (WCHAR)???

    I want to convert in my COM server a BSTR var into LPWSTR

    please help!!!
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Have you tried WideCharToMulti Byte() ?

    Comment

    • nabil035
      New Member
      • Mar 2008
      • 34

      #3
      well sorry it's so simple to convert it

      just I used this code

      USES_CONVERSION ;

      lpwstr wchar = T2W(bstrvar);

      ;)

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Originally posted by nabil035
        lpwstr wchar = T2W(bstrvar);
        That's an ATL macro.

        Here's a quote from Microsoft:
        Originally posted by MSDN
        Note The recommended way of converting to and from BSTR strings is to use the CComBSTR class. To convert to a BSTR, pass the existing string to the constructor of CComBSTR. To convert from a BSTR, use COLE2[C]DestinationType[EX], such as COLE2T.
        That is, do not use the macros.

        More here: http://msdn2.microsoft.com/en-us/lib...a3(VS.71).aspx.

        Comment

        Working...