Search the Community
Showing results for tags 'GetUserNameEx'.
-
Hi ! I have difficulties to learn how to use WinAPI functions with DllCall. I red the (very good) >Tutorial on DllCall() & DllStructs. I understand the tutorial, but it's hard for me to apply it myself. For example, the function GetUserName (just an example, I know @username of course) : BOOL WINAPI GetUserName( _Out_ LPTSTR lpBuffer, _Inout_ LPDWORD lpnSize ); Parameters lpBuffer [out] A pointer to the buffer to receive the user's logon name. If this buffer is not large enough to contain the entire user name, the function fails. A buffer size of (UNLEN + 1) characters will hold the maximum length user name including the terminating null character. UNLEN is defined in Lmcons.h. lpnSize [in, out] On input, this variable specifies the size of the lpBuffer buffer, in TCHARs. On output, the variable receives the number of TCHARs copied to the buffer, including the terminating null character. If lpBuffer is too small, the function fails and GetLastError returns ERROR_INSUFFICIENT_BUFFER. This parameter receives the required buffer size, including the terminating null character. For me, the first parameter (lpBuffer) sould be a STR type (from AutoIt helpfile in DllCall) The second, a DWORD (I think), but the MSDN says it is the size of the lpBuffer, in TCHARs : what is it ? In >this topic, I found a solution for GetUserName : MsgBox(0, "", _GetUserName() ) Func _GetUserName() Local $tlpnSize = DllStructCreate("dword[255]") Local $aDLL = DllCall("Advapi32.dll", "int", "GetUserName", "str", "", "dword*", DllStructGetPtr($tlpnSize)) If @error Then Return SetError(@error, 0, 0) Return $aDLL[1] EndFunc I don't understand : - why using "int" instead of "bool" for the first parameter (as said in the MSDN page)? - why the second parameter value is empty ? - does TCHAR is equals to dword[255], how to find this by myself ? - why the last parameter is not DllStructGetPtr (I thought the size of the lpBuffer buffer should have been defined by DllStructGetSize) As you can see, I am a newbie for this, and I would like to understand more, but I don't know how .... Can someone give me some explanations or links ?? Thanks in advance, and sorry for the blurred question...
- 36 replies
-
- winapi
- GetUserName
-
(and 1 more)
Tagged with: