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;
}