Accusoft.ScanFixXpress6.ActiveX Accusoft Pegasus
Use ScanFix Xpress in Visual C++
See Also Send Feedback  
Getting Started > Use ScanFix Xpress in Visual C++

Glossary Item Box

Use ScanFix® Xpress in Visual C++

Importing a Control into Visual C++

Importing a control via the #import directive is a simple process. The #import directive line can be added to the stdafx.h file to provide the appropriate functionality to all source files in the project.

C++ Example Copy Code
// stdafx.h : include file for standard system include files,
//  or project specific include files that are used frequently, but
//  are changed infrequently
//
#pragma once
#define VC_EXTRALEAN  // Exclude rarely-used stuff from Windows headers
#include <afxwin.h>           // MFC core and standard components
#include <afxext.h>           // MFC extensions
#include <afxdisp.h>          // MFC Automation classes
#include <afxdtctl.h>  // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>  // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
//***Import the ScanFix and ImagXpress DLL's here
#import <Accusoft.ScanFixXpress6.ActiveX.dll>
#import <PegasusImaging.ActiveX.ImagXpress9.dll>
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

The #import directive simply points to the ScanFix Xpress control. When the ScanFix Xpress control is imported with the #import directive, the compiler produces 2 files – a .tli and a .tlh file – that together create the necessary COM wrapper for the control’s properties and methods. Since the directive is in your stdafx.h file, the wrappers are immediately available to your other modules. The wrapper code defines COM smart pointers for all control interfaces. To use this COM object, you simply create an instance of the interface you want and then call methods directly by using this instance pointer.

Declare a Pointer to the COM Object

After the #import directive is specified, declare a pointer to the ScanFix Xpress COM object. In the ImageCleanup project, the pointer is called and it is implemented in the ImageCleanupDlg.h file as follows:

C++ Example Copy Code
// This code demonstrates how the pointer is declared and implemented in the ImageCleanupDlg.h file
#pragma once
// Include the necessary files and namespaces for the COM controls
using namespace AccusoftScanFixXpress6;
#include "..\Include\scanfix6events.h"
using namespace PegasusImagingActiveXImagXpress9
//////////////////////////////////////////////////////////
// CImageCleanupDlg dialog class
class CImageCleanupDlg : public CDialog
{
// Construction
public:
  CScanFix
*ppCScanFix;  // Pointer to the CScanFix class defined in scanfix6events.h
  
Iscanfix6Ptr pScanFix; // Pointer to the ScanFix COM object
  
//Pointer to the ImagXpress objects
  
IImagXpressPtr pImagXpress1;
  IImagXpressPtr pImagXpress2;
  CImageCleanupDlg(CWnd
* pParent = NULL);// standard constructor
  
// ...
  
// Remainder of class declaration deleted here –see provided sample code
  
// ...
}
;  

The ScanFix6events.h file contains the CScanFix Xpress object. The CScanFix Xpress object is used to create a ScanFix Xpress COM object and handles ScanFix Xpress events. Currently ScanFix Xpress does not have any events, but the file provides a place holder for future enhancements.

Initialize COM

The COM library must be initialized before COM functions can be called and it must be closed before the program exits. This is illustrated in the ImageCleanup.cpp file as follows:

C++ Example Copy Code
// This code from ImageCleanup.cpp demonstrates how the COM library must be initialized
BOOL CImageCleanupApp::InitInstance()
{
  
//**Must called CoInitialize here **
  
CoInitialize(NULL);
  AfxEnableControlContainer();
  
// Standard initialization
  
// If you are not using these features and wish to reduce the size
  
// of your final executable, you should remove from the following
  
// the specific initialization routines you do not need.
  
#ifdef _AFXDLL
     Enable3dControls();
// Call this when using MFC in a shared DLL
  
#else
     
Enable3dControlsStatic();// Call this when linking to MFC statically
  
#endif

  
CImageCleanupDlg dlg;
  m_pMainWnd
= &dlg;
  
int nResponse = dlg.DoModal();
  
if (nResponse == IDOK)
  {
     
// TODO: Place code here to handle when the dialog is
     
// dismissed with OK
  }
  
else if (nResponse == IDCANCEL)
  {
     
// TODO: Place code here to handle when the dialog is
     
// dismissed with Cancel
  }
  
//**Must call CoUninitialize here **
  
CoUninitialize();
  
return FALSE;
}

