By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,452 Members | 1,571 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,452 IT Pros & Developers. It's quick & easy.

win32 app pass Parameters

P: n/a
Hi,

How do I create an win 32 app and pass parameters to have it respond to the
passed values?

Like winzip "winzip32 -a"

Kinda like Console args but I want to be able to call it via Start run
helloworld.exe – something

Can someone post a simple example or a link?

vb.net or C#
Thank you

Nov 16 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
On 2005-03-09, André <An**@discussions.microsoft.com> wrote:
Hi,

How do I create an win 32 app and pass parameters to have it respond to the
passed values?

Like winzip "winzip32 -a"

Kinda like Console args but I want to be able to call it via Start run
helloworld.exe ? something

Can someone post a simple example or a link?

vb.net or C#
Thank you


class MainForm : System.Windows.Forms
{
[STAThread ()]
public static void Main (string[] args)
{

foreach (string arg in args) {
ParseArg (arg);
}

Application.Run (new MainForm ());
}

private static void ParseArg (string arg)
{
MessageBox.Show (arg);
}
}

Obviously, you'll want to do something to the arguments. In VB.NET you
can do the exact same thing - you just declare Main like this:

<STAThread ()> _
Public Shared Sub Main (ByVal args() As String)
End Sub

or

<STAThread ()> _
Public Shared Function Main (ByVal args() As String) As Integer
End Sub

The VB.NET designer creates a hidden main method if you don't supply it.
So, all you have to do is type in the method signature and you are good
to go.

--
Tom Shelton [MVP]
Nov 16 '05 #2

P: n/a
Andre,

You can pass the information using an array of strings

I hope this helps?

Cor
Nov 16 '05 #3

P: n/a
That's the strangest .vb code I have ever seen! :)

Nov 16 '05 #4

P: n/a
Wow, That was easy.

Thanks all for the help.
"Tom Shelton" wrote:
On 2005-03-09, André <An**@discussions.microsoft.com> wrote:
Hi,

How do I create an win 32 app and pass parameters to have it respond to the
passed values?

Like winzip "winzip32 -a"

Kinda like Console args but I want to be able to call it via Start run
helloworld.exe ? something

Can someone post a simple example or a link?

vb.net or C#
Thank you


class MainForm : System.Windows.Forms
{
[STAThread ()]
public static void Main (string[] args)
{

foreach (string arg in args) {
ParseArg (arg);
}

Application.Run (new MainForm ());
}

private static void ParseArg (string arg)
{
MessageBox.Show (arg);
}
}

Obviously, you'll want to do something to the arguments. In VB.NET you
can do the exact same thing - you just declare Main like this:

<STAThread ()> _
Public Shared Sub Main (ByVal args() As String)
End Sub

or

<STAThread ()> _
Public Shared Function Main (ByVal args() As String) As Integer
End Sub

The VB.NET designer creates a hidden main method if you don't supply it.
So, all you have to do is type in the method signature and you are good
to go.

--
Tom Shelton [MVP]

Nov 16 '05 #5

P: n/a
Tom,

"Tom Shelton" <ts******@YOUKNOWTHEDRILLcomcast.net> schrieb:
<STAThread ()> _
Public Shared Function Main (ByVal args() As String) As Integer
End Sub


'STAThread' is IMO added implicitly, no need to specify it in VB.NET.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 16 '05 #6

P: n/a
Herfried,
'STAThread' is IMO added implicitly, no need to specify it in VB.NET.


It is not even needed to create a Shared Function Main, that is build in in
VB.Net.

Although I find it foolish to use it in VB.Net is everybody in my opinion
free to use it in the way he wants.

:-)

Cor
Nov 16 '05 #7

P: n/a
"Cor Ligthert" <no************@planet.nl> schrieb:
'STAThread' is IMO added implicitly, no need to specify it in VB.NET.
It is not even needed to create a Shared Function Main, that is build in
in VB.Net.


A parameterless 'Sub Main' is built in implicitly.
Although I find it foolish to use it in VB.Net is everybody in my opinion
free to use it in the way he wants.


Well, if you want to check the parameters passed to the application, I
strongly vote for using a custom 'Sub Main'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 16 '05 #8

P: n/a
In article <ub*************@TK2MSFTNGP15.phx.gbl>, Herfried K. Wagner [MVP] wrote:
Tom,

"Tom Shelton" <ts******@YOUKNOWTHEDRILLcomcast.net> schrieb:
<STAThread ()> _
Public Shared Function Main (ByVal args() As String) As Integer
End Sub


'STAThread' is IMO added implicitly, no need to specify it in VB.NET.


It maybe - but I tend to do things explicitly. Not always, but often :)

--
Tom Shelton [MVP]
Nov 16 '05 #9

P: n/a
In article <11**********************@z14g2000cwz.googlegroups .com>, Chris Dunaway wrote:
That's the strangest .vb code I have ever seen! :)


Well, he said C# or VB.NET. I usually do C# - so it just comes more
naturally :)
--
Tom Shelton [MVP]
Nov 16 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.