By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,569 Members | 1,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,569 IT Pros & Developers. It's quick & easy.

WNetCancelConnection2 - How to Force Disconnect?

P: n/a
Have tried varying declares for the api call, i need to close a
connection even if resources are open (damn perfcounters)
It suggests that you can use a true (dim as a bool in the api
declare), this doesn't work, it always tells me the
getlasterrormessage of
'This network connection has files open or requests pending.'

I've tried using 1,-1 (after dimming as a long) as values, but they
still fail also

TIA

Cheers

Mack

GtErrorMessage(WNet.WNetCancelConnection2("\\192.1 68.1.2",0, 0))

Class WNet
<StructLayout(LayoutKind.Sequential)> _
Public Class NETRESOURCE
Public dwScope As Integer
Public dwType As Integer
Public dwDisplayType As Integer
Public dwUsage As Integer
Public lpLocalName As String
Public lpRemoteName As String
Public lpComment As String
Public lpProvider As String
End Class

Public Declare Ansi Function WNetAddConnection2 Lib "mpr.dll"
Alias "WNetAddConnection2A" (ByVal lpNetResource As NETRESOURCE, ByVal
lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As
Integer) As Integer
Public Declare Ansi Function WNetCancelConnection2 Lib "mpr.dll"
Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags
As Long, ByVal fForce As Long) As Integer

End Class
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Mack,

A correct declare should look like this

Public Declare Auto Function WNetCancelConnection2 Lib "mpr.dll"
(ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As
Boolean) As Integer

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #2

P: n/a
I've tried that also, using true/false in the code, but it doesn't
make the slightest bit off difference, what exact value is the API
expecting? is it -1 ? does .net handle it's true/false equivalents
different to the API ?
On Tue, 26 Aug 2003 23:16:01 +0200, Mattias Sjögren
<ma********************@mvps.org> wrote:
Mack,

A correct declare should look like this

Public Declare Auto Function WNetCancelConnection2 Lib "mpr.dll"
(ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As
Boolean) As Integer

Mattias


Nov 20 '05 #3

P: n/a
I've tried that also, using true/false in the code, but it doesn't
make the slightest bit off difference
In that case I don't think the problem is in your VB.NET code, but
perhaps some quirk with the API. Have you gotten it to work in some
other programming language? Have you tried it on multiple versions of
Windows?

what exact value is the API expecting? is it -1 ?
The value of Win32's TRUE is 1, but functions typically just check for
a non-zero value.

does .net handle it's true/false equivalents different to the API ?


Yes

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 20 '05 #4

P: n/a
If i use the declaration as
Public Declare Auto Function WNetCancelConnection2 Lib "mpr.dll"
(ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As
Boolean) As Integer

then i get an error message
This network connection does not exist.

I guess this is due to the Ansi charset being used by the api?
if i use

Public Declare Ansi Function WNetCancelConnection2 Lib "mpr.dll"
(ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As
Boolean) As Integer

then i get the error
This network connection has files open or requests pending.

If I try changing what i am disconnecting, then it does throw the
above error, so it would suggest that using the Auto in the declare is
incorrect, since it would not appear to understand the string being
passed.

I've tried changing the boolean to an integer and passing 1, but that
fails also.
Cheers

Mack
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.