Library Zone Articles
External Articles
Byte Size

Discovery Zone Catalogue
Diary
Links
Bookstore
Interactive Zone Ask the Gurus
Discussion Groups
Newsletters
Feedback
Etc Cartoons
Humour
COMpetition
Advertising
Site Builder ASP Web Ring ASP Web Ring

Click here
The Developer's Resource & Community Site
COM XML ASP Java & Misc. NEW: VS.NET
International This Week Forums Author Central Find a Job

Coding a DCOM Client

To work with any of these samples you will need the following:

  • Microsoft Visual J++ ver 6.0

The Steps involved in developing the DCOM Client are

  1. Add a new project StockDCOMClient to the StockDCOM project
  2. Add COM wrapper of SimpleStocks to StockDCOMClient
  3. Add code to Form1.java
  4. Build and run the client

Add a new project StockDCOMClient to the StockDCOM project

From Project Explorer | Solution | Add Project | Applications | Windows Application | Name: StockDCOMClient

From Project Explorer | StockDCOMClient | StockDCOMClient Properties | ClassPath uncheck the "Merge all Project-specific ClassPaths in solution" check box.

2. Add COM wrapper of SimpleStocks to StockDCOMClient

From Project Explorer | StockDCOMClient | Add | COM Wrapper check the checkbox listed with "SimpleStocks 1.0 Type Library".
Click "OK" to confirm list of COM Wrappers. Notice that the stockmarketlib folder was created under the StockDCOMClient project.
Notice the java source files that have been generated: StockMarket.java and IStockMarket.java

3. Add code to Form1.java

Form1.java
import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;

/**
 * This class can take a variable number of parameters on the command
 * line. Program execution begins with the main() method. The class
 * constructor is not invoked unless an object of type 'Form1' is
 * created in the main() method.
 */

public class Form1 extends Form {
 
  String editValue = null;
 
/**
   * TODO: make sure all your constructors/initialization code
   * paths have the following line:
   *   initForm();
   */

  public Form1() {
    // Required for Visual J++ Form Designer support
    initForm();

    // TODO: Add any constructor code after initForm call
  }

  /**
   * Form1 overrides dispose so it can clean up the
   * component list.
   *
   * TODO: have dispose call
   *   components.dispose();
   */

  public void dispose() {
    super.dispose();
    components.dispose();
  }

  private void edit1_Leave(Object source, Event e) {
    String editValue = edit1.getText();
    try {
      stockmarketlib.IStockMarket market = (stockmarketlib.IStockMarket)new stockmarketlib.StockMarket();
      String str = "$ "+market.get_price(editValue);
     
edit2.setText(str);
 
     
System.out.println( "The price of "+editValue+" is " + market.get_price(editValue) );
    }
    catch (com.ms.com.ComFailException exception) {
      System.out.println( "COM Exception:" );
    }

  }

  private void button1_click(Object source, Event e) {
    System.exit(0);
  }

  /**
   * NOTE: The following code is required by the Visual J++ form
   * designer.  It can be modified using the form editor.  Do not
   * modify it using the code editor.
   */

  Container components = new Container();
  Label label1 = new Label();
  Edit edit1 = new Edit();
  Label label2 = new Label();
  Edit edit2 = new Edit();
  Button button1 = new Button();

  private void initForm() {
    this.setText("StockDCOM Client");
    this.setAutoScaleBaseSize(new Point(5, 13));
    this.setClientSize(new Point(292, 157));

    label1.setLocation(new Point(8, 32));
    label1.setSize(new Point(136, 16));
    label1.setTabIndex(0);
    label1.setTabStop(false);
    label1.setText("Enter the Stock Symbol");

    edit1.setLocation(new Point(168, 32));
    edit1.setSize(new Point(100, 20));
    edit1.setTabIndex(1);
    edit1.setText("MY_COMPANY");
    edit1.addOnLeave(new EventHandler(this.edit1_Leave));

    label2.setLocation(new Point(8, 80));
    label2.setSize(new Point(128, 23));
    label2.setTabIndex(2);
    label2.setTabStop(false);
    label2.setText("Price of my company is");

    edit2.setLocation(new Point(168, 72));
    edit2.setSize(new Point(100, 20));
    edit2.setTabIndex(3);
    edit2.setText("$ 0.0");
    edit2.setReadOnly(true);

    button1.setLocation(new Point(112, 120));
    button1.setSize(new Point(75, 23));
    button1.setTabIndex(4);
    button1.setText("Exit");
    button1.addOnClick(new EventHandler(this.button1_click));

    this.setNewControls(new Control[] {
                        button1,
                        edit2,
                        label2,
                        edit1,
                        label1});
  }

