I'm new to using windows api's via vb.net.
I'm trying to dynamically create a network connection using WNetAddConnection2 and I keep getting ERROR_BAD_DEVICE.
MSDN states that this error means "The value specified by lpLocalName is invalid."
Any thoughts on how to resolve this error would be appreciated (thank you's in advance)
I'm initializing the lpLocalName as follows:
where NetR is a NETRESOURCE
I've defined the NETRESOURCE structure as follows:
My api functions are defined as follows:
----------
Sam
"Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest."
- Isaac Asimov
I'm trying to dynamically create a network connection using WNetAddConnection2 and I keep getting ERROR_BAD_DEVICE.
MSDN states that this error means "The value specified by lpLocalName is invalid."
Any thoughts on how to resolve this error would be appreciated (thank you's in advance)
I'm initializing the lpLocalName as follows:
Code:
NetR.lpLocalName = "Y:"
where NetR is a NETRESOURCE
I've defined the NETRESOURCE structure as follows:
Code:
<StructLayout(LayoutKind.Sequential, Pack:=1)> Public Structure NETRESOURCE
Public dwScope As Integer
Public dwType As Integer
Public dwDisplayType As Integer
Public dwUsage As Integer
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpLocalName As String
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpRemoteName As String
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpComment As String
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpProvider As String
End Structure
My api functions are defined as follows:
Code:
Public Declare Auto Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" ( _
ByVal lpNetResource As IntPtr, _
ByVal lpPassword As String, _
ByVal lpUserName As String, _
ByVal dwFlags As Integer) _
As Integer
Public Declare Auto Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" ( _
ByVal lpName As IntPtr, _
ByVal dwFlags As Integer, _
ByVal fForce As Boolean) _
As Integer
----------
Sam
"Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest."
- Isaac Asimov