HOWTO: Write an MTS Component Using ATL

Last reviewed: June 25, 1997
Article ID: Q166276
The information in this article applies to:
  • Microsoft Transaction Server, version 1.0
  • Microsoft Visual C++, 32-bit Editions, version 5.0

SUMMARY

This article describes how to write a Microsoft Transaction Server (MTS) component using the Active Template Library (ATL), which is included with Visual C++ version 5.0.

MORE INFORMATION

Follow these steps to create a simple MTS component:

Create a New ATL Project

  1. Click New from the File menu.

  2. Click the Projects tab, select the ATL COM AppWizard, and type in the Project name "MTSProj1" and Location. Click "Create a new workspace."

        Click OK.
    

  3. On the ATL COM AppWizard screen, select a Server Type of "Dynamic Link Library (DLL)" and click "Allow merging of proxy/stub code." Click Finish.

  4. Confirm the new project information and click OK.

Insert an MTS Component

  1. Click New ATL Object from the Insert menu.

  2. In the ATL Object Wizard, select Objects in the left pane, then select MS Transaction Server in the right pane. Click Next.

  3. Click the Names tab of the ATL Object Wizard Properties. Type in a C++ Short Name of "MTSObj1." Do not click OK at this time.

  4. Click the MTX tab and select a Dual Interface. As an option, you can also select "Support IObjectControl" and "Can be pooled," which tells the MTS run-time environment that your object should be returned to an instance pool after deactivation, rather than destroyed. This is, however, not required for a minimal component. Click OK to generate the component.

Add a Method to Your Component

  1. If you do not currently have the project workspace displayed, click Workspace from the View menu.

  2. Select the ClassView tab in the project workspace and expand the top level to see your class (CMTSObj1) and interface (IMTSObj1) names. Right-click on the interface name and select Add Method.

  3. Type in the Method Name "Return5" and the Parameters "[out]long*" and click OK. You will not be able to change the Return Type from HRESULT because you are implementing a dual interface.

Implement the Method

  1. Implement the CMTSObj1::Return5 method as follows:

          STDMETHODIMP CMTSObj1::Return5 (long* number)
          {
    
              *number = 5;
              return S_OK;
          }
    
    
You should now be able to build your project and add it to the MTS Explorer.


Keywords : TSrvProg
Technology : kbAtl kbInetDev
Version : 1.0 5.0
Platform : NT WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 25, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.