CreateProcess fails under windows 7
I'm trying to compile legacy code from Windows XP under a new environment in Windows 7. It compiles but fails at runtime.
CreateProcess() returns 0 and GetLastError() ret开发者_如何学Pythonurns 2, which stands for ERROR_FILE_NOT_FOUND
Here is my call to 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
Now for the oddities : When instead of tftp I run calc, calc pops up. I can execute whatever is on my command line from anywhere in a command prompt so it tells me that the %PATH% to c:\windows\system32 is known and works correctly.
I tried to force CreateProcessA with ansi strings but I got the same result. I also tried in debug and release configuration and from command line.
Any idea?
EDIT : both calc.exe and tftp.exe are located in c:\windows\system32 which is in the system path.
running "c:\windows\system32\tftp" does not workThe problem is that you have a 32 bit application trying to execute a 64 bit Windows command. You do not have to recompile your application as 64 bit to solve the problem. All you have to do is change all occurrences of c:\windows\system32 to c:\windows\SysNative.
In Windows 7 x64, references to c:\windows\system32 from 32 bit programs are automatically redirected to c:\windows\syswow64. Using the special alias c:\windows\SysNative causes Windows 7 to not do the redirect.
精彩评论