Link to home
Start Free TrialLog in
Avatar of ewang1205
ewang1205

asked on

A call to PInvoke function unbalanced the stack.

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
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial