/* * openDSM * * Open the data source manager */ int openDSM(pTW_SESSION twSession) { /* Make sure that we aren't already open */ if (DSM_IS_OPEN(twSession)) return TRUE; /* Open the data source manager */ twSession->twRC = callDSM(APP_IDENTITY(twSession), NULL, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, (TW_MEMREF) &(twSession->hwnd)); /* Check the return code */ switch (twSession->twRC) { case TWRC_SUCCESS: /* We are now at state 3 */ twSession->twainState = 3; return TRUE; break; case TWRC_FAILURE: default: LogMessage("OpenDSM failure\n"); break; } return FALSE; }
/* * TwainProcessMessage * * Returns TRUE if the application should process message as usual. * Returns FALSE if the application should skip processing of this message */ int TwainProcessMessage(LPMSG lpMsg, pTW_SESSION twSession) { TW_EVENT twEvent; twSession->twRC = TWRC_NOTDSEVENT; /* Only ask Source Manager to process event if there is a Source connected. */ if (DSM_IS_OPEN(twSession) && DS_IS_OPEN(twSession)) { /* * A Source provides a modeless dialog box as its user interface. * The following call relays Windows messages down to the Source's * UI that were intended for its dialog box. It also retrieves TWAIN * messages sent from the Source to our Application. */ twEvent.pEvent = (TW_MEMREF) lpMsg; twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession), DG_CONTROL, DAT_EVENT, MSG_PROCESSEVENT, (TW_MEMREF) &twEvent); /* Check the return code */ if (twSession->twRC == TWRC_NOTDSEVENT) { return FALSE; } /* Process the message as necessary */ processTwainMessage(twEvent.TWMessage, twSession); } /* tell the caller what happened */ return (twSession->twRC == TWRC_DSEVENT); }