CreateProcess going away indefinitely
Here's my cry for help:
Within a DLL I am calling CreateProcess to run an exe which brings up a window which requires user interaction. My problem is that the first time this call is made the window will not appear until the user clicks on something else on the Desktop - the taskbar, another window, the start menu, etc. - only then will the window we're waiting on appear. The second time this is run the window comes up on its own.
Another odditiy: If the .exe is run on its own without being called from within the DLL it comes up immediately, with no delay whether it is the first time running or the hundredth.
Does anyone have a suggestion for fixing this behavior so that I can make the exe call from the DLL, having it run as if it were NOT being called from the DLL? I am working in various versions of Windows (98/ME/XP).
Thanks in advance!!
Here's the code that calls CreateProcess:
First LaunchScanner is called, then WaitForImage. If anything like a MessageBox call is stuck in after the CreateProcess, the scanner program comes up immediately - is there something else that I can call which will have the same effect, without displaying something like a MessageBox on the screen?
Code:
CString CFilterModuleDllApp::GetScannerProgram() {
CHAR windowsDirectory[MAX_LOADSTRING];
CHAR orexAppPath[MAX_LOADSTRING];
CHAR executable[MAX_LOADSTRING];
GetWindowsDirectory(windowsDirectory, MAX_LOADSTRING);
LoadString(m_hInstance, OREX_SCANPATH, orexAppPath, MAX_LOADSTRING);
strcpy(executable, windowsDirectory);
strcat(executable, "\\");
strcat(executable, orexAppPath);
return CString(executable);
}
int CFilterModuleDllApp::LaunchScanner() {
PROCESS_INFORMATION scan_procinfo;
STARTUPINFO scan_startup;
scan_startup.cb = sizeof(STARTUPINFO);
scan_startup.lpReserved = NULL;
scan_startup.lpDesktop = NULL;
scan_startup.lpTitle = NULL;
scan_startup.dwFlags = 0;
scan_startup.cbReserved2 = 0;
scan_startup.lpReserved2 = 0;
if (!CreateProcess(GetScannerProgram(), NULL, NULL, NULL, TRUE, REALTIME_PRIORITY_CLASS,
NULL, NULL, &scan_startup, &scan_procinfo)) {
return -500;
}
return 0;
}
int CFilterModuleDllApp::WaitForImage(int *width, int *height, int *xPixelSize, int *yPixelSize) {
CHAR interfacename[MAX_LOADSTRING];
CHAR tempbuf[MAX_LOADSTRING];
CHAR compbuf[MAX_LOADSTRING];
CString pixelSizeLookup;
CString pixelSizeTranslation;
LoadString(m_hInstance, OREX_INI, interfacename, MAX_LOADSTRING);
LoadString(m_hInstance, OREX_CLOSE, tempbuf, MAX_LOADSTRING);
LoadString(m_hInstance, OREX_CLOSE, compbuf, MAX_LOADSTRING);
for(;!strcmp(tempbuf,compbuf);) {
if (GetPrivateProfileString("SCANNER STATUS", "Scanner Status", "",
tempbuf, MAX_LOADSTRING, interfacename) == 0) {
return -20;
}
}
LoadString(m_hInstance, OREX_OPEN, tempbuf, MAX_LOADSTRING);
LoadString(m_hInstance, OREX_OPEN, compbuf, MAX_LOADSTRING);
for(;!strcmp(tempbuf,compbuf);) {
if (GetPrivateProfileString("SCANNER STATUS", "Scanner Status", "",
tempbuf, MAX_LOADSTRING, interfacename) == 0) {
return -20;
}
}
LoadString(m_hInstance, OREX_CLOSE, compbuf, MAX_LOADSTRING);
if (!strcmp(compbuf,tempbuf)) {
return 0;
}
if (GetPrivateProfileString("SCANNER STATUS", "Image Width", "",
tempbuf, MAX_LOADSTRING, interfacename) == 0) {
return -21;
}
*width = atoi(tempbuf);
if (GetPrivateProfileString("SCANNER STATUS", "Image Height", "",
tempbuf, MAX_LOADSTRING, interfacename) == 0) {
return -22;
}
*height = atoi(tempbuf);
// look up the pixel size for the width, height
pixelSizeLookup.Format("%d,%d", *width, *height);
pixelSizeTranslation = GetProfileString("PixelSize", pixelSizeLookup);
// extract the x and y pixel sizes from the results
int pos = pixelSizeTranslation.Find(",");
*xPixelSize = atoi(pixelSizeTranslation.Mid(0, pos));
*yPixelSize = atoi(pixelSizeTranslation.Mid(pos + 1));
return 1;
}