I have to make a simple program with visual studio, using Windows APIs. My code works well in debug mode, however, it doesn't work well in release mode and I couldn't figure it why. I cut & paste the part where my program crashed. Here's that part.
#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>
#include <windows.h>
int _tmain(int argc, TCHAR * argv[])
{
TCHAR cmdString[] = "notepad.exe";
STARTUPINFO si = { 0, };
PROCESS_INFORMATION pi;
si.cb = sizeof(si);
BOOL ret = TRUE;
CreateProcess(NULL, cmdString, NULL, NULL, TRUE,
CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi);
_tprintf(_T("Error = {%d}\n", GetLastError()));
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
system("pause");
return 0;
}
Simple program which opens notepad.exe, right? Works well in debug mode, but notepad won't open in release mode(Program ends without opening notepad.exe).
I tried to find solution in S.O, like this link but It doesn't help me much.
Why CreateProcess() doesn't work properly in release-mode?