I have a problem with some code, hoping someone can help me, the idea of the code is to start a process, and block all code execution until that process has terminated.
The following function works as a Win32 Application, it doesn't work when compiled to a DLL and gives the error message "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." (Called using VS.NET 2005, C#).
Now the problem is somewhere in the conversion from string to char* which the CreateProcess API accepts, if I accept a char[] the code executes as a DLL just fine, unfortunatly I have little choice in the matter, and have to get it working with a string.
Help would be most appreciated.
void StartProcess(string path)
{
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi;
if(CreateProcess(0, (char*)path.c_str(), 0, 0, FALSE, 0, 0, 0, &si, &pi))
{
WaitForSingleObject(pi.hPr
ocess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
}
Start Free Trial