• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1034
  • Last Modified:

Shell Execute VB Error Message - Unbalanced Stack

Hi Experts

I am trying to open a doc file using a VB application.
The code I am using is as below:

Public 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

ShellExecute(0&, "Open", "MyFileName.doc", CommandLine, vbNullString, 1)

i end up in getting the error message "A call to PInvoke function 'SampleWorkFlowAppln!SampleWorkFlowAppln.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."

Any suggestions on what could be wrong?
0
arsmed840
Asked:
arsmed840
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You must be using VB.Net.

The problem is your API Declare is using VB6 data types.

In general, when converting API declares from VB6 to VB.Net, just change "Long" to "Integer":

    Public 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

But this doesn't matter since ShellExecute() isn't really needed for your case...

Just use:

    Process.Start("MyFileName.doc")

and the document should open.  =)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now