Hi List,

I'am trying to get the the current username under windows. After a =20
little searching I found the the following api call:


BOOL GetUserName(
   LPTSTR lpBuffer,
   LPDWORD lpnSize
);

In REBOL I tried the following:

lib: load/library %advapi32.dll ; no error
user: make routine! [arg1 [string!] agr2 [integer!] return: =20
[integer!]] lib "GetUserNameA" ; no error

name: make string! 1000
buffersize: 1000

user name buffersize ; crashes rebol

After hitting <enter> rebol crashes. I tried different values for name =20
and buffersize. I tried arg2 as string! type. Rebol then stops =20
crashing but no name or anything else is returnt.

Can someone give me a hint on what I 'am doing wrong? Or maybe is =20
there some other way to get the current user who is logged in?

Thanks Tim


I have included the official MS info:


Parameters

lpBuffer
     [out] A pointer to the buffer to receive the user's logon name. =20
If this buffer is not large enough to contain the entire user name, =20
the function fails. A buffer size of (UNLEN + 1) characters will hold =20
the maximum length user name including the terminating null character. =20
UNLEN is defined in Lmcons.h.
lpnSize
     [in, out] On input, this variable specifies the size of the =20
lpBuffer buffer, in TCHARs. On output, the variable receives the =20
number of TCHARs copied to the buffer, including the terminating null =20
character.

     If lpBuffer is too small, the function fails and GetLastError =20
returns ERROR_INSUFFICIENT_BUFFER. This parameter receives the =20
required buffer size, including the terminating null character.

     If this parameter is greater than 32767, the function fails and =20
GetLastError returns ERROR_INSUFFICIENT_BUFFER.

Return Value

If the function succeeds, the return value is a nonzero value, and the =20
variable pointed to by lpnSize contains the number of TCHARs copied to =20
the buffer specified by lpBuffer, including the terminating null =20
character.
-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to