Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 1998-12-22
4
241 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:tanmh
  • 3
4 Comments
 
LVL 11

Accepted Solution

by:
alexo earned 0 total points
ID: 1180820
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
 
LVL 11

Expert Comment

by:alexo
ID: 1180821
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
 

Author Comment

by:tanmh
ID: 1180822
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
 
LVL 11

Expert Comment

by:alexo
ID: 1180823
Actually I see no reason in restricting questions to a single expert (unless, of course, if those are "dummy" questions to award points).
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PDF library for Delphi 2 128
Compile GLUT with Visual Studio 2015 1 170
Socket Programming (Unix) 8 139
C++ error cannot convert from std::string to const char * 6 241
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question