2.7.1 Initialization

During installation, an OLE server application should verify that it is registered in the system registration database and if not, register itself. Registration only needs to occur for the first instance of an application. By isolating your existing installation code, you can create a place to insert the code that has to deal with the registration database. If all initialization code resides in one function call made from WinMain, then that function can simply return FALSE indicating there was an error so that WinMain can terminate the application.

One of the complexities of initialization is parsing the command-line to detect an /Embedding option. To make this task easier, consider writing a function to parse the command line into separate parameters. For more information on parsing the command line, see Chapter 4, "Implementing OLE into Server Applications."

When the /Embedding switch is present, the nCmdShow parameter passed to WinMain will have to change; you will need to include some method in your initialization function to return the modified nCmdShow. This can be done by passing a pointer to nCmdShow to the initialization function so that it can modify nCmdShow or leave it alone. WinMain then does not have to change, since nCmdShow was changed behind the scenes.