Public Member Functions | Protected Member Functions

# wxModule Class Reference
[Application and Process Management]

`#include <wx/module.h>`

Inheritance diagram for wxModule:
[legend]

## Detailed Description

The module system is a very simple mechanism to allow applications (and parts of wxWidgets itself) to define initialization and cleanup functions that are automatically called on wxWidgets startup and exit.

To define a new kind of module, derive a class from wxModule, override the wxModule::OnInit and wxModule::OnExit functions, and add the wxDECLARE_DYNAMIC_CLASS and wxIMPLEMENT_DYNAMIC_CLASS to header and implementation files (which can be the same file). On initialization, wxWidgets will find all classes derived from wxModule, create an instance of each, and call each wxModule::OnInit function. On exit, wxWidgets will call the wxModule::OnExit function for each module instance.

Note that your module class does not have to be in a header file.

For example:

            // A module to allow DDE initialization/cleanup
          // without calling these functions from app.cpp or from
          // the user's application.
          class wxDDEModule: public wxModule
          {
          public:
              wxDDEModule() { }
              virtual bool OnInit() { wxDDEInitialize(); return true; };
              virtual void OnExit() { wxDDECleanUp(); };

          private:
              wxDECLARE_DYNAMIC_CLASS(wxDDEModule);
          };

          wxIMPLEMENT_DYNAMIC_CLASS(wxDDEModule, wxModule);

          // Another module which uses DDE in its OnInit()
          class MyModule: public wxModule
          {
          public:
              MyModule() { AddDependency(wxCLASSINFO(wxDDEModule)); }
              virtual bool OnInit() { ... code using DDE ... }
              virtual void OnExit() { ... }

          private:
              wxDECLARE_DYNAMIC_CLASS(MyModule);
          };

          wxIMPLEMENT_DYNAMIC_CLASS(MyModule, wxModule);

          // Another module which uses DDE in its OnInit()
          // but uses a named dependency
          class MyModule2: public wxModule
          {
          public:
              MyModule2() { AddDependency("wxDDEModule"); }
              virtual bool OnInit() { ... code using DDE ... }
              virtual void OnExit() { ... }

          private:
              wxDECLARE_DYNAMIC_CLASS(MyModule2)
          };

          wxIMPLEMENT_DYNAMIC_CLASS(MyModule2, wxModule)

##

Library: wxBase
Category: Application and Process Management

## Public Member Functions
| wxModule ()
| Constructs a wxModule object.
virtual | ~wxModule ()
| Destructor.
virtual void | OnExit ()=0
| Provide this function with appropriate cleanup for your module.
virtual bool | OnInit ()=0
| Provide this function with appropriate initialization for your module.
## Protected Member Functions
void | AddDependency (wxClassInfo *dep)
| Call this function from the constructor of the derived class.
void | AddDependency (const char *classname)
| Call this function from the constructor of the derived class.

List of all members.

## Constructor & Destructor Documentation

wxModule::wxModule | ( |  | ) |

Constructs a wxModule object.

virtual wxModule::~wxModule | ( |  | ) | `[virtual]`

Destructor.

## Member Function Documentation

void wxModule::AddDependency | ( | wxClassInfo * | dep | ) | `[protected]`

Call this function from the constructor of the derived class.

dep must be the wxCLASSINFO() of a wxModule-derived class and the corresponding module will be loaded before and unloaded after this module.

Parameters:

  | dep | The class information object for the dependent module.

void wxModule::AddDependency | ( | const char * | classname | ) | `[protected]`

Call this function from the constructor of the derived class.

This overload allows a dependency to be added by name without access to the class info.

This is useful when a module is declared entirely in a source file and there is no header for the declaration of the module needed by wxCLASSINFO(), however errors are not detected until run-time, instead of compile-time, then. Note that circular dependencies are detected and result in a fatal error.

Parameters:

  | classname | The class name of the dependent module.

virtual void wxModule::OnExit | ( |  | ) | `[pure virtual]`

Provide this function with appropriate cleanup for your module.

virtual bool wxModule::OnInit | ( |  | ) | `[pure virtual]`

Provide this function with appropriate initialization for your module.

If the function returns false, wxWidgets will exit immediately.

|  | [ top ]