win32 app pass Parameters

G

Guest

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
 
T

Tom Shelton

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.
 
C

Cor Ligthert

Andre,

You can pass the information using an array of strings

I hope this helps?

Cor
 
G

Guest

Wow, That was easy.

Thanks all for the help.


Tom Shelton said:
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.
 
H

Herfried K. Wagner [MVP]

Tom,

Tom Shelton said:
<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.
 
C

Cor Ligthert

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
 
H

Herfried K. Wagner [MVP]

Cor Ligthert said:
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'.
 

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