How to parse command line arguments in WinForms

Hello there, I'm a beginner in C++ and I'm writing a simple windows forms application. I need to be able to read command line arguments, as it plays an important part in the program's functionality.

I was wondering how exactly this can be done. I know that in console applications you can use the argc and argv parameters in main(), but this cannot be done in a windows form. I have searched and searched, but I didn't find anything useful (some C# specific methods came up, but I'm using C++). So I have hoped that I'd find the answer on a C++ dedicated forum. Do you have any suggestions?

I apologise if this is in the wrong section.
Last edited on
In a windows forms application you also get the command line.

1
2
3
4
5
6
7
8
9
10
[STAThreadAttribute]
int main(array<System::String^> ^args)
{
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 

	Application::Run(gcnew Form1());
	return 0;
}
Indeed this works, thank you. How do I get the number of arguments, though (the equivalent of argc)? I want to show a window that has instructions on how to use the program if no arguments are present.
You can use args->Length

for example
1
2
for (int i = 0; i < args->Length; i++)
    Console::WriteLine(args[i]);
Awesome, thanks again.
Topic archived. No new replies allowed.