Skip to main content
gamedev.net
🔒 Locked

Windows, GetCommandLine()

Started by Brobanx 2 replies 650+ views
Original Post
Brobanx
Brobanx
Here''s my problem: When I call GetCommandLine(), sometimes (depending on how the program was executed), it returns the command line with the executable name included (ex: myprog.exe -arg1 -arg2), and sometimes without (ex: -arg1 -arg2). Is there any way to get exclusively the command line arguments, without the executable name in front? (checking the first argument against a constant wouldn''t work if the user were to rename the file).
Dean Harding
Dean Harding
I''m pretty sure that should never happen, unless maybe you''re using DDE... ?

Anyway, you can get the name of the executable using GetModuleFileName and passing in NULL for hModule. Then you can compare with the argument string (obviously, a string comparison isn''t good enough, you''ll to make sure they point to the same file...)

If I had my way, I''d have all of you shot!


codeka.com - Just click it.

Brobanx
Brobanx
Ok, thanks for the info guys. Turns out GetCommandLine() always includes the executable name as the first argument, so I can just skip it and go to the second argument.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.