Solved

Shell Execute VB Error Message - Unbalanced Stack

Posted on 2007-03-22
1
979 Views
Last Modified: 2013-11-27
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
Comment
Question by:arsmed840
1 Comment
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 50 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

763 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

9 Experts available now in Live!

Get 1:1 Help Now