| < Free Open Study > |
|
One question that should strike you at this point is "who calls these self-registration functions?" First off, ATL projects automatically register DLL and EXE projects as part of the build process, so your COM servers are always available for you to test against on your development machine. When it comes time to ship the server to another machine, you may opt to register your servers with the aid of a professional installation program. These tools have vendor-specific means to register DLL and EXE servers. If your COM servers are part of a larger stand-alone Windows application, this is sure to be the option for you.
Another approach used to register your COM servers is to use the regsvr32.exe utility. From a command prompt window, navigate to the directory containing the DLL server you wish to register, and send in the name of the DLL as a command line argument (Figure 6-10). If successful, you will see a resulting confirmation message box. You may unregister a server by providing the -u switch (e.g., regsvr32 -u atlshapesserver.dll).
Figure 6-10: Registering a DLL with regsvr32.exe
EXE servers are not registered with the regsvr32.exe utility. Instead, WinMain() is implemented to check for the -regserver or -unregserver command line arguments (proper EXE servers also check for /regserver or /unregserver). Again, from a command prompt, navigate to the directory containing the EXE server you wish to register, and execute it with the appropriate flag:
Figure 6-11: Registering an EXE server at the command line.
Testing for the -regserver or -unregserver arguments in a WinMain implementation is no problem at all. Simply do a string compare between WinMain()'s LPSTR parameter and the token strings. If you find either, make calls into the Win32 registry API to install or remove the correct registry settings:
// Check LPSTR parameter to determine (un)registration command. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { if(strstr(lpCmdLine, "/regserver") || strstr(lpCmdLine, "-regserver")) // Stuff information into registry. if(strstr(lpCmdLine, "/unregserver") || strstr(lpCmdLine, "-unregserver")) // Remove information from registry. ... }
| < Free Open Study > |
|