ONDotNet.com    
 Published on ONDotNet.com (http://www.ondotnet.com/)
 See this if you're having trouble printing code examples


Writing Your First COM Component, Part 2

by Abel Banda
01/28/2002

In Part 1 of this article, we created a COM component. In this part, we'll get our component to leverage COM+/COM services (to fully leverage COM+, you must use the COM+ Library). This quick-step guide will show you how to complete the transformation from your typical DLL to a full-fledged COM component. Microsoft's site has more information on the benefits of COM+/COM and 3-tier business web sites.

Note: Prior to initiating component services, it is vital that you have component services installed. If it is not installed, install it prior to proceeding through this guide.

Step 1 : Creating Your Component Services Application.

    From the Start menu, select the Settings and then Control Panels.
  1. Click on the Administrative Tools icon. This will display all installed administrative applications.

  2. Now, click on the Component Services icon. This is the core engine of COM+/COM/MTS. If you've used DTS, this looks all too familiar.

  3. On the left of the Component Services window, there is a pane with a tree menu that features three main applications under the Console Root. To create our COM application, drop down the Component Services tree item.
  4. Now, drop down the Computers tree to designate your computer as the computer from which you want to run our sample COM application.
  5. Once this is done, open the COM+ Applications folder. This is where all of your COM applications are stored. We will be adding an application to this library. There should be some COM+/COM Applications already installed by default.
  6. In the left pane, your COM+ Applications folder should be collapsed, displaying all of the COM+/COM applications in the right pane.

  7. Select the COM+ Applications folder in the left pane and right-click on it to bring up a context menu. Select New and Application (the only option you have).

  8. This will launch the COM Application Install Wizard. Click Next to proceed.
  9. Since we are starting from scratch with our new component, click on the button labeled "Create an empty application. You are now prompted to enter a name for the new application. Enter "myfirstcom." Make sure that the default setting of "Server Application" is turned on in the "Activation Type" menu prior to proceeding. Click Next to proceed.
  10. Next you are prompted to set application identity. This is the user from which the application will be executed. Your answer depends on the sort of network policy you have. For this sample, we will assume that the application requires a username and password; thus, type in a real username, password, and password confirmation for the server. It is recommended that you use your current username and password per your current login, or create a special user just for your COM application(s).
  11. That's it, just click finish, and we're ready to proceed.

Step 2 : Registering Your Component In COM+/COM Services.

  1. Launch your file explorer by typing c:\ from the Run command (available from the Start menu.)
  2. Locate your DLL (component) we created in Part 1 of this article. It should be located in your c:\winnt\system32\ directory. Adjust the window to fill half your screen, and adjust your Component Services window to make up the other half of the screen (as we prepare to drag-and-drop your component into our com application).
  3. Notice how your new COM application has been created and is displayed from the collapsed COM+ Applications folder. Select your myfirstcom application, then select Components. Your right pane should now be cleared because you do not have any components in this application yet.
  4. Now simply drag and drop the component from the Explorer window onto the right pane of the Component Services window. You now have a COM application with a working component.

Return to the .NET DevCenter.

Copyright © 2009 O'Reilly Media, Inc.