D
Doug Bell
Hi
In VB I used to call a Windows API from VB to get the User's Name and
Workstation Name
I have just started to try and pick up some Dot Net by rewriting one of my
small Applications and I can't see how to invoke these calls in Dot Net.
Declare Function GetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long)
As Long
Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal pBuffer As String, nSize As
Long) As Long
Function dacUser() As String
If Len(gstrUserName) = 0 Then
Dim stUser As String
Dim lngCnt As Long, lngDL As Long
Dim sngPos As Single
lngCnt = 199
stUser = String(200, 0)
lngDL = GetUserName(stUser, lngCnt)
stUser = Left(stUser, lngCnt) & lngCnt
sngPos = InStr(1, stUser, Chr(0))
If sngPos > 0 Then
gstrUserName = Left(stUser, sngPos - 1)
End If
End If
dacUser = gstrUserName
End Function
I tried replacing String with StrDup but can't get it to work
Can someone help?
In VB I used to call a Windows API from VB to get the User's Name and
Workstation Name
I have just started to try and pick up some Dot Net by rewriting one of my
small Applications and I can't see how to invoke these calls in Dot Net.
Declare Function GetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long)
As Long
Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal pBuffer As String, nSize As
Long) As Long
Function dacUser() As String
If Len(gstrUserName) = 0 Then
Dim stUser As String
Dim lngCnt As Long, lngDL As Long
Dim sngPos As Single
lngCnt = 199
stUser = String(200, 0)
lngDL = GetUserName(stUser, lngCnt)
stUser = Left(stUser, lngCnt) & lngCnt
sngPos = InStr(1, stUser, Chr(0))
If sngPos > 0 Then
gstrUserName = Left(stUser, sngPos - 1)
End If
End If
dacUser = gstrUserName
End Function
I tried replacing String with StrDup but can't get it to work
Can someone help?