473,386 Members | 2,078 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,386 software developers and data experts.

WNetAddConnection2 call: "PInvokeStackImbalance was detected"


I'm getting this message in Visual Studio 2005:
PInvokeStackImbalance was detected

Message: A call to PInvoke function
'Refresh!Refresh.Main::WNetAddConnection2' has unbalanced the stack.

This is likely because the managed PInvoke signature does not match
the unmanaged target signature. Check that the calling convention
and parameters of the PInvoke signature match the target unmanaged
signature.

My goal is to connect to a remote filesystem. I don't want to
create a mapping to the filesystem. I just want to connect using the
login name and password that I already have. The web sites that I
googled around at stated that WNetAddConnection2() could be used for
this purpose, particularly

<http://groups.google.com/group/micro...works/browse_t
hread/thread/f61e50f43601670b/005f911e0da84edc?lnk=st&q=LOGON+VPN+VB&rnum=7&
hl=en#>

The code in question is this:
' dwFlags values.
Private Const CONNECT_UPDATE_PROFILE As Long = &H1
Private Const CONNECT_INTERACTIVE As Long = &H8
Private Const CONNECT_PROMPT As Long = &H10

' dwType values.
Private Const RESOURCETYPE_ANY As Long = &H0
Private Const RESOURCETYPE_DISK As Long = &H1
Private Const RESOURCETYPE_PRINT As Long = &H2
Private Const RESOURCETYPE_RESERVED As Long = &H8
Private Const RESOURCETYPE_UNKNOWN As Long = &HFFFFFFFF

' dwScope values.
Private Const RESOURCE_CONNECTED As Long = &H1
Private Const RESOURCE_GLOBALNET As Long = &H2
Private Const RESOURCE_REMEMBERED As Long = &H3
Private Const RESOURCE_RECENT As Long = &H4
Private Const RESOURCE_CONTEXT As Long = &H5

' dwDisplayType values.
Private Const RESOURCEDISPLAYTYPE_DOMAIN As Long = &H1
Private Const RESOURCEDISPLAYTYPE_GENERIC As Long = &H0
Private Const RESOURCEDISPLAYTYPE_SERVER As Long = &H2
Private Const RESOURCEDISPLAYTYPE_SHARE As Long = &H3

Private Const RESOURCEUSAGE_CONNECTABLE As Long = &H1
Private Const SW_SHOWNORMAL As Long = 1

Private Declare Function WNetAddConnection2 Lib "mpr.dll" _
Alias "WNetAddConnection2A" _
(ByVal lpNetResource As NETRESOURCE, _
ByVal lpPassword As String, _
ByVal lpUserName As String, _
ByVal dwFlags As Long) As Long

' The examples used Private Type but Visual Studio complained
' and said that Structure was now preferred.

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
' Function code here.
Dim netstruct As New NETRESOURCE
Dim errcode As Long

With netstruct
.dwScope = RESOURCE_GLOBALNET
.dwType = RESOURCETYPE_ANY
.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
.dwUsage = RESOURCEUSAGE_CONNECTABLE
.lpRemoteName = backup_base_dir
.lpLocalName = vbNullString
.lpProvider = vbNullString
End With

errcode = WNetAddConnection2(netstruct, _
strLogPass, strLogName, _
CONNECT_INTERACTIVE Or CONNECT_UPDATE_PROFILE)

Am I using contradictory options? Or am I using the wrong function
to begin with?

Thanks,

--
-john

February 28 1997: Last day libraries could order catalogue cards
from the Library of Congress.
Jun 8 '07 #1
2 4831
"John M. Gamble" <jg*****@ripco.comschrieb:
I'm getting this message in Visual Studio 2005:
PInvokeStackImbalance was detected

Message: A call to PInvoke function
'Refresh!Refresh.Main::WNetAddConnection2' has unbalanced the stack.

[...]
I assume you took the sample from a VB6 projekt or code repository. Note
that VB 2005 is not a technical successor of VB6 and code is generally not
compatible between the two programming languages. Whereas 'Long' was a
32-bit data type in VB6, it's a 64-bit type in VB.NET. Thus you'll have to
modify your declarations, constants, and structures accordingly (this means,
changing 'Long' to 'Integer' or 'Int32', with some exceptions). Note that
some additional modifications of the source code may be necessary in order
to make the code work.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jun 8 '07 #2
In article <uw**************@TK2MSFTNGP06.phx.gbl>,
Herfried K. Wagner [MVP] <hi***************@gmx.atwrote:
>"John M. Gamble" <jg*****@ripco.comschrieb:
>I'm getting this message in Visual Studio 2005:
PInvokeStackImbalance was detected

Message: A call to PInvoke function
'Refresh!Refresh.Main::WNetAddConnection2' has unbalanced the stack.

[...]

I assume you took the sample from a VB6 projekt or code repository. Note
Hmm. The claim was that it was from a dotnet source, but given the other
change I had to make I am suspicious.
>that VB 2005 is not a technical successor of VB6 and code is generally not
compatible between the two programming languages. Whereas 'Long' was a
32-bit data type in VB6, it's a 64-bit type in VB.NET. Thus you'll have to
modify your declarations, constants, and structures accordingly (this means,
changing 'Long' to 'Integer' or 'Int32', with some exceptions). Note that
some additional modifications of the source code may be necessary in order
to make the code work.
Thanks, I'll start with that.

--
-john

February 28 1997: Last day libraries could order catalogue cards
from the Library of Congress.
Jun 8 '07 #3

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

Similar topics

6
by: Matt Bostock | last post by:
Hi, When I validate this page: http://www.drfunkenstein.net/using http://jigsaw.w3.org/css-validator/, I get the following results: ...
3
by: Laura | last post by:
I've just installed the DB2 Run-time client in a Solaris machine. Then I finnish the installation configuring the connection: 1. machine catalog was OK: ========================== $ db2 catalog...
3
by: ebj | last post by:
I get this error message from time to time in my new app: "CallbackOnCollectedDelegate was detected Message: A callback was made on a garbage collected delegate of type...
0
by: GB | last post by:
All, I raised a problem a while ago about custom cultures in .NET and an error whereby a "Resource lookup failed - infinite recursion detected" exception was raised. Usually this was raised when...
3
by: NaeiKinDus | last post by:
Hello, i'm trying to program a thread that would be locked (by a mutex) and that would only be unlocked once that a function (generating data) is done. The purpose is to generate data, and unlock...
2
by: John M. Gamble | last post by:
I'm getting this message in Visual Studio 2005: PInvokeStackImbalance was detected Message: A call to PInvoke function 'Refresh!Refresh.Main::WNetAddConnection2' has unbalanced the stack. ...
4
by: Pool | last post by:
I tried to connect DB2 (Sitting in Unix server at my client location) using Db2 connect V8. I am getting the following error message. I tried all the possible options BUt the error is same.. See each...
10
by: =?Utf-8?B?TWF0dA==?= | last post by:
I am using the following code to connect to and download files from an ftp server, but the Symantec anti-virus software on some of my customers machines tells them that their computers are...
3
by: cie | last post by:
Hi, anyone please help me when I try to close a connection to the database from a static method, "Unreachable code detected" error occured. What's the problem actually? Thank you before
1
by: itxharsh | last post by:
/* While running the program a runtime error occurs."glibc detected" followed by a lot of memory address/instruction errors. Please help rectify this error.*/ /*Header file:"nonpreemptive.h" is as...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.