Results 1 to 11 of 11

Thread: [RESOLVED] ShellExecuteA

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Location
    Pittsburgh
    Posts
    169

    Resolved [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?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ShellExecuteA

    Have you looked at using System.Diagnostics.Process.Start rather than ShellExecute?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Location
    Pittsburgh
    Posts
    169

    Thumbs up Re: ShellExecuteA

    Wow, excellent. Thanks very much the System.Diagnostics.process.start works fine and I elminated that complex routine I had been using.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ShellExecuteA

    Quote 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]

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width