Nicomsoft OCR: Developer's Guide


Cfg_SaveOptions


Syntax

C++:int Cfg_SaveOptions(HCFG CfgObj, UNICODECHAR* FileName)
C#:int Cfg_SaveOptions(int CfgObj, string FileName)
Visual Basic:Function Cfg_SaveOptions(ByVal CfgObj As Integer, ByVal FileName As String) As Integer
Java:int Cfg_SaveOptions(HCFG CfgObj, String FileName)
Delphi:function Cfg_SaveOptions(CfgObj:HCFG; FileName:PWCHAR):integer


Description

Saves the OCR configuration to a file.


Parameters

CfgObj [IN] – the Config object.
FileName [IN] – a Unicode, null-terminated string that contains the full path and filename of the configuration file. If no full path is specified, "Bin_common" directory will be used. See Engine_SetDataDirectory for details.


Return value

Zero if success, otherwise an error code.


Remarks

None.


Example

The following code initializes the OCR engine, loads the configuration, changes the language from English to German, and saves the updated configuration to the same file:

C++
int CfgObj;
Engine_Initialize(); //initialize OCR engine
Cfg_Create(&CfgObj); //create CFG object
Cfg_LoadOptions(CfgObj, L"Config.dat"); //load configuration
Cfg_SetOption(CfgObj, BT_DEFAULT, L"Languages/German", L"1"); //select German language
Cfg_SetOption(CfgObj, BT_DEFAULT, L"Languages/English", L"0"); //unselect English language
Cfg_SaveOptions(CfgObj, L"Config.dat"); //save updated configuration
Cfg_Destroy(CfgObj); //release CFG object, this line can be removed since Engine_Uninitialize releases all created objects
Engine_Uninitialize(); //release all created objects and uninitialize OCR engine


C#
//assume reference to NSOCR COM was added
using NSOCR_NameSpace; //Add NSOCR namespace from "NSOCR.cs" file
//...
int CfgObj;
NSOCRLib.NSOCRClass NsOCR = new NSOCRLib.NSOCRClass(); //create NSOCR COM object instance
NsOCR.Engine_Initialize(); //initialize OCR engine
NsOCR.Cfg_Create(out CfgObj); //create CFG object
NsOCR.Cfg_LoadOptions(CfgObj, "Config.dat"); //load configuration
NsOCR.Cfg_SetOption(CfgObj, TNSOCR.BT_DEFAULT, "Languages/German", "1"); //select German language
NsOCR.Cfg_SetOption(CfgObj, TNSOCR.BT_DEFAULT, "Languages/English", "0"); //unselect English language
NsOCR.Cfg_SaveOptions(CfgObj, "Config.dat"); //save updated configuration
NsOCR.Cfg_Destroy(CfgObj); //release CFG object, this line can be removed since Engine_Uninitialize releases all created objects
NsOCR.Engine_Uninitialize(); //release all created objects and uninitialize OCR engine


VB.NET
'assume reference to NSOCR COM was added
'assume "NSOCR.vb" file was added to project
Dim CfgObj As Integer
Dim NsOCR As New NSOCRLib.NSOCRClass 'create NSOCR COM object instance
NsOCR.Engine_Initialize() 'initialize OCR engine
NsOCR.Cfg_Create(CfgObj) 'create CFG object
NsOCR.Cfg_LoadOptions(CfgObj, "Config.dat") 'load configuration
NsOCR.Cfg_SetOption(CfgObj, TNSOCR.BT_DEFAULT, "Languages/German", "1") 'select German language
NsOCR.Cfg_SetOption(CfgObj, TNSOCR.BT_DEFAULT, "Languages/English", "0") 'unselect English language
NsOCR.Cfg_SaveOptions(CfgObj, "Config.dat") 'save updated configuration
NsOCR.Cfg_Destroy(CfgObj) 'release CFG object, this line can be removed since Engine_Uninitialize releases all created objects
NsOCR.Engine_Uninitialize() 'release all created objects and uninitialize OCR engine


Java
//assume NSOCR package was included
//Java VM option "-Djava.library.path" must point to "Bin" folder (x86 platform) or to "Bin_64" folder (x64 platform)
//...
NSOCR.HCFG CfgObj = new NSOCR.HCFG();
NSOCR.Engine.Engine_Initialize(); //initialize OCR engine
NSOCR.Engine.Cfg_Create(CfgObj); //create CFG object
NSOCR.Engine.Cfg_LoadOptions(CfgObj, "Config.dat"); //load configuration
NSOCR.Engine.Cfg_SetOption(CfgObj, NSOCR.Constant.BT_DEFAULT, "Languages/German", "1"); //select German language
NSOCR.Engine.Cfg_SetOption(CfgObj, NSOCR.Constant.BT_DEFAULT, "Languages/English", "0"); //unselect English language
NSOCR.Engine.Cfg_SaveOptions(CfgObj, "Config.dat"); //save updated configuration
NSOCR.Engine.Cfg_Destroy(CfgObj); //release CFG object, this line can be removed since Engine_Uninitialize releases all created objects
NSOCR.Engine.Engine_Uninitialize(); //release all created objects and uninitialize OCR engine