Oh, and another alternative to spit strings:
Main Topics
Browse All TopicsHello,
I have a small VC++ Program which would take a command line param and based on that, it would load an external program using create process.
The current code of the program is shown below. Lets assume the code is compiled into "code.exe", and lets says first param is called "--param1" and the second param is called "--param2"
when I execute:
>code --param1
then the GetCommandLine() is "code --param1"
>code.exe --param1
then the GetCommandLine() is "code.exe --param1"
The GetCommandLine() seems to give me exactly whats typed in the command prompt. However, what I'm interested is only in the parameter part. I would like to receive output as "--param1" for both conditions above.
I understand this could be done by finding the position of string "--" in the GetCommandLine() and then doing a sub string to extract everything to the left, however, I am finding difficult to do it on VC++, Data type mismatch errors and a lotta other caveats. Tried a few things, failed and now seeking yo experts help! :)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I think this question was asked before, please have a look at the solution below.
http://www.experts-exchang
>>>> LPSTR lpCmdLine,
Whay not simply using the lpCmdLine already passed to WinMain? It contains the arguments only, i. e. excludes the program name currently started.
You could do:
CString strArgs = lpCmdLine;
if (strArgs.Find("--param1") >= 0)
...
else if (strArgs.Find("--param2") >= 0)
...
>>>> I think this question was asked before, please have a look at the solution below.
No, that was a SDI applicatiion which has App::InitInstance but not WinMain as initial function.
Business Accounts
Answer for Membership
by: jkrPosted on 2009-09-07 at 14:22:33ID: 25277332
Why don't you convert that command line to an 'argv[]' style array for each parameter using 'CommandLineToArgvW()' (http://msdn.microsoft.com /en-us/lib rary/ bb776 391(VS.85) .aspx)? OK, you might have to convert it to a UNICODE string if you are compiling ANSI, yet that makes life a lot easier. Apart from that, the arguments are still available as '__argv[<num>]', e.g.
Select allOpen in new window