How to get user log-in name? - for jhance

hi,
in relation to the previous qn i asked,
can u pls guide me on how to return the user name in a char buffer? I need to pass this data to other functions and
I am facing difficulties converting it to char buffer.

char* GetLogin()
{
    NET_API_STATUS netStatus;
    WKSTA_USER_INFO_0 *buf;
   
    netStatus = NetWkstaUserGetInfo(NULL, 0, (LPBYTE *)&buf);
    //wprintf(_T("Username is %s\n"), buf->wkui0_username);
    //NetApiBufferFree(buf);
    return buf->wkui0_username;
}


int main(int argc, TCHAR* argv[])
{
      char* buf = GetLogin();
      cout<<buf<<endl;
        return 0;
}


Thanks.
Andrea
tanmhAsked:
Who is Participating?
 
alexoConnect With a Mentor Commented:
static char buff[256];
LPWKSTA_USER_INFO_0 pBuff = NULL;
NetWkstaUserGetInfo(NULL, 0, (LPBYTE*)&pBuff);
WideCharToMultiByte(CP_ACP, 0, (LPWSTR)pBuff->wkui0_username, -1, buff, sizeof buff, NULL, NULL);
return buff;
0
 
alexoCommented:
OOps, sorry.  Didn't notice the "for jhance" part.  You can reject it if you want jhance to get the points (although the answer is correct...)
0
 
tanmhAuthor Commented:
hi alexo,
although it was for jhance but he didn't take up this question
and your answer is correct so it is only right that
I give you the marks.

Thanks.
Andrea
0
 
alexoCommented:
Actually I see no reason in restricting questions to a single expert (unless, of course, if those are "dummy" questions to award points).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.