hi, I am a new C++ user. I need help in using GetCommandLine Function, I want for example a simple program that copy a file using GetCommandLine Function.
Thank you all. It's true Hanst as Framework said I don't know how to use it. I want a simple example to learn from it. I am sorry but I am as a said a new C++ user
This will print the name of the program to cout. I tried this with MinGW, and somehow I couldn't get it to output it on the command line, but outputting on a file works.
GetCommandLine gives you the entire command line as passed to the program.
If you want to use the arguments, you're better off looking at argc and argv as passed to main. If you're using a Windows app with WinMain, they're still available as global variables __argc, __argv.
I am not very sure about __argc and __argv. I don't think those are standard.
Then again, it doesn't even matter - you only need GetCommandLine when working with Unicode parameters, otherwise you can just use the szCmdLine parameter.
#include <shellapi.h>
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR szCmdLine,
int iCmdShow)
{
LPWSTR *szArglist;
int nArgs = 0;
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
// do your work here
// Free memory allocated for CommandLineToArgvW arguments.
LocalFree(szArglist);
return 0;
}