captkirk1001
New member
- Joined
- Jun 20, 2006
- Messages
- 3
- Programming Experience
- 10+
When I am receiving a PinvokeStackImbalance error when I execute the following code. I can not find the error. Any help would greatly be appreciated.
Public Class MapDrive
Private Structure NETRESOURCE
Dim dwScope As Long
Dim dwType As Long
Dim dwDisplayType As Long
Dim dwUsage As Long
Dim lpLocalName As String
Dim lpRemoteName As String
Dim lpComment As String
Dim lpProvider As String
End Structure
Private Const ERROR_SUCCESS = 0
Private Const CONNECT_UPDATE_PROFILE As Long = &H0
Private Const RESOURCETYPE_DISK As Long = &H1
Private Const RESOURCETYPE_PRINT As Long = &H2
Private Const RESOURCETYPE_ANY As Long = &H0
Private Const RESOURCE_GLOBALNET As Long = &H2
Private Const RESOURCEDISPLAYTYPE_SHARE As Long = &H3
Private Const RESOURCEUSAGE_CONNECTABLE As Long = &H1
Private Declare Function WNetAddConnection2 Lib "mpr.dll" _
Alias "WNetAddConnection2A" _
(ByRef lpNetResource As NETRESOURCE, _
ByVal lpPassword As String, _
ByVal lpUserName As String, _
ByVal dwFlags As Long) As Long
Private Declare Function WNetAddConnection Lib "mpr.dll" _
Alias "WNetAddConnectionA" _
(ByVal lpszNetPath As String, _
ByVal lpszPassword As String, _
ByVal lpszLocalName As String) As Integer
Private Sub MapCMM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MapCMM.Click
Dim NETR As NETRESOURCE
Dim errInfo As Long
Dim errInfoInt As Integer
Dim sServer As String
Dim sUsername As String
Dim sPassword As String
Dim sDriveLtr As String
sPassword = UserPass.Text
sUsername = UserName.Text
sServer = "\\server1\toolin"
sDriveLtr = "j:"
NETR.dwScope = RESOURCE_GLOBALNET
NETR.dwType = RESOURCETYPE_DISK
NETR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
NETR.dwUsage = RESOURCEUSAGE_CONNECTABLE
NETR.lpRemoteName = sServer
NETR.lpLocalName = sDriveLtr
NETR.lpComment = vbNullString
NETR.lpProvider = vbNullString
errInfo = WNetAddConnection2(NETR, sPassword, sUsername, CONNECT_UPDATE_PROFILE)
MsgBox(errInfo)
'errInfoInt = WNetAddConnection(sServer, sPassword, sDriveLtr)
'MsgBox(errInfoInt)
End Sub
End Class
Carol K
Public Class MapDrive
Private Structure NETRESOURCE
Dim dwScope As Long
Dim dwType As Long
Dim dwDisplayType As Long
Dim dwUsage As Long
Dim lpLocalName As String
Dim lpRemoteName As String
Dim lpComment As String
Dim lpProvider As String
End Structure
Private Const ERROR_SUCCESS = 0
Private Const CONNECT_UPDATE_PROFILE As Long = &H0
Private Const RESOURCETYPE_DISK As Long = &H1
Private Const RESOURCETYPE_PRINT As Long = &H2
Private Const RESOURCETYPE_ANY As Long = &H0
Private Const RESOURCE_GLOBALNET As Long = &H2
Private Const RESOURCEDISPLAYTYPE_SHARE As Long = &H3
Private Const RESOURCEUSAGE_CONNECTABLE As Long = &H1
Private Declare Function WNetAddConnection2 Lib "mpr.dll" _
Alias "WNetAddConnection2A" _
(ByRef lpNetResource As NETRESOURCE, _
ByVal lpPassword As String, _
ByVal lpUserName As String, _
ByVal dwFlags As Long) As Long
Private Declare Function WNetAddConnection Lib "mpr.dll" _
Alias "WNetAddConnectionA" _
(ByVal lpszNetPath As String, _
ByVal lpszPassword As String, _
ByVal lpszLocalName As String) As Integer
Private Sub MapCMM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MapCMM.Click
Dim NETR As NETRESOURCE
Dim errInfo As Long
Dim errInfoInt As Integer
Dim sServer As String
Dim sUsername As String
Dim sPassword As String
Dim sDriveLtr As String
sPassword = UserPass.Text
sUsername = UserName.Text
sServer = "\\server1\toolin"
sDriveLtr = "j:"
NETR.dwScope = RESOURCE_GLOBALNET
NETR.dwType = RESOURCETYPE_DISK
NETR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
NETR.dwUsage = RESOURCEUSAGE_CONNECTABLE
NETR.lpRemoteName = sServer
NETR.lpLocalName = sDriveLtr
NETR.lpComment = vbNullString
NETR.lpProvider = vbNullString
errInfo = WNetAddConnection2(NETR, sPassword, sUsername, CONNECT_UPDATE_PROFILE)
MsgBox(errInfo)
'errInfoInt = WNetAddConnection(sServer, sPassword, sDriveLtr)
'MsgBox(errInfoInt)
End Sub
End Class
Carol K