<< Click to Display Table of Contents > 

Scanner Card Interface > Example Code > Saving & Loading Settings with COM

Saving & Loading Settings with COM
Previous pageReturn to chapter overviewNext page

Client applications that wish to save and load scanner specific settings can either save those values together with their regular settings and apply them individually, or can use SCI functions to save them.

The following code snippet can be used in the COM interface to save all current settings into the file file_name.

int saveSettings(CString file_name)

{

 ScDocArchive archive;

 ScDocStorage scaps_storage;

 archive.Create();

 archive->ScOpenScapsStorage(NULL,CComBSTR(file_name),&scaps_storage);

 if (!scaps_storage)

 {

   // generate a new settings file

   ScDocStorage storage;

   archive->ScCreateStorage(NULL,CComBSTR(file_name),&storage);

   if (storage)

   {

     archive->ScCreateStorage(storage,CComBSTR("SCAPS"),&scaps_storage);

   }

 }

 if (scaps_storage)

 {

   ScDocStorage optic_storage;

   archive->ScCreateStorage(scaps_storage,CComBSTR("ScOpticModuleCtrl"),&optic_storage);

   if (optic_storage)

   {

     long res;

     m_optic_module->ScSaveToArchive(archive,NULL,scComArchiveProperty|scComArchiveChild|scComArchiveGlobal|scComArchiveOptic|scComArchiveScanner|scComArchiveStyle,&res);

     return res;

   }

 }

 return 0;

}

 

The corresponding load function could look like this:

int loadSettings(CString file_name)

{

 ScDocArchive archive;

 ScDocStorage scaps_storage;

 archive.Create();

 archive->ScOpenScapsStorage(NULL,CComBSTR(file_name),&scaps_storage);

 if (scaps_storage)

 {

   ScDocStorage optic_storage;

   archive->ScOpenStorage(scaps_storage,CComBSTR("ScOpticModuleCtrl"),&optic_storage);

   if (optic_storage)

   {

     long res;

     m_optic_module->ScLoadFromArchive(archive,NULL,scComArchiveProperty|scComArchiveChild|scComArchiveGlobal|scComArchiveOptic|scComArchiveScanner,&res);

     return res;

   }

 }

 return 0;

}

 

ScSCISaveSettings / ScSCILaveSettings are designed accordingly, and can load and save compatible settings files.