【发布时间】:2016-04-22 18:32:46
【问题描述】:
我最近开始使用 Visual C++,并且正在尝试掌握处理参数的窍门。我正在尝试使用CommandLineToArgvW() 创建一个参数数组,但是当将数组中的值传递给消息框时,只打印第一个字符,而不是整个字符串。例如,如果我使用ProjectName.exe test abc 123 运行程序,我将得到 4 个消息框,分别显示“P”、“t”、“a”和“1”。我在这里做错了什么?
int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR lpCmdLine, int show) {
int argNum, i;
LPWSTR *argList;
argList = CommandLineToArgvW(GetCommandLineW(), &argNum);
if (NULL == argList)
{
wprintf(L"CommandLineToArgvW failed\n");
return 0;
}
else
{
for (i = 0; i < argNum; i++)
{
int msgboxID2 = MessageBox(
NULL,
(LPCSTR)argList[i],
(LPCSTR)"Arguments",
MB_OK
);
}
}
return 0;
}
【问题讨论】:
标签: c++ arrays visual-c++ messagebox