我正在尝试在Windows 7的新环境下编译来自Windows XP的旧代码。它编译成功,但在运行时失败。
CreateProcess()返回0,GetLastError()返回2,表示ERROR_FILE_NOT_FOUND(找不到文件)。
以下是我的CreateProcess调用:
STARTUPINFO StartInfo;
memset(&StartInfo, 0, sizeof(StartInfo));
wcsncpy(astrCommandLine, L"TFTP", MAX_OSCOMMANDLINE_SZ-1);
BOOL bFuncRetn = CreateProcess(NULL,
astrCommandLine, // command line
NULL, // process security attributes
NULL, // primary thread security attributes
NULL, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&StartInfo, // STARTUPINFO pointer
&m_ProcInfo ); // receives PROCESS_INFORMATION
现在谈谈一些奇怪的事情:当我运行 calc 而不是 tftp 时,calc 弹出。我可以在命令提示符中从任何位置执行我的命令行,因此它告诉我 c:\windows\system32 的 %PATH% 已知并且工作正确。
我尝试强制使用 ansi 字符串创建 CreateProcessA,但得到了相同的结果。我还尝试了 debug 和 release 配置以及从命令行运行。
有什么想法吗?
编辑: calc.exe 和 tftp.exe 都位于 c:\windows\system32 中,它也在系统路径中。 运行 "c:\windows\system32\tftp" 不起作用。