PInvoke stack balance detected?
-
Hello, I've been searching the net on how to execute a dialup connection and came up with the following code:
Imports System.Runtime.InteropServices Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long Private Declare Function InternetAttemptConnect Lib "wininet" (ByVal dwReserved As Long) As Long Const scUserAgent = "ISP_Dialup" Const INTERNET_OPEN_TYPE_PRECONFIG = 0 Public Function ConnectToSISP() As Boolean Dim hInternet As Long If InternetAttemptConnect(0) <> 0 Then Exit Function hInternet = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0) ConnectToSISP = (hInternet <> 0) 'return False if hInternet=0 End Function
When my code reaches this pointIf InternetAttemptConnect(0) <> 0 Then Exit Function
I receive a message that states PInvoke stack balance detected... A call to PInvoke function 'Project1!Project1.Dialup::InternetAttemptConnect' has unbalanced the stack. I'm thinking maybe some how I am not referencing wininet.dll properly...any suggestions is greatly appreciated. Rashar -
Hello, I've been searching the net on how to execute a dialup connection and came up with the following code:
Imports System.Runtime.InteropServices Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long Private Declare Function InternetAttemptConnect Lib "wininet" (ByVal dwReserved As Long) As Long Const scUserAgent = "ISP_Dialup" Const INTERNET_OPEN_TYPE_PRECONFIG = 0 Public Function ConnectToSISP() As Boolean Dim hInternet As Long If InternetAttemptConnect(0) <> 0 Then Exit Function hInternet = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0) ConnectToSISP = (hInternet <> 0) 'return False if hInternet=0 End Function
When my code reaches this pointIf InternetAttemptConnect(0) <> 0 Then Exit Function
I receive a message that states PInvoke stack balance detected... A call to PInvoke function 'Project1!Project1.Dialup::InternetAttemptConnect' has unbalanced the stack. I'm thinking maybe some how I am not referencing wininet.dll properly...any suggestions is greatly appreciated. RasharRashar wrote:
Private Declare Function InternetAttemptConnect Lib "wininet" (ByVal dwReserved As Long) As Long
Try changing that to...
Private Declare Function InternetAttemptConnect Lib "wininet" (ByVal dwReserved As Integer) As Integer
Hope that helps :) In fact I think
InternetOpen
will also throw this error - you will need to change the parameterslAccessType As Long
andlFlags As Long
to beInteger
s, as well as the return value. You can use pinvoke.net[^] to look for Win32 API method signatures in C# and VB.Net.
“Accept that some days you are the pigeon, and some days you are the statue” -- David Brent Cheers, Will H -- modified at 13:32 Thursday 4th May, 2006