OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Step 7: Processing the command line

When OLE invokes a server, it places an -Embedding switch on the command line to tell the application why it has been invoked.

The presence of the switch indicates that the user did not launch the server directly. Usually a server responds by keeping its main window hidden. The user interacts with the server through the container. If the -Embedding switch is not present, the user has invoked the server as a standalone application and the server shows itself in the normal way.

When you construct a TRegistrar object, it parses the command line for you and searches for any OLE-related switches. It removes the switches as it processes them, so if you examine your command line after creating TRegistrar you will never see them.

If you want to know what switches were found, call IsOptionSet. For example, this line tests for the presence of a registration switch on the command line:

if (::Registrar->IsOptionSet(amAnyRegOption))
return 0;
owl::TPointer< ocf::TRegistrar > Registrar
Global registrar object defined by the client application.

This is a common test in OwlMain. If the a command line switch such as -RegServer was set, the application simply quits. By the time the registrar object is constructed, any registration action requested on the command line have already been performed.

The following table lists all the OLE-related command-line switches

SwitchWhat the server should doOLE places switch?
/RegServerRegister all its information and quitNo
/UnregServerRemove all its entries from the system and quitNo
/NoRegValidateRun without confirming entries in the system databaseNo
/AutomationRegister itself as single-use (one client only). Always accompanied by -EmbeddingYes
/EmbeddingConsider remaining hidden because it is running for a client, not for itselfYes
/LanguageSet the language for registration and type librariesNo
/TypeLibCreate and register a type libraryNo
/DebugEnter a debugging sessionYes

OLE places some of the switches on the program's command line. Anyone can set other flags to make ObjectComponents perform specific tasks. An install program, for example, might invoke the application it installs and pass it the -RegServer switch to make the server register itself. Switches can begin with either a hyphen (-) or a slash (/).

Only a few of the switches call for any action from you. If a server or an automation object sees the -Embedding or -Automation switch, it might decide to keep its main window hidden. Usually ObjectComponents makes that decision for you. You can use the -Debug switch as a signal to turn trace messages on and off, but responding to -Debug is always optional. (OLE uses -Debug switch only if you register the debugprogid key.)

ObjectComponents handles all the other switches for you. If the user calls a program with the -UnregServer switch, ObjectComponents examines its registration tables and erases all its entries from the registration database. If ObjectComponents finds a series of switches on the command line, it processes them all. This example makes ObjectComponents generate a type libary in the default language and then again in Belgian French.

myapp -TypeLib -Language=80C -TypeLib

the number passed to -Language must be hexadecimal digits. The Win32 API defines 80C as the locale ID for the Belgian dialect of the French language. For this command line to have the desired effect, of course, myapp must supply Belgian French strings in its XLAT resources.

The -RegServer flag optionally accepts a file name.

This causes ObjectComponents to create a registration data file in MYAPP.REG. The new file contains all the application's registration data. If you distribute MYAPP.REG with your program, users can merge the file directly into their own registration database (using RegEdit). Without a file name, -RegServer writes all data directly to the system's registration database.

Note
Only EXE servers have true command lines. OLE can't pass command line switches to a DLL. ObjectComponents simulates passing a command line to a DLL server so that you can use the same code either way. The registrar object always sets the right running mode flags.