/*
Initializes TWAIN interface . Is already called from the constructor. 
It should be called again if ReleaseTwain is called.

  hWnd is the window which has to subclassed in order to recieve
  Twain messaged. Normally - this would be your main application window.

*/
BOOL CTwain::InitTwain(HWND hWnd)
{
char libName[512];
	if(IsValidDriver()) 
	{
		return TRUE;
	}
	memset(&m_AppId,0,sizeof(m_AppId));
	if(!IsWindow(hWnd))
	{
		return FALSE;
	}
	m_hMessageWnd = hWnd;
	strcpy(libName,"TWAIN_32.DLL");
	
	m_hTwainDLL  = LoadLibrary(libName);
	if(m_hTwainDLL != NULL)
	{
		if(!(m_pDSMProc = (DSMENTRYPROC)GetProcAddress(m_hTwainDLL,MAKEINTRESOURCE(1))))
		{
			FreeLibrary(m_hTwainDLL);
			m_hTwainDLL = NULL;
		}
	}
	if(IsValidDriver())
	{
		GetIdentity();
		m_bDSMOpen= CallTwainProc(&m_AppId,NULL,DG_CONTROL,DAT_PARENT,MSG_OPENDSM,(TW_MEMREF)&m_hMessageWnd);
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}
Beispiel #2
0
/** Releases the twain interface . Need not be called unless you
    want to specifically shut it down.
 */
void TwainIface::ReleaseTwain()
{
    if(IsValidDriver())
    {
        CloseDSM();
        FreeLibrary(m_hTwainDLL);
        m_hTwainDLL = NULL;
        m_pDSMProc  = NULL;
    }
}
Beispiel #3
0
/** Entry point into Twain. For a complete description of this
    routine  please refer to the Twain specification 1.8
 */
bool TwainIface::CallTwainProc(pTW_IDENTITY pOrigin, pTW_IDENTITY pDest,
                               TW_UINT32 DG, TW_UINT16 DAT, TW_UINT16 MSG, TW_MEMREF pData)
{
    if(IsValidDriver())
    {
        USHORT ret_val;
        ret_val      = (*m_pDSMProc)(pOrigin, pDest, DG, DAT, MSG, pData);
        m_returnCode = ret_val;

        if(ret_val == TWRC_FAILURE)
        {
            (*m_pDSMProc)(pOrigin, pDest, DG_CONTROL, DAT_STATUS, MSG_GET, &m_Status);
        }
        return (ret_val == TWRC_SUCCESS);
    }
    else
    {
        m_returnCode = TWRC_FAILURE;
        return false;
    }
}
Beispiel #4
0
int EVOpenDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  在此添加您专用的创建代码
	InitTwain(m_hWnd);
	if(!IsValidDriver())
	{
		AfxMessageBox("Unable to load Twain Driver.");
	}

	SetTimer(1,1000,NULL);
	dlgArea = new EVAreaDlg;
	dlgArea->Create(IDD_AREA,this);
	dlgArea->pDlg = this;
	dlgArea->uEditID = IDC_NEWEDIT4;
	dlgArea->ShowWindow(SW_HIDE);
	dlgArea->m_szArea=&m_szArea;

	return 0;
}
Beispiel #5
0
/** Returns true if the Data Source is Open
 */
bool TwainIface::DSOpen() const
{
    return IsValidDriver() && DSMOpen() && m_bDSOpen;
}
/*
Returns true if the Data Source is Open
*/
BOOL CTwain::DSOpen() const
{
	return IsValidDriver() && DSMOpen() && m_bDSOpen;
}
Beispiel #7
0
bool QTwain::isValidDriver() const
{
	return (IsValidDriver() == true);
} // !isValidDriver()