Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Using ISettingsTransaction with private .ini-based settings

After creating an instance of AEECLSID_SettingsIniFactory and an ISettings object for the settings store (as shown in Using private .ini-based settings), an application can use the ISettingsTransaction interface as follows:
  1. Call ISettings_QueryInterface() with the AEEIID_ISettingsTransaction interface ID, which returns the ISettingsTransaction object for the ISettings object created in step 2. For example:
       result = ISettings_QueryInterface(pMe->piSettings,
                AEEIID_ISettingsTransaction, (void**) &pMe->piSettingsTrans);
    
       if (SUCCESS != result) {
          DBGPRINTF("QI failed: %d", result);
          return FALSE;
       }
  2. Call ISettingsTransaction_Begin() to start the transaction, as follows:
       result = ISettingsTransaction_Begin(pMe->piSettingsTrans, "");
    
       if (SUCCESS != result) {
          DBGPRINTF("start failed %d", result);
          ISettingsTransaction_Release(pMe->piSettingsTrans);
          pMe->piSettingsTrans = NULL;
          return FALSE; 
       }
  3. Call ISettings functions, such as ISettings_Set() or ISettings_Delete(), that modify the settings store. For example:
       STRCPY(newvalue, "2012");
    
       result = ISettings_Set(pMe->piSettings, "mysection/year", newvalue);
       if (SUCCESS != result) {
          // add code to handle error
          DBGPRINTF("set year failed");
       }

  4. If there are no errors, call ISettingsTransaction_Commit() to end the transaction and commit the changes to the persistent store. For example:
       result = ISettingsTransaction_Commit(pMe->piSettingsTrans, "");
       if (SUCCESS != result) {
          // add code to handle error
          DBGPRINTF("commit failed");
       }
  5. If any errors occurred when modifying the settings store, call ISettingsTransaction_Rollback() to reverse the changes, as follows:
       result = ISettingsTransaction_Rollback(pMe->piSettingsTrans, "");
       if (SUCCESS != result) {
          // add code to handle error
          DBGPRINTF("commit failed");
       }
  6. Release resources, as follows:
       if (NULL != pMe->piSettingsTrans) {
          ISettingsTransaction_Release(pMe->piSettingsTrans);
          pMe->piSettingsTrans = NULL;
       }