1
#include <afxwin.h>
// TODO: add your code here
2
3 LPWSTR *szArglist = NULL;
4 int nArgs = 0;
5 szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
6 if (NULL != szArglist)
7 {
8 //szArglist就是保存参数的数组
9 //nArgs是数组中参数的个数
10 //数组的第一个元素表示进程的path,也就是szArglist[0],其他的元素依次是输入参数。
11 }
12 CString str1 = szArglist[1];
13 CString str2 = szArglist[2];
14 int a = atoi((LPSTR)(LPCTSTR)str1);
15 int b = atoi((LPSTR)(LPCTSTR)str2);
16 char msg[256];
17 int c = a + b;
18 sprintf_s(msg, "%d", c);
19 printf(msg);
20 //取得参数后,释放CommandLineToArgvW申请的空间
21 LocalFree(szArglist);
22
23 Caesar卢尚宇
24 2019年12月2日
转载自https://blog.csdn.net/bwmwm/article/details/4558439