接上文,我们从TWAIN状态的改变开始。
第一步,将状态1转到2,即从软件打开到获取在DSM的入口。
HMODULE gpDSM = 0; /**< global pointer to the DSM library */
DSMENTRYPROC gpDSM_Entry = 0; /**< global pointer to the DSM entry point */
TW_ENTRYPOINT g_DSM_Entry = { 0 }; /**< global pointer to the TWAIN entry point structure */
bool LoadDSMLib(char* _pszLibName)
{
// check if already opened
if(0 != gpDSM)
{
return true;
}
if((gpDSM=LOADLIBRARY(_pszLibName)) != 0)
{
if((gpDSM_Entry=(DSMENTRYPROC)LOADFUNCTION(gpDSM, "DSM_Entry")) == 0)
{
cerr << "Error - Could not find DSM_Entry function in DSM: " << _pszLibName << endl;
return false;
}
}
else
{
cerr << "Error - Could not load DSM: " << _pszLibName << endl;
return false;
}
retur