【发布时间】:2016-05-17 16:42:37
【问题描述】:
VS10、MBCS、Unicode 预处理器定义。 浏览了 Google 博士的案例手册后,最好的帮助是 here,但它并不能完全解决这个特殊问题。考虑以下代码,其中 thisexePath 是可执行文件的路径:
cmdLineArg = (wchar_t *)calloc(BIGGERTHANMAXPATH, sizeof(wchar_t));
wcscpy_s (cmdLineArg, maxPathFolder, L"\\\\??\\C:\\My directory\\My directory\\");
CreateProcessW (thisexePath, cmdLineArg, NULL, NULL, FALSE, NULL, NULL, NULL, &lpStartupInfo, &lpProcessInfo)
程序调用时
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
wchar_t hrtext[256];
swprintf_s(hrtext, sizeof(hrtext), L"%ls", lpCmdLine);
//deal with possible buffer overflow later
MessageBoxW(NULL, hrtext, L"Display", MB_ICONINFORMATION);
}
hrtext 只显示“我的目录\我的目录\”这里明显遗漏了什么?
【问题讨论】:
-
swprintf_s(hrtext, sizeof(hrtext), L"%ls", lpCmdLine);第二个参数似乎是错误的。它应该表示字符数,而不是字节数。 -
您希望显示什么?我在您的帖子中没有看到任何建议显示除“我的目录\我的目录\”之外的其他内容。
-
`\\\\??\\C:\`发生了什么?它会被自动切断还是什么的?
-
"\\\\??\\"不是有效前缀。这应该是"\\\\?\\",并带有一个问号(请参阅 Naming Files, Paths, and Namespaces)。 -
@IInspectable:在自己的代码中一直使用它并取得了不错的效果(大部分情况下)。从一个古老的 OSR 线程中得到它。 here 也提出了这个问题 - 看起来它与 DOSDeviceNames 的符号链接有关。
标签: c++ process command arguments truncate