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

The registrar object registers and runs the application.

Its constructor receives the application registration structure and a pointer to the list of document registration structures. In a linking and embedding application, the registrar is an object of type TOcRegistrar. 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 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.

Next, in OwlMain allocate a new TOcRegistrar object and initialize the global pointer Registrar. The TOcRegistrar constructor has three required parameters: the application's registration structure, the component's factory callback and the command-line string that invoked that application.

An optional fourth parameter points to the beginning of the document registration list. In a Doc/View application, this parameter defaults to the application's list of document templates. Applications that do not use Doc/View should pass a TRegLink* pointing to the list of document registration structures.

int
OwlMain(int /*argc*/, char* /*argv*/ [])
{
::Registrar = new TOcRegistrar(::AppReg,
TApplication::GetCmdLine(),
// Did command line say to register only?
//
if (::Registrar->IsOptionSet(amAnyRegOption))
return 0;
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

TOleFactory is a template that creates a class with a factory callback function. For a linking and embedding ObjectWindows application that does not use Doc/View, the template 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.

When the registrar is created, it compares the information in the registration tables to the application's entries in the system registration database and updates the database if necessary. The Run method causes the registrar to call the factory callback which, among other things, enters the application's message loop.