Select to view content in your preferred language

Identical Code (Doesn't throw errors in either) - Works in VB, Doesn't in .NET

2372
4
04-15-2010 09:35 AM
JustinRiggs
Emerging Contributor
I ran across a great ArcScript that opens an .exe from inside ArcMap, which is exactly what I needed. The example says to create a UI button, drop the code into a module, and then call the subroutine in the OnClick event. POOF! Works like a charm. I'm excited, but I need to get this into a .dll, because I have to deploy it on many, many machines.

I go to vs2005. I create a new Class Library, add the proper references, let the wizard generate the necessary information and so on and so on. Then I add the code, which looks like this:

Const SW_SHOW = 1
Const SW_SHOWMAXIMIZED = 3

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

Sub RunMozillaFirefox()
Dim RetVal As Long
On Error Resume Next
RetVal = ShellExecute(0, "open", "C:\Program Files\Mozilla Firefox\firefox.exe", "www.google.com", _
"", SW_SHOWMAXIMIZED)
End Sub

and call RunMozillaFirefox in the OnClick subroutine.

I go to ArcMap, hit "Tools --> Customize --> Commands

My command is there! Now I'm getting really excited.

I drag the command onto a toolbar, click on it, and... nothing. nada. zero, zip, zilch.

Can anybody tell me why this code works when its placed in a module, but not when its compiled as part of a .dll?

Thanks in advance...

Justin
0 Kudos
4 Replies
NeilClemmons
Honored Contributor
One possibility is your Declare statement for the API call.  In VB6/VBA, a Long is a 32-bit integer.  In VB.NET, a Long is a 64-bit integer.  You should change the Declare statement to use Integer or Int32 instead of Long.
0 Kudos
KirkKuykendall
Deactivated User
I'd take a look at the System.Diagnostics.Process.Start static method, that way you wouldn't have to hardwire for a particular browser.
http://dotnetperls.com/process-start-examples-vbnet
0 Kudos
JustinRiggs
Emerging Contributor
Neil, you're a life saver. That worked a charm. Thanks much.
0 Kudos
JustinRiggs
Emerging Contributor
Kirk,

Thanks for the advice on that. I'm not actually using Firefox - that was just the code from the ArcScript example. I'm opening an application (or several, actually - like Word, Excel, and then my custom app). I'll check out the method anyway. I need to start learning how to use the documentation better anyway.

Justin
0 Kudos