Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. PInvoke stack balance detected?

PInvoke stack balance detected?

Scheduled Pinned Locked Moved Visual Basic
algorithmsdata-structurestutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rashar
    wrote on last edited by
    #1

    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 point If 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

    K 1 Reply Last reply
    0
    • R 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 point If 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

      K Offline
      K Offline
      kasik
      wrote on last edited by
      #2

      Rashar 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 parameters lAccessType As Long and lFlags As Long to be Integers, 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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups