win32 app pass Parameters

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
Andre,

You can pass the information using an array of strings

I hope this helps?

Cor
 
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.
 
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.
 
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
 
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'.
 
Back
Top