Make your own free website on Tripod.com

Developing The Bank Account IDL
Gopalan Suresh Raj

Note
To work with any of these samples, you will need the following:
.........................................Microsoft Visual J++ ver 6.0
.........................................Windows NT 4.0 Options Pack
.........................................guidgen.exe and midl.exe from Microsoft Visual C++ ver 6.0

In Visual J++, the most simplest method to create an MTS server component is to first write your server code in pure Java and then create a COM wrapper for it. However, creating the component from scratch using the IDL will allow you more flexibility and control in coding the server component. Hence, we will develop our Bank Account from scratch using IDL.

The Steps involved in developing the MTS Server component are

1. Code the IDL
2. Compile the IDL and generate the type library

1. Code the IDL
Write the code for the IDL as follows. Use
guidgen.exe where necessary to generate new UUIDs. Code the Checking and Savings Account interfaces and create interfaces to access the Primary Key so that if we need to have a collection of keys that form our primary key, we can work easier.

Bank.idl
[
  uuid (07D690F0-FB95-11d2-97E3-006097A7D34F),
  version (1.0)
]
library Bank {

  /*
   * Primary Key Interface for accounts
   */

  importlib ("stdole32.tlb");
  [
    uuid (07D690F1-FB95-11d2-97E3-006097A7D34F),
    dual
  ]
  interface IAccountKey : IDispatch {
    HRESULT setKey ([in] int key);
  }

  /*
   * Checking creation interface
   */

  [
    uuid (07D690F2-FB95-11d2-97E3-006097A7D34F),
    dual
  ]
  interface ICheckingHome : IDispatch {
    HRESULT create ([in] IAccountKey* key,
                    [in] BSTR name,
                    [in] double startingBalance);

  }

  /*
   * Checking Interface for business rules
   */

  [
    uuid(07D690F3-FB95-11d2-97E3-006097A7D34F),
    dual
  ]
  interface IChecking : IDispatch {
    HRESULT credit ([in] double amount,
                    [in] IAccountKey* key);

    HRESULT debit ([in] double amount,
                   [in] IAccountKey* key);

    HRESULT getBalance ([in] IAccountKey* key,
                        [out, retval] double* balance);

    HRESULT getCustomerName ([in] IAccountKey* key,
                             [out, retval] BSTR* name);

  }

  /*
   * Checking Primary Key class
   */

  [
    uuid(07D690F4-FB95-11d2-97E3-006097A7D34F)
  ]
  coclass CheckingPK {
    interface IAccountKey;
  };

  /*
   * Checking class
   */

  [
    uuid(07D690F5-FB95-11d2-97E3-006097A7D34F)
  ]
  coclass Checking {
    interface ICheckingHome;
    interface IChecking;
  };

  /*
   * Savings creation interface
   */

  [
    uuid (07D690F6-FB95-11d2-97E3-006097A7D34F),
    dual
  ]
  interface ISavingsHome : IDispatch {
    HRESULT create ([in] IAccountKey* key,
                    [in] BSTR name,
                    [in] float interestRate,
                    [in] double startingBalance);

  }

  /*
   * Savings Interface for business rules
   */

  [
    uuid(07D690F7-FB95-11d2-97E3-006097A7D34F),
    dual
  ]
  interface ISavings : IDispatch {
    HRESULT credit ([in] double amount,
                    [in] IAccountKey* key);

    HRESULT debit ([in] double amount,
                   [in] IAccountKey* key);

    HRESULT getBalance ([in] IAccountKey* key,
                        [out, retval] double* balance);

    HRESULT getCustomerName ([in] IAccountKey* key,
                             [out, retval] BSTR* name);

    HRESULT getInterestRate ([in] IAccountKey* key,
                             [out, retval] float* rate);

  }

  /*
   * Savings Primary Key
   */

  [
    uuid(07D690F8-FB95-11d2-97E3-006097A7D34F)
  ]
  coclass SavingsPK {
    interface IAccountKey;
  };

  /*
   * Savings class
   */

  [
    uuid(07D690F9-FB95-11d2-97E3-006097A7D34F)
  ]
  coclass Savings {
    interface ISavingsHome;
    interface ISavings;
  };
};

2. Generate the type library from the IDL
Use the
midl.exe that comes with your VC++ to compile the IDL files. If the VC++ environment variables are not loaded use the full path to midl.exe. Notice that Bank.tlb will now appear.

MS DOS Command Prompt
E:\com\gopalan\AccountMTS>
E:\com\gopalan\AccountMTS>midl Bank.idl
Microsoft (R) MIDL Compiler Version 5.01.0164
Copyright (c) Microsoft Corp 1991-1997. All rights reserved.
Processing .\Bank.idl
Bank.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\oaidl.idl
oaidl.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\objidl.idl
objidl.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\unknwn.idl
unknwn.idl
Processing D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\wtypes.idl
wtypes.idl

E:\com\gopalan\AccountMTS>

 

click here to go to the
Developing the Checking Account MTS Server...
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 April 26,1999.

Last Updated : Apr 26,'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.