Solved

A call to PInvoke function unbalanced the stack.

Posted on 2006-07-11
2
2,176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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