  /**
   * The main entry point for the application.
   *
   * @param args Array of parameters passed to the application
   * via the command line.
   */

  public static void main(String args[]) {
    Application.run(new Form1());
  }
}

4. Build and run the client

IDL Client

What do you think of this article?

You can also write a review. We will publish the best ones here on this article. Send your review to [email protected].

Mail a question to the author!!

As part of the IDevResource commitment to Open Publishing, all of our authors are available to answer all of your trickiest questions at Author Central. For information about the authors, or to mail a question, visit them at Author Central.

Want to read more articles by this author?

Try these:

Byte size articles:

COM Threading Models By Gopalan Suresh Raj, 070200
Gopalan explains the differences in COM and Win 32 threading models.
Go To Article.

ActiveX & COM By Gopalan Suresh Raj, 270100
Gopalan explains the basics of ActiveX / COM as a truly distributed Object Oriented Architecture.
Go To Article.

Full size articles:

COM Channel:

Java COM Integration - Use Visual J++ to implement COM Objects By Gopalan Suresh Raj.
Go To Article.

Developing an MSMQ Server Application using VJ++ By Gopalan Suresh Raj.
Go To Article.

Developing an MSMQ Client using VJ++ By Gopalan Suresh Raj.
Go To Article.

Coding a DCOM Server Component from IDL By Gopalan Suresh Raj.

Coding a DCOM Client By Gopalan Suresh Raj.

Microsoft Transaction Server By Gopalan Suresh Raj.
Gopalans introductory article on Microsoft Transaction Server intorduces the basics to MTS, and leads in to the example articles included in the series.

Developing a Simple MTS Server Component By Gopalan Suresh Raj.
Part 1 of a two part example.

Developing a Simple MTS Client Application By Gopalan Suresh Raj.
Part 2 of a two part example.

Developing The Bank Account IDL By Gopalan Suresh Raj.
A Three-Tier Architecture for a Bank Checking Account - Developing The Bank Account IDL is part 1 of a 3 part example.

MTS Server Component By Gopalan Suresh Raj.
A Three-Tier Architecture for a Bank Checking Account - MTS Server Component is the second part of this three part example.

MTS Client By Gopalan Suresh Raj.
A Three-Tier Architecture for a Bank Checking Account - MTS Server Component is the third part of this three part example.

Java Channel:

Enterprise Java Beans By Gopalan Suresh Raj.
In this introduction to Enterprise Java Beans, Gopalan covers the bases then goes on to demonstrate how to build server side business object components. This article is the introduction to Gopalan's series of Enterprise JavaBeans articles. (This series of articles is © Copyright 1997-2000 Gopalan Suresh Raj. Reproduced with Permission)

Enterprise Java Beans Series - Components at the Server By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Model By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Naming Services and JNDI By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Transactions and JTS By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Lifecycle By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Servers By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Containers By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Components By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Session Beans By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Entity Beans By Gopalan Suresh Raj.

Enterprise Java Beans Series - Writing an Entity Bean By Gopalan Suresh Raj.
Part 1 of a four part series: A four tier bank account example

Enterprise Java Beans Series - Writing a Session Bean By Gopalan Suresh Raj.
Part 2 of a four part series: A four tier bank account example

Enterprise Java Beans Series - Writing an EJB Client By Gopalan Suresh Raj.
Part 3 of a four part series: A four tier bank account example

Enterprise Java Beans Series - Writing an EJB Servlet Client By Gopalan Suresh Raj.
Part 4 of a four part series: A four tier bank account example

More COM Library articles:

CAtlBitmapButton - ATL/WTL Ownerdraw Superclassed Bitmap Button By Amit Dey.
Amit describes building a simple user interface consisting of a series of bitmap buttons in a dialog.

ATL COM and ADO By Paddy Srinivas.
COM+ Events addresses many shortcomings of Connection points. Paddy Srinivas walks us through the COM+ Events System.

