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

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

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.

The next step is to modify your OwlMain function to allocate a new TOcRegistrar object and initialize the global pointer Registrar. The TOcRegistrar constructor expects 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 a template class. For a linking and embedding ObjectWindows application that uses Doc/View, the template class is called TOleDocViewFactory.
  • The command line string can come from the GetCmdLine method of TApplication.

After initializing the Registrar pointer, your OLE container application must invoke the Run method of the registrar 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. However, using the registrar method makes your application OLE server-ready. The following code shows an example of OwlMain after the addition of a 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

The last parameter of the TOcRegistrar constructor is the command line string that invokes the application. The registrar object processes the command line by searching for switches, such as /Embedding or /Automation, that OLE may have placed there. ObjectComponents takes whatever action the switches call for and then removes them. If for some reason you need to test the OLE switches, be sure to do it before constructing the registrar. If you have no use for the OLE switches, wait until after constructing the registrar before parsing the command line.