Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualKhatharr

Posted 06 January 2013 - 10:52 PM

Does the video file's name become the argument(char** argv) to my program? (Windows)
If you compiled as a console program then your main function's prototype should be something like:

int main(int argc, char** argv);

The argc is the ARGument Count. The argv is the ARGument Values.

argv[0] is the name of your executable (the program's own file name).
argv[1] is the first command-line argument
argv[2] is the second command-line argument

etc. The command-line arguments are separated by spaces, except when enclosed by double quotes:

myprog -play my test video.mp4

argc[0] -> myprog
argc[1] -> -play
argc[2] -> my
argc[3] -> test
argc[4] -> video.mp4

myprog -play "my test video.mp4"

argc[0] -> myprog
argc[1] -> -play
argc[2] -> my test video.mp4

If you compiled the program as a windows program then your entry point prototype looks something like:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);

hInstance is the instance handle for your program, which is required by some functions. This is incidentally the base address of the module in memory, but that's trivia. You can also get this value by calling GetModuleHandle(0).

hPrevInstance is typically not used and is shrouded in ancient secrets kept by a select order of monks who never leave the basement of the Redmond campus.

lpCmdLine is a pointer to your command line, excluding the program itself.

nCmdShow is just something to pass to ShowWindow() if you want. It has the indicated user preference for how the window should be shown at program start (start minimized, etc).

lpCmdLine is something like this:

Typed at command line:

myprog -play my test video.mp4

Contents of lpCmdLine:

-play my test video.mp4

In other words, it's everything that came after the program name except for the first space.

#1Khatharr

Posted 06 January 2013 - 10:52 PM

<blockquote class="ipsBlockquote" data-author="lride" data-cid="5018097"><p>Does the video file's name become the argument(char** argv) to my program? (Windows)</p></blockquote><br />If you compiled as a console program then your main function's prototype should be something like:<br /><br />int main(int argc, char** argv);<br /><br />The argc is the ARGument Count. The argv is the ARGument Values.<br /><br />argv[0] is the name of your executable (the program's own file name).<br />argv[1] is the first command-line argument<br />argv[2] is the second command-line argument<br /><br />etc. The command-line arguments are separated by spaces, except when enclosed by double quotes:<br /><br />myprog -play my test video.mp4<br /><br />argc[0] -&gt; myprog<br />argc[1] -&gt; -play<br />argc[2] -&gt; my<br />argc[3] -&gt; test<br />argc[4] -&gt; video.mp4<br /><br />myprog -play "my test video.mp4"<br /><br />argc[0] -&gt; myprog<br />argc[1] -&gt; -play<br />argc[2] -&gt; my test video.mp4<br /><br />If you compiled the program as a windows program then your entry point prototype looks something like:<br /><br />int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);<br /><br />hInstance is the instance handle for your program, which is required by some functions. This is incidentally the base address of the module in memory, but that's trivia. You can also get this value by calling GetModuleHandle(0).<br /><br />hPrevInstance is typically not used and is shrouded in ancient secrets kept by a select order of monks who never leave the basement of the Redmond campus.<br /><br />lpCmdLine is a pointer to your command line, excluding the program itself.<br /><br />nCmdShow is just something to pass to ShowWindow() if you want. It has the indicated user preference for how the window should be shown at program start (start minimized, etc).<br /><br />lpCmdLine is something like this:<br /><br />Typed at command line:<br /><br />myprog -play my test video.mp4<br /><br />Contents of lpCmdLine:<br /><br />-play my test video.mp4<br /><br />In other words, it's everything that came after the program name except for the first space.

PARTNERS