Results 1 to 4 of 4

Thread: Anyone know why this doesn't work

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207

    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

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    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.

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    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
  •  



Click Here to Expand Forum to Full Width