Click to See Complete Forum and Search --> : Command Line Parameters


RubbeR DuckY
March 28th, 2008, 03:52 PM
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)


How can I parse lpCmdLine to get a filename passed if there are other command line parameters. For example, if the parameters are as follows:

/test /silent /play C:\test.wmv

How can I get the file name if I do not know where it will be. The way I do it in other languages is replace known command line parameters.

If /test exists, replace it with an empty string and set a variable.
If /silent exists, replace it with an empty string and set a variable.
If /play exists, replace it with an empty string and set a variable.

Now what I would be left with would be C:\test.wmv. Is there a better way to achieve this?

STLDude
March 28th, 2008, 04:19 PM
Here (http://www.codeproject.com/KB/cpp/SimpleOpt.aspx) and here (http://www.tenouk.com/ModuleY.html) are couple good articles which should give you plenty to read, enjoy.

RubbeR DuckY
March 29th, 2008, 12:05 AM
Am I blind? I did not see anything related to parsing a string for command line parameters. I know how to parse the arg array in main(), but not the string in WinMain? I also know there is an API that converts the lpCmdLine string to the arg[] array, however, I am looking to check if there are alternatives.

Thanks!

Marc G
March 29th, 2008, 10:17 AM
I think you could use the first link posted by STLDude by converting your lpCmdLine to an argv array with CommandLineToArgvW (http://msdn2.microsoft.com/en-us/library/bb776391(VS.85).aspx)

RubbeR DuckY
March 29th, 2008, 12:52 PM
Yup, that is the API that I was looking at. So I guess that is the best way to go then? I appreciate both of your inputs.