Pass main() Commands In WinMain() Function

Hello everyone,

I have the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
int main(int argc, char* argv[])
{
	if (argc!=3)
	{
		exit(1);
	}

	in=fopen(argv[1], "rb");
	if (!in)
	{
		exit(1);
	}
	out=fopen(argv[2], "wb");
	if (!out)
	{
		exit(1);
	}

	run();

	fclose(in);
	fclose(out);

	return 0;
}


Now, I want this to be a WinMain() function instead, so I change it to:

1
2
3
4
5
6
7
int WINAPI WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{

}


So, what I want to do is pass the following main() command in my WinMain function:

program.exe file1 file2

This will execute the run() function of my program with both arguments as "file1" and "file2".

How can I do this?
the following main() command

Do you mean "command line arguments"? You can get those through the third parameter to WinMain or using GetCommandLine if you need the program name; you can parse the command line using CommandLineToArgvW (there is no narrow version.)

https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx
There is __argc and __argv global variables defined automatically by the C runtime. These are not standard, but it works.
Thanks for the responses guys.

I will give these suggestions a try and see which works best.
Topic archived. No new replies allowed.