Solved

A call to PInvoke function unbalanced the stack.

Posted on 2006-07-11
2
2,152 Views
Last Modified: 2008-02-20
I got this error when running the following code:
A call to PInvoke function 'tonin_image!tonin_image.Form1::ShellExecute' 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.


Public Class Form1

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles a.Click
        Dim HttpJump
        Dim MyUrl As String

        MyUrl = "http://server/default.aspx?lease=" + a.Text + "&file_sufx=" + File_Sufx.Text
        ShellExecute(0, "", MyUrl, "", "", vbNormalFocus)

    End Sub
End Class
0
Comment
Question by:ewang1205
  • 2
2 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
You've got a VB6 declaration there...

Convert all "Long" to "Integer" and you should be good to go:

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Integer, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Integer) As Integer
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
On a side note, you don't really need ShellExecute in VB.Net...

Try this instead:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles a.Click
        Process.Start("http://server/default.aspx?lease=" & a.Text & "&file_sufx=" & File_Sufx.Text)
    End Sub

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now