locked
ASCII string to UNICODE string RRS feed

  • Question

  • Hi,
    I need to convert a simple word from ASCII to UNICODE.
    I am using VC++ 6.0 and was wondering if i can make it so that when I type "hello" the compiler will automatically change it into UNICODE, instead of having to use the MultibyteToWideChar() function.
    Also i am unsure how to use this function(how should i declare the buffer the converted string is stored in) Could someone please show me an example.
    Thanks
    Friday, September 22, 2006 6:57 AM

Answers

  •  daniboy120 wrote:
    Hi,
    [...] if i can make it so that when I type "hello" the compiler will automatically change it into UNICODE, instead of having to use the MultibyteToWideChar() function. [...]

    If you want to type "hello" into your program and ask the compiler to represent it in Unicode, then use the "L" suffix. For example:

     

    wchar_t unicodeString[] = L"hello";

     

    I hope this helps.

    Friday, September 22, 2006 7:26 AM

All replies


  • u can build the app in unicode and accept the input in a CString (in unicode the CString::m_pchData will be of type WCHAR*)

    u can use  the function as...

    MultiByteToWideChar(CP_ACP, 0, GetName() /*returns CString object*/, 
           GetName().GetLength() + 1,
           m_wzCharFile /* WCHAR* datatype */, MAX_PATH);

    Regards,

      Sudeesh.

     

    Friday, September 22, 2006 7:08 AM
  • Thanks but im not using MFC.

    An example would be great thanks.

    *edit*
    Could you give me an example using the CString Function
    Friday, September 22, 2006 7:19 AM
  •  daniboy120 wrote:
    Hi,
    [...] if i can make it so that when I type "hello" the compiler will automatically change it into UNICODE, instead of having to use the MultibyteToWideChar() function. [...]

    If you want to type "hello" into your program and ask the compiler to represent it in Unicode, then use the "L" suffix. For example:

     

    wchar_t unicodeString[] = L"hello";

     

    I hope this helps.

    Friday, September 22, 2006 7:26 AM
  • you can also use A2W (ATL conversion macros) for conversion.
    CString will allocate memory with wchar_t if UNICODE specified else it will be char*
    int MultiByteToWideChar(
    CP_ACP, // code page
    MB_PRECOMPOSED// character-type options
    pChInput, // string to map
    nSizeInput, // number of bytes in string
    pWchDest, // wide-character buffer
    nSizeDest // size of buffer
    );

    Friday, September 22, 2006 7:27 AM
  • Perfect thanks
    Friday, September 22, 2006 7:28 AM
  • _T() would be good choice than L"";
    because it will behave depends on the UNICODE definition
    Friday, September 22, 2006 10:10 AM