ashrobo
Well-known member
hi all, ive got the following code from MSDN but couldnt get it to work. 
i added Microsoft.VisualBasic. because it wouldnt allow me to use Left
encountered the following error while trying to run it.
>> Ret = GetUserName(Buffer, 25) error occurs here
An unhandled exception of type System.NullReferenceException occurred in WindowsApplication3.exe
Additional information: Object reference not set to an instance of an object.
has anyone encountered this before? all help will be appreciated!
-ashrobo

Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
Dim Ret As Integer
Dim UserName As String
Dim Buffer As String
Buffer = New String(CChar(" "), 25)
Ret = GetUserName(Buffer, 25)
UserName = Microsoft.VisualBasic.Left(Buffer, InStr(Buffer, Chr(0)) - 1)
MsgBox(UserName)
i added Microsoft.VisualBasic. because it wouldnt allow me to use Left
encountered the following error while trying to run it.
>> Ret = GetUserName(Buffer, 25) error occurs here
An unhandled exception of type System.NullReferenceException occurred in WindowsApplication3.exe
Additional information: Object reference not set to an instance of an object.
has anyone encountered this before? all help will be appreciated!
-ashrobo