Processing TWAIN messages

 

 In the BiTWAIN.dll several window messages helps you to use the scanner:

 

 

The BiTWAIN.ocx uses events for handling messages:

 

 

Important: You must be free the DIB if you don’t want to use it anymore. Use the GlobalFree API function in C++ and the ReleaseData method from BiTwain.ocx when using the ActiveX control.

 

[C++]

 

/* Processing TWAIN messages */

 

#include “BiTwain.h”

 

LRESULT CScanSampleDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)

{

            lpstScanningDocumentFinished         lpstFinishDoc;

            lpstScanningError                                           lpstError;

            char                                                                             szMsg[128];

            UINT                                                                          i, j;

 

            if (message == m_iBiTwainMsg)

            {

                        switch (wParam)

                        {

                        case WM_BI_SCANNING_DOCUMENT_FINISHED :

                                    // Scanned to memory

                                    lpstFinishDoc =

(lpstScanningDocumentFinished)lParam;

GlobalFree(lpstFinishDoc->hDib);

                                    break;

                        case WM_BI_SCANNING_ERROR :

                                    lpstError = (lpstScanningError)lParam;

                                    break;

                        case WM_BI_FEEDER_EMPTY:

                                    AfxMessageBox(“The feeder is empty");

                                    break;

                        case WM_BI_PAGE_FINISHED :               

                                    lpstFinishDoc =

 (lpstScanningDocumentFinished)lParam;

                                                GlobalFree(lpstFinishDoc->hDib);

                                    break;

                        }

            }

 

            return CDialog::WindowProc(message, wParam, lParam);

}

 

[VB]

 

‘ Processing TWAIN events

 

Private Sub BiTwain_BatchPageDone(ByVal hDibOutput As Long,  ByVal FileOutput As String)

    If hDibOutput > 0 Then

        BiTwain.ReleaseData hDibOutput

    End If

End Sub

 

Private Sub BiTwain_FeederIsEmpty()

    MsgBox "Feeder is empty"

End Sub

 

Private Sub BiTwain_TwError(ByVal ErrorCode As Long, ByVal ErrorStr As String)

    Dim s As String

    Dim i As Long

   

    For i = 1 To Len(ErrorStr)

        If Mid(ErrorStr, i, 1) <= " " Then

            s = s + " "

        Else

            s = s + Mid(ErrorStr, i, 1)

        End If

    Next i

    LBLIST.AddItem s

    LBLIST.ListIndex = LBLIST.NewIndex

End Sub

 

[C#]

 

/* Processing TWAIN events */

 

private void BiTwain_BatchPageDone(object sender, AxBITWAINLib._DBiTwainEvents_BatchPageDoneEvent e)

{

if (e.hDibOutput > 0)

                        BiTwain.ReleaseData(e.hDibOutput);

}

 

private void BiTwain_FeederIsEmpty(object sender, System.EventArgs e)

{

            MessageBox.Show("Feeder is empty", "TWAIN Sample",

MessageBoxButtons.OK, MessageBoxIcon.Error);

}

 

private void BiTwain_TwError(object sender, AxBITWAINLib._DBiTwainEvents_TwErrorEvent e)

{

            string s = e.errorStr.Replace('\n', ' ');

 

            MessageBox.Show (s, "TWAIN Sample",

MessageBoxButtons.OK, MessageBoxIcon.Error);

}