|
-
Jan 10th, 2008, 01:20 PM
#1
Thread Starter
Addicted Member
[RESOLVED] ShellExecuteA
Seem to be having a lot of problems switching an old VB6 API to work in .NET. I was using the ShellExecuteA to open documents/images/drawings in their appropriate application. Now in .NET I'm getting an error that the call to PInvoke has unbalanced the stack. Does anyone know what that means or how to correct it?
-
Jan 10th, 2008, 01:34 PM
#2
Re: ShellExecuteA
Welcome to the Forums.
You need to declare it correctly for .NET.
Code:
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("shell32.dll", CharSet:=CharSet.Auto, EntryPoint:="ShellExecute")> _
Private Shared Function ShellExecute( _
ByVal hwnd As IntPtr, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Integer) As Integer
End Function
End Class
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 10th, 2008, 01:36 PM
#3
Re: ShellExecuteA
Have you looked at using System.Diagnostics.Process.Start rather than ShellExecute?
-
Jan 10th, 2008, 01:38 PM
#4
Re: ShellExecuteA
That is an equilivalent but ShellExecute API may still be needed over process.start in some instances.
Plus he mentioned how to declare APIs in .NET
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 10th, 2008, 01:41 PM
#5
Re: ShellExecuteA
But, many times that is because he could be unaware there are .NET alternatives to APIs
I sure know I didn't know that when I started, and for a long keep using APIs that I no longer needed.
-
Jan 10th, 2008, 01:43 PM
#6
Re: ShellExecuteA
Yes, but there arent .NET equilivalents for most of the APIs.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 10th, 2008, 02:03 PM
#7
Re: ShellExecuteA
I've yet to run into a situation where in VB6 I used an API, and when converting to VB.NET, there wasn't a class available that I could use in its stead.
That could happen, but, so far it hasn't.
-
Jan 10th, 2008, 02:06 PM
#8
Thread Starter
Addicted Member
Re: ShellExecuteA
Wow, excellent. Thanks very much the System.Diagnostics.process.start works fine and I elminated that complex routine I had been using.
-
Jan 10th, 2008, 02:12 PM
#9
Re: ShellExecuteA
Ok great. 
Ps, dont forget to Resolve your thread from the Thread Tools menu so others know your question has been answered.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 10th, 2008, 02:19 PM
#10
Re: ShellExecuteA
 Originally Posted by schaefer
Wow, excellent. Thanks very much the System.Diagnostics.process.start works fine and I elminated that complex routine I had been using.
I'm glad...as I mentioned, for the most part, the APIs that you using in VB6 can be handled by a .NET class, so before just porting the APIs over, I would do some research, or perhaps post a question here in the .NET section, on what would be the VB.NET equivalent to [insert API name here]
-
Jan 10th, 2008, 02:59 PM
#11
Re: [RESOLVED] ShellExecuteA
Well there really isnt too many .NET equilivalents of APIs. There are over over 7,000 new APIs for Vista alone and most of the common ones dont have equilivalents.
For example:
SendMessage, PostMessage, FindWindow, FindWindowEx, GetWindowLong, SetWindowLong etc. all are very commly used in VB 6 apps but have no equilivalents in .NET.
SendKeys is not an equilivalent as it doesnt directly send the contents to a specific window but rather whichever window has the input focus.
Unmanaged API code in .NET is definately something to learn.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|