Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Get Username via DllCall

Keywords: 	 username DllCall  Advapi32.DLL

Question:

I have problem calling the function "GetUserNameA" in the dll Advapi32.dll. This is what i did but i get a Dr-Watson
dllname=strcat(dirwindows(1),"Advapi32.DLL")
PTRBB=BinaryAlloc(100) ; allocate a memory buffer of n bytes
a3 = 100
DllCall(dllname, lpstr:"GetUserNameA", lpbinary:PTRBB, long:a3)
BinaryEODSet(PTRBB,100) ; set the end of 
a2=BinaryPeekStr(PTRBB, 0, 100)
Message(a1,a2)
BinaryFree(PTRBB) 

Answer:

The basic problem was that the size variable was actually a pointer to the size variable, so it also had to be stuffed into a binary buffer.
dllname=strcat(dirwindows(1),"Advapi32.DLL")
bufsize=100
PTRBB=BinaryAlloc(bufsize) ; allocate a memory buffer of n bytes
PTRNAM=BinaryAlloc(4)
BinaryPoke4(PTRNAM,0,bufsize)
DllCall(dllname, long:"GetUserNameA", lpbinary:PTRBB, lpbinary:PTRNAM)
BinaryEODSet(PTRBB,100) ; set the end of 
username=BinaryPeekStr(PTRBB, 0, 100)
Message("Username",username)
BinaryFree(PTRBB) 
BinaryFree(PTRNAM)

Article ID:   W15134