This is how i do it:
Code:
int main(int argc, char* argv[])
{
char fName[1024] = "";
int width = 0;
int height = 0;
//Loop through command arguments
for(int i = 0; i < argc; ++i)
{
//Check if it starts with a "-"
if(argv[i][0] == '-')
{
switch(argv[i][1])
{
//If we're setting the width variable
case 'w':
case 'W':
if(++i < argc)
width = atoi(argv[i]);
break;
//If we're setting the height variable
case 'h':
case 'H':
if(++i < argc)
height = atoi(argv[i]);
break;
}
//If it is not a command option (an option starting with '-'),
//its probably the name of the file that was dragged onto the exe
} else if(i == 1)
strncpy(fName, argv[i], sizeof(fName));
}
printf("File: %s\n", fName);
printf("Width: %i\n", width);
printf("Height: %i\n", height);
if(strlen(fName))
{
//Do something
}
return 1;
}
So it could pass this: myProg.exe fileToOpen.txt -W 32 -H 64
This would print
File: fileToOpen.txt
Width: 32
Height: 32
EDIT: Now that i look again, this may not be what you want