Convert VB.NET to C#.NET

G

Gee

Hi

Can anyone help me convert this to C# please?

Structure NETRESOURCE
Public dwScope As Int32
Public dwType As Int32
Public dwDisplayType As Int32
Public dwUsage As Int32
Public lpLocalName As String
Public lpRemoteName As String
Public lpComment As String
Public lpProvider As String
End Structure
'
Public Const NO_ERROR As Int32 = 0
Public Const CONNECT_UPDATE_PROFILE As Int32 = &H1
Public Const RESOURCETYPE_DISK As Int32 = &H1

'
Declare Function WNetAddConnection2 Lib "mpr.dll" Alias _
"WNetAddConnection2A" (ByRef lpNetResource As NETRESOURCE, _
<MarshalAs(UnmanagedType.LPStr)> ByVal lpPassword As String, _

<MarshalAs(UnmanagedType.LPStr)> ByVal lpUserName As String, _
ByVal dwFlags As Int32) As Int32
'
Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias _
"WNetCancelConnection2A" (ByVal lpName As String, _
ByVal dwFlags As Long, ByVal fForce As Long) As Long

Thanks,

-Gee.
 
M

Mythran

Gee said:
Hi

Can anyone help me convert this to C# please?

Structure NETRESOURCE
Public dwScope As Int32
Public dwType As Int32
Public dwDisplayType As Int32
Public dwUsage As Int32
Public lpLocalName As String
Public lpRemoteName As String
Public lpComment As String
Public lpProvider As String
End Structure
'
Public Const NO_ERROR As Int32 = 0
Public Const CONNECT_UPDATE_PROFILE As Int32 = &H1
Public Const RESOURCETYPE_DISK As Int32 = &H1

'
Declare Function WNetAddConnection2 Lib "mpr.dll" Alias _
"WNetAddConnection2A" (ByRef lpNetResource As NETRESOURCE, _
<MarshalAs(UnmanagedType.LPStr)> ByVal lpPassword As String, _

<MarshalAs(UnmanagedType.LPStr)> ByVal lpUserName As String, _
ByVal dwFlags As Int32) As Int32
'
Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias _
"WNetCancelConnection2A" (ByVal lpName As String, _
ByVal dwFlags As Long, ByVal fForce As Long) As Long

Thanks,

-Gee.

Off top of head:

struct NETRESOURCE {
public int dwScope;
public int dwType;
public int dwUsage;
public string lpLocalName;
public string lpRemoteName;
public string lpComment;
public string lpProvider;
}

public const int NO_ERROR = 0;
public const int CONNECT_UPDATE_PROVILE = 0x1;
public const int RESOURCETYPE_DISK = 0x1;

[DllImport("mpr.dll")]
public static extern int WNetAddConnection2(
ref NETRESOURCE lpNetResource,
[MarshalAs(UnmanagedType.LPStr)] string lpPassword,
[MarshalAs(UnmanagedType.LPStr)] string lpUserName,
int dwFlags
);

[DllImport("mpr.dll")]
public static extern int WNetCancelConnection2(
string lpName,
int dwFlags,
int fForce
);


HTH :)

Mythran
 
G

Guest

From our Instant C# VB.NET to C# converter:
(note that you can keep using the explicit System types - e.g., Int32)

public struct NETRESOURCE
{
public Int32 dwScope;
public Int32 dwType;
public Int32 dwDisplayType;
public Int32 dwUsage;
public string lpLocalName;
public string lpRemoteName;
public string lpComment;
public string lpProvider;
}
//
public const Int32 NO_ERROR = 0;
public const Int32 CONNECT_UPDATE_PROFILE = 0X1;
public const Int32 RESOURCETYPE_DISK = 0X1;

//
[System.Runtime.InteropServices.DllImport("mpr.dll",
EntryPoint="WNetAddConnection2A", ExactSpelling=false,
CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
public static extern Int32 WNetAddConnection2(ref NETRESOURCE
lpNetResource, [MarshalAs(UnmanagedType.LPStr)] string lpPassword,
[MarshalAs(UnmanagedType.LPStr)] string lpUserName, Int32 dwFlags);
//
[System.Runtime.InteropServices.DllImport("mpr.dll",
EntryPoint="WNetCancelConnection2A", ExactSpelling=false,
CharSet=System.Runtime.InteropServices.CharSet.Ansi, SetLastError=true)]
public static extern long WNetCancelConnection2(string lpName, long
dwFlags, long fForce);

David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter
and the Instant VB C# to VB.NET converter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top