Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

A call to PInvoke function unbalanced the stack.

Posted on 2006-07-11
2
Medium Priority
?
2,205 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 86

Expert Comment

by:Mike Tomlinson
ID: 17086015
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 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 17086049
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Integration Management Part 2
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

877 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