|
-
Oct 23rd, 2002, 04:51 PM
#1
Thread Starter
Addicted Member
Anyone know why this doesn't work
Does anyone know why this doesn't work?
Public Class Class1
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, ByVal NSize As Long) As Long
Public Function SysGetUserName() As String
Dim UserName As String
Dim BufSize As Long
Dim RetCode As Long
Dim NullCharPos As Long
UserName = Space(80)
BufSize = Len(UserName)
RetCode = GetUserName(UserName, BufSize)
NullCharPos = InStr(UserName, Chr(0))
If NullCharPos > 0 Then
UserName = Left(UserName, NullCharPos - 1)
Else
UserName = ""
End If
MsgBox(UserName)
End Function
End Class
-
Oct 23rd, 2002, 05:05 PM
#2
PowerPoster
My guess is that you are trying to access a API call using mismatched variable types.
Change your longs to integers, that might work. The integers in .Net are now what the API calls longs.
-
Oct 23rd, 2002, 06:21 PM
#3
Sleep mode
try using this structure :
Code:
try
' perform operation that will generates an error
catch x as system.exception
messagebox.show(x.message)
end try
hope this catches your bug
-
Oct 23rd, 2002, 08:18 PM
#4
Thread Starter
Addicted Member
The refernce is Object reference not set to an instance of an object.
Thanks
Jeremy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|