Thread: unicode assignment

  1. #1
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164

    unicode assignment

    What's the best/correct way of assigning return values of non unicode functions to unicode char arrays?

    e.g. if I have defined _UNICODE, what would be the correct way to assign a return value from the following:

    Code:
    TCHAR *ip;
    ip = inet_ntoa(source.sin_addr);
    I'm guessing:

    Code:
    TCHAR *ip;
    char *iptemp;
    iptemp = inet_ntoa(source.sin_addr);
    #ifdef _UNICODE
        MultiByteToWideChar(0,0, iptemp, sizeof(*iptemp), ip, 256);
    #else
        *ip = *iptemp;
    #endif
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Well you need to allocate memory for your unicode string, but you have the right idea.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    There is a set of helper functions that perform memory allocation and conversion here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  3. <string> to LPCSTR? Also, character encoding: UNICODE vs ?
    By Kurisu33 in forum C++ Programming
    Replies: 7
    Last Post: 10-09-2006, 12:48 AM
  4. Should I go to unicode?
    By nickname_changed in forum C++ Programming
    Replies: 10
    Last Post: 10-13-2003, 11:37 AM
  5. UNICODE and GET_STATE
    By Registered in forum C++ Programming
    Replies: 1
    Last Post: 07-15-2002, 03:23 PM