1、开发环境
Windows7_sp1_x64 Qt4.7.4 + mingw32 twain_32.dll (1.7.1.3)
2、常用缩写
DSM: Data Source Manager 数据源管理器
DS: Data Source 数据源
DSM_Entry: DSM调用入口
TW_UINT16 FAR PASCAL DSM_Entry( pTW_IDENTITY pOrigin, // Source of message pTW_IDENTITY pDest, // Destination of message TW_UINT32 DG, // Data group ID: DG_xxxx; DG_CONTROL,DG_IMAGE,DG_AUDIO TW_UINT16 DAT, // Data argument type: DAT_xxxx; DAT_IDENTITY ... TW_UINT16 MSG, // Message ID: MSG_xxxx; MSG_GET,MSG_SET ... TW_MEMREF pData // Pointer to data );
3、调用实现
3.0 加载 TWAIN_32.DLL,并获取 DSM_Entry
HINSTANCE m_hTwainDLL = LoadLibrary(L"TWAIN_32.DLL"); DSMENTRYPROC m_pDSMProc = (DSMENTRYPROC)GetProcAddress(m_hTwainDLL, "DSM_Entry");
3.1 打开 DSM
MSG_PROCESSEVENT
HWND hWnd = this->WinId(); TW_IDENTITY m_AppId; BOOL m_bDSMOpen = DSM_Entry(&m_AppId,NULL,DG_CONTROL,DAT_PARENT,MSG_OPENDSM,(TW_MEMREF)&hWnd);
3.2 选择 DS
TW_IDENTITY m_Source; BOOL m_bDSSelect = DSM_Entry(&m_AppId,NULL,DG_CONTROL,DAT_IDENTITY,MSG_USERSELECT,&m_Source); BOOL m_bDSSelect = DSM_Entry(&m_AppId,NULL,DG_CONTROL,DAT_IDENTITY,MSG_GETDEFAULT,&m_Source);
3.3 打开 DS
BOOL m_bDSOpen = DSM_Entry(&m_AppId,NULL,DG_CONTROL,DAT_IDENTITY,MSG_OPENDS,(TW_MEMREF)&m_Source);
3.4 设置参数
MSG_SET
3.5 显示扫描界面
MSG_ENABLEDS
3.6 获取图像
MSG_XFERREADY
DAT_SETUPFILEXFER
DAT_IMAGEFILEXFER
3.7 关闭扫描界面
MSG_CLOSEDSREQ
MSG_CLOSEDSOK
MSG_DISABLEDS
3.8 关闭 DS
MSG_CLOSEDS
3.9 关闭 DSM
MSG_CLOSEDSM