Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Scanning from VFP
Message
General information
Forum:
Visual FoxPro
Category:
Pictures and Image processing
Miscellaneous
Thread ID:
00341709
Message ID:
00344896
Views:
19
Eylon,
The out-of-process server that I wrote about is a VB ActiveX EXE. It is utilized much in the same way that you might use MS Word or Excel via OLE automation.

The reasoning behind using an out-of-process server (OLE automation on an ActiveX exe) vs. an in-process server (ActiveX/OCX control or COM object) is that an out-of-process server runs in its own address space without any intervention from VFP or reliance upon VFP. No flaky OCX control problems.

The down side to using an out-of-process server is that you have less control over an externally running program and it is sometimes tricky to avoid a 'Switch To...' dialog that can appear if the user clicks on the calling program when the server is executing.

A good rule of thumb is to avoid the out-of-process solution if an in-process solution can do the trick (less nonsense...the keep it simple principle).

Writing an out-of-process server is simple in VB and a little less simple in VC. If you have any experience with VB create a project for an ActiveX EXE. Add one form and on that form add whatever ActiveX/OCX control that is to be used (in the case of this TWAIN interface, I have one VB form with a Leadtools OCX and a pushbutton).

The trick to writing the VB ActiveX EXE is to pass along the Leadtools OCX's events from the VB form to the VB class wrapper (the example below is a very simple, single purpose VB ActiveX EXE):


*** VB Class Wrapper Code ***
Option Explicit
Dim WithEvents frm As Form1
Public Event LeadIsDone(resval As Long)
Public Event ClientNotify(notestr As String)

Public Sub KillIt()
Class_Terminate
End Sub

Private Sub Class_Initialize()
Set frm = New Form1
End Sub

Private Sub Class_Terminate()
Unload frm
End Sub

Public Property Get AutoSetRects() As Boolean
AutoSetRects = frm.LEAD1.AutoSetRects
End Property

Public Property Let AutoSetRects(ByVal lNewValue As Boolean)
frm.LEAD1.AutoSetRects = lNewValue
End Property

Public Property Get EnableMethodErrors() As Boolean
EnableMethodErrors = frm.LEAD1.EnableMethodErrors
End Property

Public Property Let EnableMethodErrors(ByVal lNewValue As Boolean)
frm.LEAD1.EnableMethodErrors = lNewValue
End Property

Public Function TwainAcquire() As Long
Dim res As Long
res = frm.LEAD1.TwainAcquire(frm.hWnd)
TwainAcquire = res
End Function


Public Function Save(ByVal filenam As String) As Long
Dim res As Long
If frm.LEAD1.Bitmap <> 0 Then
res = frm.LEAD1.Save(filenam, FILE_BMP, frm.LEAD1.BitmapBits, _
0, SAVE_OVERWRITE)
Else
res = -999
End If
Save = res
End Function

Public Function TwainSelect() As Long
Dim res As Long
res = frm.LEAD1.TwainSelect(frm.hWnd)
TwainSelect = res
End Function

Public Sub FormShow()
RaiseEvent ClientNotify("TWAIN Acquire In Process")
DoEvents
frm.Show
End Sub

Public Property Get ResState() As Boolean
ResState = frm.ResState
End Property

Public Property Let ResState(ByVal lNewValue As Boolean)
frm.ResState = lNewValue
End Property

Public Property Get TempFileName() As String
TempFileName = frm.tmpfile
End Property

Public Property Let TempFileName(ByVal sNewValue As String)
frm.tmpfile = sNewValue
End Property

Private Sub frm_LeadDone(resval As Long)
RaiseEvent LeadIsDone(resval)
End Sub

Public Property Get TWAINDevice() As String
TWAINDevice = frm.LEAD1.TwainSourceName
End Property

Private Sub frm_NotifyClient(notestr As String)
RaiseEvent ClientNotify(notestr)
End Sub


*** Form Code ***
Option Explicit
Public ResState As Boolean
Public tmpfile As String
Public LeadProcessing As Boolean
Public Event LeadDone(resval As Long)
Public Event NotifyClient(notestr As String)

Private Sub Command1_Click()
Dim res As Long
On Error Resume Next
Hide
DoEvents
If tmpfile = "" Then
tmpfile = "scantemp.bmp"
End If
RaiseEvent NotifyClient("TWAIN Driver Processing...")
DoEvents
res = LEAD1.TwainAcquire(hWnd)
If res = 0 Then
res = LEAD1.Save(tmpfile, FILE_BMP, LEAD1.BitmapBits, _
0, SAVE_OVERWRITE)
End If
RaiseEvent LeadDone(res)
Err.Clear
End Sub

Private Sub Command2_Click()
RaiseEvent LeadDone(-1)
Hide
DoEvents
End Sub

Private Sub Command3_Click()
Dim res As Long
On Error Resume Next
RaiseEvent NotifyClient("Select TWAIN Device")
DoEvents
res = LEAD1.TwainSelect(hWnd)
If res = 0 Then
Command3.Caption = "Scan From " & Trim(LEAD1.TwainSourceName)
Command1.Enabled = True
Else
Command3.Caption = "Twain Device Not Found"
Command1.Enabled = False
End If
Err.Clear
End Sub

Private Sub Form_Load()
Dim res As Long
On Error Resume Next
ResState = True
LeadProcessing = False
res = LEAD1.TwainRealize(hWnd)
If res = 0 And Trim(LEAD1.TwainSourceName) <> "" Then
Command3.Caption = "Scan From " & Trim(LEAD1.TwainSourceName)
Command1.Enabled = True
Else
Command3.Caption = "Twain Device Not Found"
Command1.Enabled = False
End If
Err.Clear
End Sub

The user only sees a single pushbutton. If the user clicks on the button the image is scanned (using any TWAIN compliant device) and the results are saved to a temporary file.

When the VB server is complete you can utilize it as you would any OLE automation program or you can use the event binding aspects of VFPCOM.DLL (map the events 'LeadIsDone' and 'ClientNotify' to the calling VFP program).

This is enough for now. If you need additional information (if you want to try this solution) let me know.

Hope This Helps,

ED
Ed Aguinaga
ARIS, Inc
ed@arismls.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform