473,378 Members | 1,280 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

cannot convert from <STRUCT_NAME> to ref <STRUCT_NAME>

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.InteropService*s.DllImport(
"mpr.dll",
EntryPoint="WNetAddConnection2*A",
ExactSpelling=false,

CharSet=System.Runtime.Interop*Services.CharSet.An si,
SetLastError=true)]
public static extern Int32 WNetAddConnection2(
ref NETRESOURCE
lpNetResource,
[MarshalAs(UnmanagedType.LPStr*)] string
lpPassword,
[MarshalAs(UnmanagedType.LPStr*)] string
lpUserName,
Int32 dwFlags);
[System.Runtime.InteropService*s.DllImport(
"mpr.dll",
EntryPoint="WNetCancelConnecti*on2A",
ExactSpelling=false,

CharSet=System.Runtime.Interop*Services.CharSet.An si,
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_PA*RAMETER_CAUSES_ERROR* *********************************

// \\server\wwwroot$\TEST\pgeCOMt*est.aspx.cs(85): The best
overloaded
method match for 'TEST.pgeCOMtest.WNetAddConnec*tion2(ref
TEST.pgeCOMtest.NETRESOURCE, string, string, int)' has some invalid
arguments
// \\server\wwwroot$\TEST\pgeCOMt*est.aspx.cs(86): Argument '1':
cannot
convert from 'TEST.pgeCOMtest.NETRESOURCE' to 'ref
TEST.pgeCOMtest.NETRESOURCE'
linResult = WNetAddConnection2(theNetResou*rce, "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(theNetRe*source.lpLocalName, 0,
0);
Response.End();
}
}
}

Nov 17 '05 #1
8 2195
When calling a method that expects a parameter by ref, C# requires that
you put the ref keyword in when you write the call to the method, not
just in the method declaration.

I imagine that its to make it clear that you are passing something by
reference.

HTH
Andy

Nov 17 '05 #2
Hi Gee

has to be
linResult = WNetAddConnection2( ref theNetResou*rce, "pwd", "dom_usr",
CONNECT_UPDATE_PROFILE);

If there is a ref in the declaration, there has also to be a ref in the
call.

Christof

"Gee" <in**@emmanuelsolutions.co.uk> schrieb im Newsbeitrag
news:11*********************@z14g2000cwz.googlegro ups.com...
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.InteropService*s.DllImport(
"mpr.dll",
EntryPoint="WNetAddConnection2*A",
ExactSpelling=false,

CharSet=System.Runtime.Interop*Services.CharSet.An si,
SetLastError=true)]
public static extern Int32 WNetAddConnection2(
ref NETRESOURCE
lpNetResource,
[MarshalAs(UnmanagedType.LPStr*)] string
lpPassword,
[MarshalAs(UnmanagedType.LPStr*)] string
lpUserName,
Int32 dwFlags);
[System.Runtime.InteropService*s.DllImport(
"mpr.dll",
EntryPoint="WNetCancelConnecti*on2A",
ExactSpelling=false,

CharSet=System.Runtime.Interop*Services.CharSet.An si,
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_PA*RAMETER_CAUSES_ERROR* *********************************

// \\server\wwwroot$\TEST\pgeCOMt*est.aspx.cs(85): The best
overloaded
method match for 'TEST.pgeCOMtest.WNetAddConnec*tion2(ref
TEST.pgeCOMtest.NETRESOURCE, string, string, int)' has some invalid
arguments
// \\server\wwwroot$\TEST\pgeCOMt*est.aspx.cs(86): Argument '1':
cannot
convert from 'TEST.pgeCOMtest.NETRESOURCE' to 'ref
TEST.pgeCOMtest.NETRESOURCE'
linResult = WNetAddConnection2(theNetResou*rce, "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(theNetRe*source.lpLocalName, 0,
0);
Response.End();
}
}
}
Nov 17 '05 #3
Gee
Thanks Andy and Christof!

I've also tried that but that gives me this error:
Use of unassigned local variable 'theNetResource'

Not sure what that means, but if it means that I've not assigned it a
value, in the code I've instantiated it and assigned values to it's
properties.

Any ideas?

Cheers,

-Gee.

Nov 17 '05 #4
Can you post the code where you instantiate it and then call the function?

Thanks,
Adam Clauss
"Gee" <in**@emmanuelsolutions.co.uk> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Thanks Andy and Christof!

I've also tried that but that gives me this error:
Use of unassigned local variable 'theNetResource'

Not sure what that means, but if it means that I've not assigned it a
value, in the code I've instantiated it and assigned values to it's
properties.

Any ideas?

Cheers,

-Gee.

Nov 17 '05 #5
Sorry, ignore previous post.

I do not see where you instantiate the NETRESOURCE. Add "= new
NETRESOURCE();"

NETRESOURCE theNetResource = new NETRESOURCE(); <---- ADD THIS
Enterprise01.Toolkit objToolkit;

---
Adam Clauss

"Gee" <in**@emmanuelsolutions.co.uk> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Thanks Andy and Christof!

I've also tried that but that gives me this error:
Use of unassigned local variable 'theNetResource'

Not sure what that means, but if it means that I've not assigned it a
value, in the code I've instantiated it and assigned values to it's
properties.

Any ideas?

Cheers,

-Gee.

Nov 17 '05 #6
Gee
Doh!

Simple as that eh! Damnit, it's these little oversights that take ages
to figure out! :-)

Thanks Adam!

-Gee.

Nov 17 '05 #7
Gee wrote:
Thanks Andy and Christof!

I've also tried that but that gives me this error:
Use of unassigned local variable 'theNetResource'

Not sure what that means, but if it means that I've not assigned it a
value, in the code I've instantiated it and assigned values to it's
properties.

Any ideas?

Cheers,

-Gee.


See also http://www.yoda.arachsys.com/csharp/parameters.html

Nov 17 '05 #8
It's always the little ones that take forever :)

Adam

"Gee" <in**@emmanuelsolutions.co.uk> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Doh!

Simple as that eh! Damnit, it's these little oversights that take ages
to figure out! :-)

Thanks Adam!

-Gee.

Nov 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michel | last post by:
Hi again all, I have a small issue. Here's an example dataset : F1 F2 F3 1 0.58 Hi 2 0.70 Hello 3 Fail Bye 4 <Null> Hi
3
by: Chris | last post by:
Hi, I have the following procedure below: I am getting 2 errors on compile: Argument '2': cannot convert from 'System.Data.SqlClient.SqlDataReader' to 'ref...
1
by: Gary | last post by:
I have a strange compile error. C2664 cannot convert parameter 2 from int to int... Earlier in my code I was setting up my dataset... I add an int field like so... ...
6
by: Tim Cartwright | last post by:
I have a page that has the login control on it, nothing else. This page inherits from a master page, neither page has any code in it. This page works perfectly when running on the WebDev debug web...
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
2
by: Christophe | last post by:
class A {} class B {} interface MyInterface { void method(A a); void method(B b); }
3
by: bg_ie | last post by:
Hi, I am using a API I downloaded from the internet programmed in C. I need the function below which works with this api in my c++ file - void StoreNoteCallback(void *context, int arglen,...
7
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be...
6
by: John | last post by:
The following code: int test = 1; bool isTrue = (bool)test; results in a compiler error: Cannot convert type 'int' to 'bool' wtf, any ideas on how to work around this?
1
by: gdavid | last post by:
Hi. I Have started using Visual C++ 2008 a month ago. I Tried to make a GUI calculator but i cannot convert the textbox's text with the atof() function. The function cannot convert String^ type into...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.