跳转到主要内容
本主题适用于 Windows 版 FRE。
本节介绍如何在 C (Objective-C) 中加载和卸载 ABBYY FineReader Engine。
  1. 导入 FREngine.h 头文件时,请包含以下代码:
/* C */
#define __RPC__deref_out
#define COBJMACROS
#include <FREngine.h>
/* Objective-C */
#define interface _COM_interface
#define __RPC__deref_out
#define COBJMACROS
#import <FREngine.h>
#undef interface
  1. 使用以下代码加载和卸载 FREngine.dll:
typedef HRESULT (*initializeEngine_ptr) (BSTR, BSTR, BSTR, BSTR, BSTR, VARIANT_BOOL, IEngine **);
typedef HRESULT (*DeinitializeEngine_ptr) (void);
static IEngine* FREngine;
static HMODULE FREngineDll;
int main(int argc, char *argv[]) {
 initializeEngine InitializeEngine=NULL;
 DeinitializeEngine_ptr DeinitializeEngine=NULL;
 // 在此处提供您的 Customer Project ID;如果适用,还请提供 Online License 信息
 wchar_t *customerProjectId = L"";
 wchar_t *licensePath = L"";
 wchar_t *licensePassword = L"";
 FREngineDll = LoadLibraryEx("<path to FREngine.dll>", 0, LOAD_WITH_ALTERED_SEARCH_PATH);
 if(FREngineDll) {
  InitializeEngine = (InitializeEngine_ptr) GetProcAddress(FREngineDll,"InitializeEngine");
  if(InitializeEngine)
   InitializeEngine(customerProjectId, licensePath, licensePassword, "", "", FALSE, &FREngine);
 }
 ProcessImage();
 IEngine_Release( FREngine );
 DeinitializeEngine = (DeinitializeEngine_ptr) GetProcAddress(FREngineDll,"DeinitializeEngine");
 DeinitializeEngine();
}
  1. 对 ABBYY FineReader Engine 的所有其他调用,都可以使用在 FREngine.h 头文件中定义的 C 宏。
void ProcessImage()
{
 IFRDocument* frDocument = NULL;
 IEngine_CreateFRDocument( FREngine, &frDocument );
 IFRDocument_AddImageFile( frDocument, L"<path to a source image>", NULL, NULL );
 IFRDocument_Process( frDocument, NULL, NULL, NULL );
 IFRDocument_Export( frDocument, L"<path to an output file>", FEF_PDF, NULL );
 IFRDocument_Release( frDocument );
}

另请参阅

编程相关内容