Solved

Shell Execute VB Error Message - Unbalanced Stack

Posted on 2007-03-22
1
983 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
ID: 18793899
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Table Size and Indexes in SQL Server 6 21
Mixed results 10 79
WPF MainWindow update textbox from another class... 6 102
SSIS 2010 Convert to SSIS 2013 On Different Box 3 56
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…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 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

21 Experts available now in Live!

Get 1:1 Help Now