Execution of external program fails after a few calls
I want to call an external program to convert BMP to DDS files, but after
a few calls it crashes all the time. I tried both ShellExecute and
CreateProcessor. Here the example with ShellExecute:
path = "C:\\pictures";
file = "C:\\pictures\\test.bmp";
string cmd = "-f BC1_UNORM -o " + path + " " + file;
char* cmdConvert= new char[cmd.size()];
strcpy(cmdConvert, cmd.c_str());
int buffSize = (int)strlen(cmdConvert) + 1;
LPWSTR cmdL= new wchar_t[buffSize];
MultiByteToWideChar(CP_ACP, 0, cmdConvert, buffSize, cmdL, buffSize);
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShEecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = _T("C:\\Texconv\\texconv.exe");
ShExecInfo.lpParameters = cmdL;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
CloseHandle(ShExecInfo.hProcess);
delete convertMe;
delete gah;
It crashes directly after ShellExecuteEx(&ShExecInfo). There must be some
race conditions (or something like this), because it is not crashing when
running in the debugger (I'm using VS2012).
No comments:
Post a Comment