PrevNextUpHome SophiaFramework UNIVERSE 5.3

23.1. Calling BREW APIs for the C Programming Language

The method to call the BREW APIs for the C Programming Language from the SophiaFramework program is as follows:

Example 23.1. IShell Interface

SFBShellSmp xshell;    // smart pointer that manages IShell interface
IShell* ishell;        // Ishell interface

// method 1
// get the SFBShell instance
if ((xshell = SFBShell::GetInstance()) != null) {
    // get pointer to ishell interface
    ishell = interface_cast(xshell.Get());
    // ishell can be used if xshell is valid
    // ishell scope depends on xshell scope
}

// method 2
if ((xshell = SFBShell::GetInstance()) != null) {
   // get pointer to ishell interface
   ishell = interface_cast(xshell.Detach());
   // developer get priviledge to release ishell from xshell
   // therefore developer must release ishell explicitly 
   ISHELL_Release(ishell);
}

Example 23.2. IFileMgr Interface

  
SFBShellSmp shell;     // smart pointer that manages IShell interface
SFBBaseSmp xfilemgr;   // smart pointer that manages IBase interface
IFileMgr* ifilemgr;    // IFileMgr interface

// method 1
// get SFBShell instance
if ((shell = SFBShell::GetInstance()) != null) {

   // create IFileMgr interface
   if ((xfilemgr = shell->CreateInstance(AEECLSID_FILEMGR)) != null) {

      // get pointer to IFileMgr interface from smart pointer class
      ifilemgr = reinterpret_cast<IFileMgr*>(interface_cast(xfilemgr.Get()));

      // use IFileMgr interface
      if (IFILEMGR_Test(ifilemgr, "myfile.txt") == SFERR_NO_ERROR) {
          // ...
      }
      // ifilemgr scope depends on xfilemgr scope
      // to extend scopes, define xfilemgr and ifilemgr as class member variables
   }
}

// method 2
if ((shell = SFBShell::GetInstance()) != null) {

   // create IFileMgr interface
   if ((xfilemgr = shell->CreateInstance(AEECLSID_FILEMGR)) != null) {

      //  get pointer to IFileMgr interface from smart pointer class
      ifilemgr = reinterpret_cast<IFileMgr*>(interface_cast(xfilemgr.Detach()));

      // use IFileMgr interface
      if (IFILEMGR_Test(ifilemgr, "myfile.txt") == SFERR_NO_ERROR) {
         // ...
      }

      IFILEMGR_Release(ifilemgr);
      // ifilemgr should be managed by developer
      // although ifilemgr scope does not depend on xfilemgr scope, 
      // developer must release ifilemgr explicitly when IFileMgr interface is no longer used
   }
}