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

Developer

resources

IModule and IMod

IModule is used with the MOD/DLL format, and IMod is used with the MOD1/DLL1 format.

IModule

The IModule interface provides a mechanism for controlling access to a group of associated classes (applets and in-process classes) in a MOD file. The IModule interface allows modules to expose a wide variety of classes without fixed entry points.

IModule can be leveraged to implement a singleton contract. The IModule interface is a singleton enforced by Brew MP at creation time.

When Brew MP loads a module, the module is represented by a unique instance of the IModule class. During execution, IModule creates instances of the classes it contains when requested by applications. After all instances of these classes in the module are released, the module is released, freeing the memory it used to contain its code and data. Brew MP only loads and creates a module once.

AEEModGen.c is the implementation for the IModule interface. AEEModGen.c is a helper file provided by the Brew MP Plugin Wizard, containing reference source code for modules. IModule is the pointer to the module (DLL or MOD file), and deals with loading the entry point. It contains code that enables the MOD file to be loaded, and exposes the single CreateInstance entry point to it.

AEEMod_Load() is the entry point for the module in MOD format and is implemented in AEEModGen.c. AEEModGen.c also implements four methods of IModule:
  • CreateInstance: Brew MP invokes this method when it needs an instance of a class provided by the module.
  • FreeResources: this method frees additional resources consumed by the module prior to its destruction.
  • AddRef: this method increments the module's reference count.
  • Release: this method decrements the module's reference count and cleans up after the module when its reference count reaches 0.

For more information on IModule, see the Brew MP http://developer.brewmp.com/reference/api-all on the Brew MP website.

AEEClsCreateInstance() is the entry point for all classes inside the module and needs to be implemented in source file of the classes. It is invoked by the AEEMod_CreateInstance() in AEEModGen.c file when a class is being instantiated.

When the component infrastructure receives a request to instantiate an object via IEnv_CreateInstance(), it performs the following actions:

  1. Searches the module database (the set of all MIF files in the system) for a module that implements the class.
  2. Loads and links the module's code image in memory.
  3. Calls the entry function, AEEMod_Load(), in the newly loaded module to instantiate the component.
  4. Calls AEEMod_CreateInstance() on the resulting IModule, which calls AEEClsCreateInstance() to instantiate the requested class. When idle modules (modules that have no references to their IEnv) are released, AEEMod_FreeResources() is called before the module's code is released.

For more information on IModule, see the Brew MP http://developer.brewmp.com/reference/api-all on the Brew MP website.

IMod

IMod is used to instantiate classes implemented by a module (DLL1 or MOD1 file). Each module exports one entry function, IMod_New, executed when the module is loaded. This function must return an instance of IMod, which is then used to instantiate classes implemented in that module.

Each module must provide implementation of IMod_New(). Modules typically do this by linking with a1mod and building with code auto-generated by the CIF compiler (cifc.exe), which contains the implementation for IMod_New.

When the component infrastructure receives a request to instantiate an object via IShell_CreateInstance() or IEnv_CreateInstance(), it performs the following actions:

  1. Searches the module database (the set of all MIF files in the system) for a module that implements the class.
  2. Loads and links the module's code image in memory.
  3. Calls the entry function, IMod_New(), in the newly loaded module to instantiate the component.
  4. Calls IMod_Init() on the resulting IMod.
  5. Calls IMod_CreateInstance() to instantiate the requested class. When idle modules (modules that have no references to their IEnv) are released, IMod_Exit() is called before the module's code is released.

For more information on IMod, see the OS Services Technology Guide for Developers in http://developer.brewmp.com/resources on the Brew MP website.