ATL COM and ADO By Amit Dey.
New author Amit Dey (he's looking for a job BTW ;-) ) explains his recent experiences with ATL COM and ADO. He simply explains the fundamentals of ADO and then runs through some ATL code examples in his application.

COM Singletons: A Dangerous Animal By Richard Blewett.
Richard Blewitt simply explains the use of COM Singletons.

ASP COM Objects By Jan Verhoeven.
Creating ASP com objects, or Active Server Objects with Delphi 5 is very easy, once you know how to do it.

SafeArrays - For the Beginner By A. Abdul Azeez.
This article is a primer to Safe Arrays and can be used by any beginner to Safe Arrays.

COM+ Basics - Creating your first COM+ Application By Martin Lapierre.

COM+ - the backbone of Windows DNA By Mahesh Bhide.

Exploring COM Threading and Apartments By Anthony Toivonen.
Anthony Toivonen wants you to figure it out for yourself: he guarantees success in threads and apartments after reading this article.

COM on Linux By Frank Rem.
A description of how to code a DCOM client for Linux without using Microsoft products.

ATL Server By Richard Grimes.
A description of ATL Server.

ATL Internals - Part 2 By Shivesh Viswanathan.
Following on from Shivesh's first article of this two part series, this article covers the details of the internals of ATL.

How to use DDX with WTL By Girish Bharadwaj.

COM Patterns By Tony Toivonen.

COM+ Object Pooling By Jeremiah Talkar.

What are COM Pipes? By Richard Grimes.

Java COM Integration - Use Visual J++ to implement COM Objects By Gopalan Suresh Raj.

Developing an MSMQ Server Application using VJ++ By Gopalan Suresh Raj.

Developing an MSMQ Client using VJ++ By Gopalan Suresh Raj.

What is Async COM? By Richard Grimes.

Coding a DCOM Server Component from IDL By Gopalan Suresh Raj.

Coding a DCOM Client By Gopalan Suresh Raj.

Threads and Apartments By Brad Wilson.
Brad's article gives detailed information about apartments and their relationship to threading and synchronization. The goal is to demystify what is a very important, yet under-documented system in COM.

WTL Architecture By Richard Grimes.
This article covers the basics of the WTL architecture, it describes the types of applications that you can create and how WTL manages threads. The example monitors the debug stream and uses WTL to present this data.

The MTS Series by Gopalan Suresh Raj:

Microsoft Transaction Server By Gopalan Suresh Raj.
Gopalans introductory article on Microsoft Transaction Server introduces the basics to MTS, and leads in to the example articles included in the series.

Developing a Simple MTS Server Component By Gopalan Suresh Raj.
Part 1 of a two part example.

Developing a Simple MTS Client Application By Gopalan Suresh Raj.
Part 2 of a two part example.

Developing The Bank Account IDL By Gopalan Suresh Raj.
A Three-Tier Architecture for a Bank Checking Account - Developing The Bank Account IDL is part 1 of a 3 part example.

MTS Server Component By Gopalan Suresh Raj.
A Three-Tier Architecture for a Bank Checking Account - MTS Server Component is the second part of this three part example.

MTS Client By Gopalan Suresh Raj.
A Three-Tier Architecture for a Bank Checking Account - MTS Server Component is the third part of this three part example.

Other Articles

Active Template Library: Architecture & Internals By Shivesh Viswanathan.
Active Template Library is basically a set of template classes provided by Microsoft for writing COM components. The time to write COM components can be considerably reduced if they are written using the ATL framework. The document here provides theory of what goes inside ATL to implement certain generic interfaces.

Microsoft Transaction Server By Richard Grimes.
Introduces Microsoft Transaction Server

What COM is all about By Richard Grimes.
An introductory article to COM, covering all basics including OLE, Activex and DLL's.

String Binding Moniker By Frank Rem.
This article shows how a SB Moniker resolves a connection with a DCE RP server running on Linux using a VB client.


Author: Gopalan Suresh Raj

Gopalan Suresh Raj is a Software Architect, Developer and an active Author.

He is contributing author to a couple of books "Enterprise JavaComputing-Applications and Architecture"(Cambridge University Press, June '99) and "TheAwesome Power of JavaBeans"(Manning, July'98).

His expertise spans enterprise component architectures and distributed object computing. Visit him at his Web Cornucopia site (https://www.execpc.com/~gopalan)or mail him at [email protected].

Go to Gopalan's pages in Author Central.


Power your site with idr newswire

Contribute to IDR:

To contribute an article to IDR, a click here.

To contact us at IDevResource.com, use our feedback form, or email us.

To comment on the site contact our webmaster.

Promoted by CyberSavvy UK - website promotion experts

All content © Copyright 2000 IDevResource.com, Disclaimer notice

Java COM integration

Code Project

Visit the IDR Forums

Visit the IDR Bookstore!