Create the ScanFix Xpress COM Object

You need to create an instance of the ScanFix Xpress COM object. After the object is created, you can use the object’s properties and methods to integrate ScanFix Xpress features into your application.

In the ImageCleanup project, the COM object is created in the ImageCleanupDlg.cpp file as follows:

C++ Example Copy Code
// This code demonstrates how the ScanFix Xpress COM object is created.
// This code is from the OnInitDialog() method in ImageCleanupDlg.cpp
//*****Create a SF Object here ***
HINSTANCE hDLL2 = SF_Open();
// Create a ScanFix object. The ScanFix object automatically creates a ScanFix Xpress COM object.
ppCScanFix = new CScanFix((DWORD) this, 1);
pScanFix
= ppCScanFix->pScanFix;
SF_Close(hDLL2);   

The SF6_Open.cpp file installs in the ScanFix Xpress VC++\Include directory. This file contains 2 functions  SF_Open and SF_Close. These function calls are required to properly register and license the ScanFix Xpress COM object an only need to be called once. You must issue a SF_Open prior to creating the first ScanFix object and you must issue a SF_Close anytime after the first ScanFix object is created.

Before you distribute applications that use the ScanFix Xpress COM object, you need to edit the SF6_Open.cpp file and change the unlock license codes passed to the UnlockRuntime function. Obtain the unlock license codes from Accusoft Pegasus.

Use the ScanFix Xpress COM Object to Set Properties and Call Methods

After an instance of the ScanFix Xpress COM object is created, the object can be used to set ScanFix Xpress properties and call ScanFix Xpress methods. This code comes from the Process function in the ProcessingDlgDeskew.cpp file:

C++ Example Copy Code
// Create options object
   
CComPtr<IDeskewOptions> deskewOpts;
   HRESULT hr
= deskewOpts.CoCreateInstance( __uuidof(DeskewOptions), 0,
                                                    CLSCTX_INPROC_SERVER );
   
if (SUCCEEDED(hr))
   {
       
// Set options object properties
       
deskewOpts->put_maintainOriginalSize( m_MaintainOriginalSize.GetCheck() ==                                
                                             
BST_CHECKED );
       deskewOpts
->put_minimumCorrectableAngle( (double)(m_ctlMinFixAngle.GetPos() /
                                                  
100.0) );
       deskewOpts
->put_minimumConfidence( (long)m_ctlMinConfidence.GetPos() );
       deskewOpts
->put_quality( (long)m_ctlQuality.GetPos() );
       deskewOpts
->put_padColor( m_olePadColor );
       
// Create results object
       
CComPtr<IDeskewResults> deskewRes;
       HRESULT hr2
= deskewRes.CoCreateInstance( __uuidof(DeskewResults), 0,
                                                 CLSCTX_INPROC_SERVER );
       
if (SUCCEEDED(hr2))
       {
           CWaitCursor hourglass;
           
// RUN: Deskew
           
deskewRes = pScanFix->Deskew( deskewOpts );
           
// Check results object properties
           
if (deskewRes->imageWasModified)
               
return true;
       }
   }
   
return false;

Delete the ScanFix Xpress COM Object

The ScanFix Xpress COM object must be deleted when it is no longer needed. The object is usually deleted before the application exits. In the ImageCleanup project, the COM object is deleted in the ImageCleanupDlg.cpp file as follows:

C++ Example Copy Code
// This code demonstrates how to delete the ScanFix Xpress COM object
void CImageCleanupDlg::OnDestroy()
{
   
//**Set the ScanFix object to NULL and delete the COM object**
   
if (pScanFix)
   {
       pScanFix
= NULL;
       
if (ppCScanFix)
       {
           
delete ppCScanFix;
       }
   }
}

 

See Also


©2010. Pegasus Imaging Corporation, DBA Accusoft Pegasus. All Rights Reserved.