G
Gee
I get the above error with this code and I can't figure out why? Any
ideas please? See code below - the actual error is included in the
code:
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);
private void Page_Load(object sender, System.EventArgs
e)
{
// Put user code to initialize the page here
Int32 intRes;
long linResult;
NETRESOURCE theNetResource;
Enterprise01.Toolkit objToolkit;
//' Set Resource Type
theNetResource.dwType = RESOURCETYPE_DISK;
//'Set Remote server & share name
theNetResource.lpRemoteName = "\\\\server\\share";
//'Set Local Path for share
theNetResource.lpLocalName = "F:";
//'Ensure the Username and Password are set correctly
//********************FIRST_PARAMETER_CAUSES_ERROR*********************************
// \\server\wwwroot$\TEST\pgeCOMtest.aspx.cs(85): The best
overloaded
method match for 'TEST.pgeCOMtest.WNetAddConnection2(ref
TEST.pgeCOMtest.NETRESOURCE, string, string, int)' has some invalid
arguments
// \\server\wwwroot$\TEST\pgeCOMtest.aspx.cs(86): Argument '1':
cannot
convert from 'TEST.pgeCOMtest.NETRESOURCE' to 'ref
TEST.pgeCOMtest.NETRESOURCE'
linResult = WNetAddConnection2(theNetResource, "pwd", "dom_usr",
CONNECT_UPDATE_PROFILE);
//***********************************************************************************
objToolkit = new
Enterprise01.ToolkitClass();
intRes = objToolkit.OpenToolkit();
if(intRes > 0)
{
Response.Write("Error opening
toolkit: " +
objToolkit.LastErrorString);
intRes =
objToolkit.CloseToolkit();
if(intRes > 0)
{
Response.Write("Error
closing toolkit: " +
objToolkit.LastErrorString);
linResult =
WNetCancelConnection2(theNetResource.lpLocalName, 0,
0);
Response.End();
}
}
}
ideas please? See code below - the actual error is included in the
code:
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);
private void Page_Load(object sender, System.EventArgs
e)
{
// Put user code to initialize the page here
Int32 intRes;
long linResult;
NETRESOURCE theNetResource;
Enterprise01.Toolkit objToolkit;
//' Set Resource Type
theNetResource.dwType = RESOURCETYPE_DISK;
//'Set Remote server & share name
theNetResource.lpRemoteName = "\\\\server\\share";
//'Set Local Path for share
theNetResource.lpLocalName = "F:";
//'Ensure the Username and Password are set correctly
//********************FIRST_PARAMETER_CAUSES_ERROR*********************************
// \\server\wwwroot$\TEST\pgeCOMtest.aspx.cs(85): The best
overloaded
method match for 'TEST.pgeCOMtest.WNetAddConnection2(ref
TEST.pgeCOMtest.NETRESOURCE, string, string, int)' has some invalid
arguments
// \\server\wwwroot$\TEST\pgeCOMtest.aspx.cs(86): Argument '1':
cannot
convert from 'TEST.pgeCOMtest.NETRESOURCE' to 'ref
TEST.pgeCOMtest.NETRESOURCE'
linResult = WNetAddConnection2(theNetResource, "pwd", "dom_usr",
CONNECT_UPDATE_PROFILE);
//***********************************************************************************
objToolkit = new
Enterprise01.ToolkitClass();
intRes = objToolkit.OpenToolkit();
if(intRes > 0)
{
Response.Write("Error opening
toolkit: " +
objToolkit.LastErrorString);
intRes =
objToolkit.CloseToolkit();
if(intRes > 0)
{
Response.Write("Error
closing toolkit: " +
objToolkit.LastErrorString);
linResult =
WNetCancelConnection2(theNetResource.lpLocalName, 0,
0);
Response.End();
}
}
}