Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to call the GetUserName() API function 1

Status
Not open for further replies.

psnead

Programmer
Jul 5, 2000
41
DK
Thanks to palbano, I was able to figure out how to get the directory path.  However, I am still confused about calling the GetUserName() API function.  I have always programmed on the UNIX operating system,and have just started programming with the Visual C++ software.  Could someone help clarify how to actually use API functions?  Will this function work with a simple DOS command line interface? What library do I need to include when calling this function? Any help would be much appreciated.
 
Hello,<br><br>you need to use the MSDN to find what you need to include and other explainations. When MSDN is install, simply select the function you want informations about and stroke F1 (sometime you need to do this twice when starting MSDN).<br><br>The header file is indicate in the QuickInfo at the end of the MSDN page. For GetUserName() API, it's winbase.h<br><br>I also comes from UNIX, and MSDN is like a (bad ?) man (the shell help command). Know that if you can choose your developpement software, I prefere the help of borland builder. But that's my opinion.<br><br>David.
 
David is correct. And if you don't have the MSDN CDROM you can find all the same information at msdn.microsoft.com.<br><br>-pete
 
There is no Command Line Interface to an Application Program Interface method.&nbsp;&nbsp;&nbsp;I guess if there were it would be a CLI ;) <br><br>For some functions there are replacements.&nbsp;&nbsp;For example, typing SET in a DOS window might shed light on your needs.<br><br>Also, You can create a &quot;wrapper&quot; application providing the command line interface you need.&nbsp;&nbsp;Some of my favorite wrapper applications are sleep and log.&nbsp;&nbsp;Sleep suspends procesing for a number of seconds and log adds a date time stamp in fromt of a text message.&nbsp;&nbsp;That brings you back to your start, that is, needing MSDN, which is addressed in previous responses.<br><br><br>Hope this helps...<br>Wil<br> <p>Wil Mead<br><a href=mailto:wmead@optonline.net>wmead@optonline.net</a><br><a href= > </a><br>
 
Wow, what a mess this has turned into.<br><br>psnead,<br><br>Are you attempting to use Visual C++ to produce a Win32 console application? If so there is a wizard in Visual C that will set up your project to include all the libraries for most of the Windows API's. All that is left is to include the header file for the API in question. That is where the MSDN SDK documentation comes in. It will tell you which header file is needed for a given API function.<br><br>The API GetUserName() will work in a Win32 Console application.<br><br>If your question is something else, please clarify.<br><br>Hope this helps<br>-pete
 
I appreciate all of the help.&nbsp;&nbsp;To be more precise, the application that I am working on calculates a number, and inserts that number into a certain location in a different file.&nbsp;&nbsp;However, each time this utility is run, the username, path, time and date are inserted into the file too, so that later on someone can tell who updated the file.&nbsp;&nbsp;Currently, the program is running in the DOS shell, on Win98(and soon WinNT), and I really don't see the need for a GUI wrapper -- unless of course I can't find any other way to get the username.&nbsp;&nbsp;But I find it hard to believe that there is not some kind of system call that would simply return the username to a DOS command line interface.&nbsp;&nbsp;<br>I am rewriting a VAX Pascal program for Windows, and my executable must be byte for byte the same as the executable generated by the VAX.&nbsp;&nbsp;Thanks again for the help.
 
We spent more time posting about this than it took to write the program, compile and test it!<br><br>Here drop this into a file named GetUserName.cpp, compile it and put the .EXE into your windows directory or anywhere on your PATH. Now you have a command line interface to the current user.<br><br>#include &lt;iostream&gt;<br>#include &lt;windows.h&gt;<br><br>int main(int argc, char* argv[])<br>{<br>&nbsp;&nbsp;const unsigned long BUFSIZE = 255;<br>&nbsp;&nbsp;unsigned long dwSize = BUFSIZE;<br>&nbsp;&nbsp;char pbuf[ BUFSIZE + 1];<br>&nbsp;&nbsp;GetUserName(pbuf, &dwSize);<br>&nbsp;&nbsp;std::cout &lt;&lt; (LPCTSTR)pbuf &lt;&lt; std::endl;<br>&nbsp;&nbsp;return 0;<br>}<br><br>-pete
 
Great News, palbano rules. The code does exactly as stated and will work great with the program (my first program out of school) I am working on.&nbsp;&nbsp;Thanks again for all the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top