The two methods:
The first type:
1 intWINAPI _tWinMain (hinstance hinstance, hinstance/*hprevinstance*/, LPTSTR Lpstrcmdline,intncmdshow) {2 intARGC =0;3LPWSTR *argv=NULL;4 //splitting command-line arguments5 uses_conversion;6LPCWSTR temp=a2w (lpstrcmdline);7argv= COMMANDLINETOARGVW (temp, &argc);8 //There are two parameters argc argv, unlike the console program: The number of ARGC is the actual number of parameters, not including the. \test.exe itself. ARGV, Argv[0] is the first parameter, not a. \test.exe9 //This method has a flaw, when the command parameter has a space, parsing fails, resulting in incomplete parameters. Ten}
The second type:
1#include <misc/cmdline.h>2 intWINAPI _tWinMain (hinstance hinstance, hinstance/*hprevinstance*/, LPTSTR Lpstrcmdline,intncmdshow) {3 cmdline cmdline;4 CmdLine. Analyze (lpstrcmdline);5 6 if(CmdLine. Hasparam ("Test")){7printf"%s", cmdline["Test"]);8 }9 } Ten //This method in the command line parameter input is key:value form, in the program can use KEY to get value, the class also has SetParam and other methods, please refer to the source code. OneUse the. \test.exe-key:value
At this point two methods are finished, there are suggested small partners can give me comments.
If you want to reprint, please indicate the source: http://www.cnblogs.com/guozht/7680893.html
Windows WTL using command-line arguments