#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    India
    Posts
    9
    Rep Power
    0

    Unhappy UNICODE problem...


    I am trying to get username using NetWksaUserGetInfo...it
    puts username in LPWSTR format inside a buffer (pBuf)...then
    i copy it into TCHAR name[40]...the output of the program is (with
    user Amit) is :

    A Amit

    Why just "A" instead of entire name?? :(...i feel that there is
    some thing to do with UNICODE but exactly what it is ,is beyond
    me...plssss help...or even a link which discuss such a problem
    will b helpful...thanks...
    Amit...
    =============================================

    #ifndef _UNICODE
    #define _UNICODE
    #endif
    #include <windows.h>
    #include <lm.h>
    #include <iostream>
    #include <tchar.h>

    using namespace std;
    int main(void)
    {
    DWORD dwLevel = 0;
    LPWKSTA_USER_INFO_0 pBuf = NULL;
    NET_API_STATUS nStatus;
    TCHAR name[40];

    nStatus = NetWkstaUserGetInfo(NULL,
    dwLevel,
    (LPBYTE *)&pBuf);
    if (nStatus == NERR_Success)
    {
    if (pBuf != NULL)
    {
    strcpy(name ,(char *)pBuf->wkui0_username);
    wprintf(L"%s\n",name);
    wprintf(L"\t%s" ,pBuf->wkui0_username);
    }
    }
    if (pBuf != NULL)
    NetApiBufferFree(pBuf);
    return 0;
    }
  2. #2
  3. No Profile Picture
    .
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    296
    Rep Power
    13
    not sure, but i do know that unicode can be stored in 8 bit (utf8) or 16 bit (utf16) and even 32 bit (utf32?) sized numbers. utf16 is the most common i think, or at least the most prefered. if you were treating it as if it were 8 bit data that'd cause problems. you can imagine that the 2nd 8bit half of the 16 bit number on a usual english (low valued) character would be 0, and signal incorrectly the end? if treating 16bit unicode data as 8bit that is. just guessing.

    maybe have a look at www.unicode.org for some further info - there's some c code on there for dealing with unicode and they've got an email help list aswell
    Last edited by balance; July 6th, 2003 at 07:23 AM.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    India
    Posts
    9
    Rep Power
    0
    thanks balance...it was most probably the
    same problem as u mentioned...a bit searching
    on MSDN site gave wcsncpy() instead of
    strcpy for wide characters...

IMN logo majestic logo threadwatch logo seochat tools logo