Command Lines
Command Lines
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
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
- AndrewAPrice
- Member
- Posts: 2299
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
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.
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Did both of you wake up forgetting how to interpret dates?
Why revive this ancient topic?
Code: Select all
Wed Jan 02, 2002 8:22 am
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 !
Regards
inflater
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 !
Regards
inflater
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English )
Derrick operating system: http://derrick.xf.cz (Slovak and English )
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...
lets say the times from MegaTokyo. Wink Yay, when OSdev was moving from MT, I joined in ! Very Happy
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
That may be true... but this place wasn't even half as good until the mtDark2 themeJAAman 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
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Smooth dark blue gives you a headache? but bright white doesn't?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
That's Insanity! mtDark2 > Default
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
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