Command Lines

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
Jonozon(I forgot my pwd)

Command Lines

Post by Jonozon(I forgot my pwd) »

I am in the process of writing an application which plays a midi and then exits, It has no user interface or visible presence. What I need to know is this.
How can I parse command line arguments i.e.
"myapp.exe midifile.mid -repeats(5)"

I can already do the parsing of the midi filename, but I don't know how to add other arguments i.e. looping

I am writing it in Visual C++ 6, without MFC. My WinMain function looks like this:
[pre]
//--WinMain Function--//

int APIENTRY WinMain(HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR     lpCmdLine,
                    int       nCmdShow)
{
     MSG msg;
     s_lpCmdLine=lpCmdLine;

     ifstream iMidi( s_lpCmdLine, ios::nocreate );

     if ( iMidi.fail() ) {
           MessageBox(NULL,"Error:File does not exist","DarkWind Midi Player",NULL);
           return FALSE;
     }
     if(!Init(hInstance, nCmdShow)) {
           MessageBox(NULL,"Failed to Initialize","Error",NULL);
           CloseMusic();
           return FALSE;
     }


     while (GetMessage(&msg, NULL, NULL, NULL))
   {
       TranslateMessage(&msg);
       DispatchMessage(&msg);
   }

     return (msg.wParam);
}
[/pre]
How can I parse the Commandline?

Thanks,

Jonathan
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

Use std::string. Then you pass the array of command line arguments one by one through a switch statement. If "-repeats" is detected, point to the next argument, and convert that value into an int.
My OS is Perception.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

If you're not using a GUI, then why are you using WinMain and Translate/DispatchMessage?

Just use "int main(char argc, char **argv)" and they're there for you, all layed out in argv ;)
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

Did both of you wake up forgetting how to interpret dates?

Code: Select all

Wed Jan 02, 2002 8:22 am
Why revive this ancient topic?
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post by inflater »

MessiahAndrw does like reincarnation eh? :)
The "dead and buried" topics that hadn't been replied *doesn't matter if revived after 5, 10, 15 or 50 years :)*, could be a great opportunity for learning the things again, for those who didn't found an answer when searching the old forum section, lets say the times from MegaTokyo. ;) Yay, when OSdev was moving from MT, I joined in ! :D

Regards
inflater
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

...
lets say the times from MegaTokyo. Wink Yay, when OSdev was moving from MT, I joined in ! Very Happy
just one problem with your statement... OSdev didnt move from MT -- we were always here, we just agreed to take the people from the MT board when df decided to close the MT board -- iirc this board (at osdev.org) is older than the MT board
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

JAAman wrote:just one problem with your statement... OSdev didnt move from MT -- we were always here, we just agreed to take the people from the MT board when df decided to close the MT board -- iirc this board (at osdev.org) is older than the MT board
That may be true... but this place wasn't even half as good until the mtDark2 theme ;)
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
JackScott
Member
Member
Posts: 1031
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Contact:

Post by JackScott »

I disagree. I like this forum much more than MT, simply because it doesn't have the yucky dark theme as default!

Apparently the MT forums were added some time in 2000, and the OSdev.org ones in August of that year. Does anybody have any more idea what day they opened (specifically MT)?
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

i agree -- i really dont like the MT theme -- i read every post ever posted on both boards, but i always hated going to MT, because the color scheme there hurt my eyes and gave me a head-ache
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

JAAman wrote:i agree -- i really dont like the MT theme -- i read every post ever posted on both boards, but i always hated going to MT, because the color scheme there hurt my eyes and gave me a head-ache
Smooth dark blue gives you a headache? but bright white doesn't?

That's Insanity! mtDark2 > Default 8)
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post by JAAman »

no, reading text on a dark background does though...
and if i turn my brightness up really high on my monitor white can too...

the point is its too dark -- trying to make out dark text on that dark background was torture -- interestingly, its only the forums which had that horrible color combination -- the main site uses a white background, which is so much easier to read

the MT board was so bad it gave me a headache and made my eyes hurt -- i used to select the page before reading it, to invert the colors -- it did help some
User avatar
B.E
Member
Member
Posts: 275
Joined: Sat Oct 21, 2006 5:29 pm
Location: Brisbane Australia
Contact:

Post by B.E »

I agree with Brynet-Inc , the old MT theme was much better then the this one.
Image
Microsoft: "let everyone run after us. We'll just INNOV~1"
Post Reply