|
The Developer's Resource & Community Site
|
Coding a DCOM Server Component from IDL
Author: Gopalan Suresh Raj
Date Submitted: February 10th 2000
Level of Difficulty: Advanced
Subjects Covered: IDL, DCOM, J++
Pre-required Reading: Component Object Model
To work with any of these samples you will need the following:
- Microsoft Visual J++ ver 6.0
- guidgen.exe and midl.exe from Microsoft Visual C++ ver 6.0
In Visual J++, the most simplest method to create a DCOM 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, I am presenting here a stock market server component developed from scratch using IDL.
The Steps involved in developing the DCOM Server component from IDL are
- Create an empty project
- Define your interface in IDL
- Compile your IDL and generate the required typelibs necessary
- Set the properties for your project
- Implement the DCOM server component
- Build and register the DCOM server component
1. Create an empty project
Select New Project and from the File menu, choose the Empty project template in Visual J++. Name the project StockDCOM.
2. Define your interface in IDL
Use guidgen.exe where necessary to generate new UUIDs
StockMarketLib.idl |
[
uuid(7371a240-2e51-11d0-b4c1-444553540000),
version(1.0)
]
library SimpleStocks {
importlib("stdole32.tlb");
[
uuid(BC4C0AB0-5A45-11d2-99C5-00A02414C655),
dual
]
interface IStockMarket : IDispatch
{
HRESULT get_price([in]
BSTR p1, [out, retval] float * rtn);
} [
uuid(BC4C0AB3-5A45-11d2-99C5-00A02414C655),
]
coclass StockMarket {
interface IStockMarket;
};
};
|
3. Compile the idl file and generate typelibs
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 stockmarketlib.tlb will now appear under the StockDCOM project.
E:\MyProjects\StockDCOM>
E:\MyProjects\StockDCOM>midl StockMarketLib.idl
Microsoft (R) MIDL Compiler Version 5.01.0164
Copyright (c) Microsoft Corp 1991-1997. All rights
reserved.
Processing .\StockMarketLib.idl
StockMarketLib.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:\MyProjects\StockDCOM>
|
4. Set the properties for your project
- From the Project Explorer | StockDCOM | StockDCOM Properties | ClassPath, uncheck the "Merge all Project-specific ........ClassPaths in solution" check box
- From the Project Explorer | StockDCOM | StockDCOM Properties | COM Classes check the "Use existing Type Library" ........radio button
- Click the "Select" button
- Click the "Browse" button
- Browse to the newly created StockMarketLib.tlb file in the project directory
- Select and open the StockMarketLib.tlb file
- Click the "OK" button to confirm the list of COM Components
- Click "OK" to confirm StockMarketLib Properties form changes
- Notice that the StockMarketLib folder is added to the StockDCOM project
- Notice that three java source files have been created:
StockMarket.java, IStockMarket.java, and IStockMarketDefault.java
- Rename the generated implementation class, StockMarket.java to StockMarketImpl.java
- StockMarket.class will be a COM wrapper automatically generated during the compile phase
5. Implement the DCOM Server Component
Edit StockMarketImpl.java as needed to implement the interface. Notice that when JActiveX created the file it placed skeleton code in place
StockMarketImpl.java |
//
// Auto-generated using JActiveX.EXE 5.00.2918
// ("D:\Program Files\Microsoft Visual
Studio\VJ98\jactivex.exe" /javatlb /c2j
// /creg /xh /wfc /w /xi /X:rkc /l
"F:\TEMP\jvcD.tmp" /nologo /d
// "E:\MyProjects\StockDCOM"
"E:\MyProjects\StockDCOM\StockMarketLib.tlb")
//
// WARNING: Do not remove the comments that include
"@com" directives.
// This source file must be compiled by a @com-aware
compiler.
// If you are using the Microsoft Visual J++ compiler,
you must use
// version 1.02.3920 or later. Previous versions will not
issue an error
// but will not generate COM-enabled class files.
// package stockmarketlib;
import
com.ms.com.*;
import com.ms.com.IUnknown;
import com.ms.com.Variant;
/**
@com.register(clsid=BC4C0AB3-5A45-11D2-99C5-00A02414C655,
* typelib=7371A240-2E51-11D0-B4C1-444553540000,
* version="1.0") */
public class StockMarketImpl implements IUnknown,
com.ms.com.NoAutoScripting,
stockmarketlib.IStockMarketDefault
{
public float get_price(String
symbol) {
float price = 0;
for( int i = 0; i < symbol.length(); i++ ) {
price += (int)
symbol.charAt(i);
}
price /= 5;
return price;
}
}
|
6. Build and register the COM DLL Server component
Project Explorer | StockDCOM | Build
Notice that both StockMarket.class and StockMarketImpl.class are in the project folder
StockMarket.class will be "hidden" using the Project Explorer.
StockMarket is the COM callable wrapper generated by the @com.register directive
StockMarketImpl is the J++ code we defined for the COM object.
Next....Coding a DCOM 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.
Author: Gopalan Suresh Raj
Date Submitted: February 10th 2000
Level of Difficulty: Advanced
Subjects Covered: IDL, DCOM, J++
Pre-required Reading: Component Object Model
Coding a DCOM Client By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: February 10th 2000
Level of Difficulty: Advanced
Subjects Covered: IDL, DCOM, J++
Pre-required Reading: Component Object Model, Coding a DCOM Server Component from IDL
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.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: None
Developing a Simple MTS Server Component By Gopalan Suresh Raj.
Part 1 of a two part example.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server
Developing a Simple MTS Client Application By Gopalan Suresh Raj.
Part 2 of a two part example.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server, Developing a Simple MTS Server Component
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.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server
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.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server, Developing The Bank Account IDL
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.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server, Developing The Bank Account IDL, MTS Server Component
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)
Author: Gopalan Suresh Raj
Date Submitted: January 6th 2000
Level of Difficulty: Advanced
Subjects Covered: Enterprise JavaBeans, EJB Server, EJB Architecture, Java Naming and Directory Interface, Java Transaction Service.
Pre-required Reading: None
Enterprise Java Beans Series - Components at the Server By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: January 11th 2000
Level of Difficulty: Advanced
Subjects Covered: Server side components, CORBA
Pre-required Reading: Enterprise JavaBeans
Enterprise Java Beans Series - EJB Model By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: January 11th 2000
Level of Difficulty: Advanced
Subjects Covered: Enterprise JavaBeans, EJB Server, EJB Containers, EJB Clients.
Pre-required Reading: Enterprise JavaBeans
Enterprise Java Beans Series - EJB Naming Services and JNDI By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: January 11th 2000
Level of Difficulty: Advanced
Subjects Covered: Naming Services, Java Naming Directory Interface
Pre-required Reading: Enterprise JavaBeans
Enterprise Java Beans Series - EJB Transactions and JTS By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: January 11th 2000
Level of Difficulty: Advanced
Subjects Covered: Java Transaction Service, Two-phase commits
Pre-required Reading: Enterprise JavaBeans
Enterprise Java Beans Series - EJB Lifecycle By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: January 11th 2000
Level of Difficulty: Advanced
Subjects Covered: EJB server provider, EJB container provider, EJB developer, EJB deployer, Application developer.
Pre-required Reading: Enterprise JavaBeans
Enterprise Java Beans Series - EJB Servers By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: January 11th 2000
Level of Difficulty: Advanced
Subjects Covered: Server Infrastructure
Pre-required Reading: Enterprise JavaBeans
Enterprise Java Beans Series - EJB Containers By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: January 11th 2000
Level of Difficulty: Advanced
Subjects Covered: EJB Containers, EJB Servers
Pre-required Reading: Enterprise JavaBeans
Enterprise Java Beans Series - EJB Components By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: January 11th 2000
Level of Difficulty: Advanced
Subjects Covered: EJB Object, Home Object, Remote Object
Pre-required Reading: Enterprise JavaBeans
Enterprise Java Beans Series - EJB Session Beans By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: January 11th 2000
Level of Difficulty: Advanced
Subjects Covered: Stateful Session Beans, Stateless Session Beans
Pre-required Reading: Enterprise JavaBeans
Enterprise Java Beans Series - EJB Entity Beans By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: January 11th 2000
Level of Difficulty: Advanced
Subjects Covered: Container-Managed Persistence, Bean-Managed Persistence
Pre-required Reading: Enterprise JavaBeans
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
Author: Gopalan Suresh Raj
Date Submitted: January 11th 2000
Level of Difficulty: Advanced
Subjects Covered: Developing Entity Beans, Home & Remote Interfaces, Data Sources.
Pre-required Reading: Enterprise JavaBeans
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
Author: Gopalan Suresh Raj
Date Submitted: January 11th 2000
Level of Difficulty: Advanced
Subjects Covered: Developing Session Beans, Home & Remote Interfaces, Deployment Descriptors.
Pre-required Reading: Enterprise JavaBeans
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
Author: Gopalan Suresh Raj
Date Submitted: January 11th 2000
Level of Difficulty: Advanced
Subjects Covered: EJB Clients.
Pre-required Reading: Enterprise JavaBeans
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
Author: Gopalan Suresh Raj
Date Submitted: January 11th 2000
Level of Difficulty: Advanced
Subjects Covered: Servlet Clients.
Pre-required Reading: Enterprise JavaBeans
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.
Author: Amit Dey
Date Submitted: June 8 2001
ATL COM and ADO By Paddy Srinivas.
COM+ Events addresses many shortcomings of Connection points. Paddy Srinivas walks us through the COM+ Events System.
Author: Paddy Srinivas
Date Submitted: March 7 2001
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.
Author: Amit Dey
Date Submitted: March 6 2001
COM Singletons: A Dangerous Animal By Richard Blewett.
Richard Blewitt simply explains the use of COM Singletons.
Author: Richard Blewett
Date Submitted: January 24 2001
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.
Author: Jan Verhoeven
Date Submitted: November 1 2000
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.
Author: A. Abdul Azeez
Date Submitted: November 1 2000
COM+ Basics - Creating your first COM+ Application By Martin Lapierre.
Author: Martin Lapierre
Date Submitted: June 1 2000
COM+ - the backbone of Windows DNA By Mahesh Bhide.
Author: Mahesh Bhide
Date Submitted: June 1 2000
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.
Author: Anthony Toivonen
Date Submitted: May 17th 2000
COM on Linux By Frank Rem.
A description of how to code a DCOM client for Linux without using Microsoft products.
Author: Frank Rem
Date Submitted: May 17th 2000
ATL Server By Richard Grimes.
A description of ATL Server.
Author: Richard Grimes
Date Submitted: May 9th 2000
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.
Author: Shivesh Viswanathan
Date Submitted: May 3rd 2000
How to use DDX with WTL By Girish Bharadwaj.
Author: Girish Bharadwaj
Date Submitted: March 27th 2000
COM Patterns By Tony Toivonen.
Author: Tony Toivonen
Date Submitted: March 27th 2000
COM+ Object Pooling By Jeremiah Talkar.
Author: Jeremiah Talkar
Date Submitted: March 23rd 2000
What are COM Pipes? By Richard Grimes.
Author: Richard Grimes
Date Submitted: March 23rd 2000
Java COM Integration - Use Visual J++ to implement COM Objects By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: March 9th 2000
Developing an MSMQ Server Application using VJ++ By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: March 9th 2000
Developing an MSMQ Client using VJ++ By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: March 9th 2000
What is Async COM? By Richard Grimes.
Author: Richard Grimes
Date Submitted: March 8th 2000
Coding a DCOM Server Component from IDL By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: February 10th 2000
Level of Difficulty: Advanced
Subjects Covered: IDL, DCOM, J++
Pre-required Reading: Component Object Model
Coding a DCOM Client By Gopalan Suresh Raj.
Author: Gopalan Suresh Raj
Date Submitted: February 10th 2000
Level of Difficulty: Advanced
Subjects Covered: IDL, DCOM, J++
Pre-required Reading: Component Object Model, Coding a DCOM Server Component from IDL
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.
Author: Brad Wilson
Date Submitted: Feb 04 2000
Level of Difficulty: Intermediate
Subjects Covered: Single Threaded Apartments, Multi Threaded Apartments, Apartments.
Pre-required Reading:
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.
Author: Richard Grimes
Date Submitted: Feb 02 2000
Level of Difficulty: Intermediate
Subjects Covered: WTL applications architecture, WTL UI update, OutputDebugString and debugging API
Pre-required Reading: assumes a knowledge of ATL and of Win32 application development (for example "Professional ATL COM Programming", Richard Grimes, Wrox Press)
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.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: None
Developing a Simple MTS Server Component By Gopalan Suresh Raj.
Part 1 of a two part example.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server
Developing a Simple MTS Client Application By Gopalan Suresh Raj.
Part 2 of a two part example.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server, Developing a Simple MTS Server Component
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.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server
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.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server, Developing The Bank Account IDL
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.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server, Developing The Bank Account IDL, MTS Server Component
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.
Author: Shivesh Viswanathan
Date Submitted: Jan 21 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: ATL
Pre-required Reading: None
Microsoft Transaction Server By Richard Grimes.
Introduces Microsoft Transaction Server
Author: Richard Grimes
Date Submitted: Dec 09 1999
Level of Difficulty: Beginners
Subjects Covered: MTS, VB
Pre-required Reading: None
What COM is all about By Richard Grimes.
An introductory article to COM, covering all basics including OLE, Activex and DLL's.
Level of difficulty: Beginner
Subjects Covered: COM
Pre-required reading: None
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.
Level of difficulty: Intermediate
Languages covered: COM
Pre-required reading: None
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.
|