How to get cmdArgs in Windows Application (vs2005) ?

R

RBarryYoung

How can I get the following two features in the same program in
VS2005?:

1) Access to the command-line arguments (cmdArgs()) that started my
App.

2) Shutdown Mode = "When last Form exits".

The first feature requires a "Sub Main(cmdArgs())", however my app
exits when the Main Sub exits, EVEN if I have an open & running Form.

The second feature seems to require that I specify my project type as
"Windows Applicaiton" and enable "Application Framework" (is this
documented anywhere?). BUT, the Windows Application Framework has it's
own MAin Sub and apparently won't call mine. Even if it did, I doubt
that it would be nice and pass cmdArgs() to me.

Since this is the way that all VB apps used to work, I have to
believe that there is a way to do it. However, I sure cannot find it.

Help, please.

-- Barry Young
 
T

Toff McGowen

All applications require an entry point. In .Net executables that entry
point is the Main method. To get access to any arguments supplied via the
command line you simply iterate the args array of type string. This of
course requires that know that arg(0) means something specific, args(1)
means something else.... so it is highly application/order specific.
BUT, the Windows Application Framework has it's
own MAin Sub and apparently won't call mine. Even if it did, I doubt
that it would be nice and pass cmdArgs() to me.

Theres no reason why it should. You can designate your Main method as being
the main method for the application in project properties > Right Mouse
Click on your project in Solution Explorer. However beyond that there is no
reason why the VS designated main method cannot simply call your main method
and supply it the arguments from the command line.

If your application is exiting upon completion of Sub Main then you have not
started a messaging loop to for your starting/main form. You do this as
below via application.run:

Private Sub BootApplication()
Application.EnableVisualStyles()
Application.DoEvents()
Application.Run(New frmMain)
End Sub

You can google what the other methods mean. Note that application.run opens
a message loop and is different form creating an application domain in which
to run the application.

If you put code below application.run it will not be executed until
application.run returns. Application.run will not return until the main
application form is closed. This should answer your second question.

tm
 
H

Herfried K. Wagner [MVP]

1) Access to the command-line arguments (cmdArgs()) that started my
App.
[...]
The second feature seems to require that I specify my project type as
"Windows Applicaiton" and enable "Application Framework" (is this
documented anywhere?). BUT, the Windows Application Framework has it's
own MAin Sub and apparently won't call mine. Even if it did, I doubt
that it would be nice and pass cmdArgs() to me.

'Environment.GetCommandLineArgs'.
 
R

RBarryYoung

Thanks, Herfried. I have since discovered [My.Application.Commands]
which works also.

-- RBarryYoung
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top