Anyway, I ran into this problem while I was writing some stuff at work. I've restructured it to remove the "work-ness" of the code, but the problem still exists.
It's short, but sweet:
#include <stdio.h>#include <windows.h>#define PROCESS_NAME L"C:\\WINDOWS\\NOTEPAD.EXE"int _tmain(int argc, _TCHAR* argv[]){ PROCESS_INFORMATION processInformation = {0}; STARTUPINFO startupInfo = {0}; DWORD status; if (GetFileAttributesW(PROCESS_NAME) == INVALID_FILE_ATTRIBUTES) { wprintf(L"Can't find " PROCESS_NAME L"; error %d, aborting\n", GetLastError()); return(1); } startupInfo.cb = sizeof(startupInfo); if (!CreateProcessW(NULL, PROCESS_NAME, NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &processInformation)) { status = GetLastError(); } wprintf(L"Status launching " PROCESS_NAME L" is %d\n", status); return 0;}
Some things that are NOT wrong with this code:
It's possible that you won't see the bug if you take it and compile it. But it is still there, and if you compile it in the NT build environment, you'll see the problem (you may also see the problem with current versions of Visual Studio, I was able to reproduce the problem quite easily.
Once upon a time, I watched the TV show The Paper Chase. As I recall it, the feared and respected professor