OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Step 5: Creating a registrar object

Every ObjectComponents application needs to create a registrar object to manage all of its registration tasks.

Insert the following line after the #include statements in your main .CPP file.

owl::TPointer< ocf::TRegistrar > Registrar
Global registrar object defined by the client application.

The Registrar object is created in your OwlMain function. The TPointer template ensures that the Registrar object is destructed when the program ends.

Note
It is important to name the variable Registrar, since OCF depends on this. Also note that, unlike previous versions of OCF, Registrar should not be declared static, and the pointer type should be TPointer<TRegistrar>, not TPointer<TOcRegistrar>. However, note that Registrar must still point to a TOcRegistrar object.

The next step is to modify your OwlMain function to allocate a new TOcRegistrar object to initialize the global pointer Registrar. The TOcRegistrar constructor requires three parameters: the application's registration structure, the component's factory callback and the command line string that invoked that application.

  • The registration structure you create with the registration macros.
  • The factory callback you create with an ObjectWindows factory template.

You can write your own callback function from scratch if you prefer, but the templates are much easier to use. For a linking and embedding ObjectWindows application that doesn't use Doc/View, the template class is called TOleFactory. The code in the factory template assumes you have defined an application dictionary called AppDictionary and a pointer to TRegistrar called Registrar.

  • The command line string comes from the GetCmdLine method of TApplication.

Factories are explained in more detail in the ObjectWindows Reference Guide. After initializing the Registrar pointer, your OLE container application must invoke TOcRegistrar::Run instead of TApplication::Run. For OLE containers, the registrar's Run simply invokes the application object's Run to create the application's windows and process messages. In a server, however, TOcRegistrar::Run does more. Using the registrar's Run method in a container makes it easier to modify the application later if you decide to turn it into a server.

Here is an example of OwlMain after adding the registrar object:

int
OwlMain(int /*argc*/, char* /*argv*/[])
{
::Registrar = new TOcRegistrar(::AppReg,
TApplication::GetCmdLine());
return ::Registrar->Run();
}
STDAPI_(owl::TDocTemplate **) GetDocTemplateHead(owl STDAPI_(owl::TModule **) GetModulePtr(owl in OwlMain)(int argc, TCHAR *argv[])
Main entry point for an Owl application.
Definition module.h:391