Make your own free website on

Developing A Simple MTS Server Component using Visual C++
Gopalan Suresh Raj


To work with any of these samples, you will need the following:
.........................................Microsoft Visual C++ ver 6.0
.........................................Windows NT 4.0 Options Pack

The ClickServer has an Increment() method. Clients call this method and pass in an integer argument. All this server component does is increment the value passed in and return it back to the client.

The Steps involved in developing the MTS Server component are

1. Create a new COM DLL project
2. Insert an MTS Component
3. Add Business Methods to Your Component
4. Build the DLL
5. Deploy the DLL into The Microsoft Transaction Server Explorer

1. Create a New ATL Project

1) From the File menu, Click New.
Select the Projects tab.
Start a new project, click ATL COM AppWizard, then click OK.

2) For Microsoft Transaction Server, you must create a DLL.
Adding support for merging proxy/stub code and MFC is optional
Select the Support MTS button.

3) Click on the Finish button and confirm the new project information and click on OK.

2. Insert an MTS Component

1) Click New ATL Object from the Insert menu.
In the ATL Object Wizard, select Objects in the left-pane, then select MS Transaction Server Component in the right-pane.
Click Next.

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

3) Select the MTS 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.

3. Add a Business 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 (Server) and interface (IServer) names.
Right-click on the interface name and select Add Method.

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

4. Implement the Business Method

1) Implement the CServer::Increment method as follows:

STDMETHODIMP CServer::Increment(int *value)
  // TODO: Add your implementation code here
  // Get the Object Context
  bool bSuccess = false;

  // Implement your business logic here
  bSuccess = true;

  if(bSuccess == true)
    // No errors. Complete transaction
    m_spObjectContext->SetComplete ();
    // Error occurred. Abort transaction
    m_spObjectContext->SetAbort ();

	return S_OK;
2) Build your project
--------------------Configuration: ClickServer - Win32 Release MinDependency--------------------
Creating Type Library...
Microsoft (R) MIDL Compiler Version 5.01.0164
Copyright (c) Microsoft Corp 1991-1997. All rights reserved.
Processing E:\com\gopalan\ClickServer\ClickServer.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\oaidl.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\objidl.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\unknwn.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\wtypes.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\ocidl.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\oleidl.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\servprov.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\urlmon.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\msxml.idl
Compiling resources...
Generating Code...
Creating library ReleaseMinDependency/ClickServer.lib and object ReleaseMinDependency/ClickServer.exp
Performing registration
RegSvr32: DllRegisterServer in .\ReleaseMinDependency\ClickServer.dll succeeded.
Execute mtxrereg.exe before using MTS components in MTS

ClickServer.dll - 0 error(s), 0 warning(s)

3) Register the Server DLL.

MS-DOS Prompt
E:\com\gopalan\ClickServer\ReleaseMinDependency>regsvr32 ClickServer.dll

Mtxrereg: Refreshing all locally registered Mtx components...
Done: All Mtx components were refreshed.



5. Add the MTS Component to MTS Explorer

1) Start up the MTS Explorer.

2) Right Click the Packages Installed on the Computers->My Computer, and select New.
In the Package Wizard, click on Create an empty package.

3) Type in the name of the package, which is ClickServer in the edit box, and click on the Next button.

4) Click on the Add Files button, and select the ClickServer.DLL in from the appropriate directory and click on the Finish button.


Download the Entire Source as a Zip file


click here to go to the
Developing a Simple MTS Client Page...
click here to go to
My MTS HomePage...

Go to the Component Engineering Cornucopia page

This site was developed and is maintained by Gopalan Suresh Raj

This page has been visited times since February 24,1999.

Last Updated : Feb 24, '99

If you have any questions, comments, or problems regarding this site, please write to me I would love to hear from you.

Copyright (c) 1997-99, Gopalan Suresh Raj - All rights reserved. Terms of use.

All products and companies mentioned at this site,are trademarks of their respective owners.