Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

command line arguements

Status
Not open for further replies.

AndyHollywood

Programmer
Joined
Oct 7, 2001
Messages
30
Location
GB
Hello

I'm having trouble getting my win32 app to act on command line arguements!

I just want it to run a set of commands if the arguement is set to -a

what is a simple way of doing this?!

cheers in advance

Andy
 
sorry here it is:

int WINAPI WinMain (HINSTANCE hInst, HINSTANCE HPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
 
I haven't done much with the win32 api but I'm assuming that the best bet is to just do a regexp search on lpszCmdLine for "-a. It's my understanding that this string contains the entire command line call, but you can print it out and do a little testing just to make sure. Hope that helped a little. Good Luck. MYenigmaSELF:-9
myenigmaself@yahoo.com
 
Also if you just want to do a quick search an easy way is to encapsulate it in a CString and then call CString::FindOneOf("-a"). If "-a" isn't in the string the function will return -1, otherwise the returned value will be >= 0. MYenigmaSELF:-9
myenigmaself@yahoo.com
 
if your still interested, i managed to do it by:

if (0 == lstrcmpiA(lpszCmdLine, "-a"))


seems to work for just one argument, havent tried with anymore! if you want to know the results let me know!


cheers for the help

Andy
 
two things. Generaly you want your command line arguments to be case sensitive, so you would use lstrcmp instead of lstrcmpi, I assume the 'A' at the end is a typo. And using this method will fail if you have more than one argument. lstrcmp compares strings not only for equality but also if one string is greater than the other. if you want to use more than one argument you're going to need something more powerful than the lstrcmp comparator, which is why I gave you the CString code. That should work no matter how many arguments you have, so long as they are independant arguments(eg. you don't have -0 and -0a as arguments). Anyway, your code looks good for one argument. Good luck and let me know how things work out. MYenigmaSELF:-9
myenigmaself@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top