/* * closeDS * * Close the datasource associated with the * specified session. */ int closeDS(pTW_SESSION twSession) { /* Can't close a closed data source */ if (DS_IS_CLOSED(twSession)) { LogMessage("closeDS: Data source already closed\n"); return TRUE; } /* Open the TWAIN datasource */ twSession->twRC = callDSM(APP_IDENTITY(twSession), NULL, DG_CONTROL, DAT_IDENTITY, MSG_CLOSEDS, (TW_MEMREF) DS_IDENTITY(twSession)); /* Check the return to determine what the user decided * to do. */ switch (twSession->twRC) { case TWRC_SUCCESS: /* We are now in TWAIN state 3 */ twSession->twainState = 3; LogMessage("Data source %s closed\n", DS_IDENTITY(twSession)->ProductName); return TRUE; break; default: LogMessage("Error \"%s\" closing data source\n", currentTwainError(twSession)); break; } return FALSE; }
/* * setBufferedXfer */ static int setBufferedXfer(pTW_SESSION twSession) { TW_CAPABILITY bufXfer; pTW_ONEVALUE pvalOneValue; /* Make sure the data source is open first */ if (DS_IS_CLOSED(twSession)) return FALSE; /* Create the capability information */ bufXfer.Cap = ICAP_XFERMECH; bufXfer.ConType = TWON_ONEVALUE; bufXfer.hContainer = twainAllocHandle(sizeof(TW_ONEVALUE)); pvalOneValue = (pTW_ONEVALUE) twainLockHandle(bufXfer.hContainer); pvalOneValue->ItemType = TWTY_UINT16; pvalOneValue->Item = TWSX_MEMORY; twainUnlockHandle(bufXfer.hContainer); /* Make the call to the source manager */ twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession), DG_CONTROL, DAT_CAPABILITY, MSG_SET, (TW_MEMREF) &bufXfer); /* Free the container */ twainFreeHandle(bufXfer.hContainer); /* Let the caller know what happened */ return (twSession->twRC==TWRC_SUCCESS); }
/* * twainMessageLoop * * Process Win32 window messages and provide special handling * of TWAIN specific messages. This loop will not exit until * the application exits. */ int twainMessageLoop(pTW_SESSION twSession) { MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { if (DS_IS_CLOSED(twSession) || !TwainProcessMessage(&msg, twSession)) { TranslateMessage((LPMSG)&msg); DispatchMessage(&msg); } } return msg.wParam; }
/* * requestImageAcquire * * Request that the acquire user interface * be displayed. This may or may not cause * an image to actually be transferred. */ int requestImageAcquire(pTW_SESSION twSession, gboolean showUI) { /* Make sure in the correct state */ if (DS_IS_CLOSED(twSession)) { LogMessage("Can't acquire image with closed datasource\n"); return FALSE; } twainSetupCallback(twSession); /* Set the transfer mode */ if (setBufferedXfer(twSession)) { TW_USERINTERFACE ui; /* Set the UI information */ ui.ShowUI = TRUE; ui.ModalUI = TRUE; /* In Windows, the callbacks are sent to the window message handler */ ui.hParent = twSession->hwnd; /* Make the call to the source manager */ twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession), DG_CONTROL, DAT_USERINTERFACE, MSG_ENABLEDS, (TW_MEMREF) &ui); if (twSession->twRC == TWRC_SUCCESS) { /* We are now at a new twain state */ twSession->twainState = 5; return TRUE; } else { LogMessage("Error during data source enable\n"); return FALSE; } } else { LogMessage("Unable to set buffered transfer mode: %s\n", currentTwainError(twSession)); return FALSE; } }