DCOM using Visual Basic |
|
DS420, Fall 1998, Dr. Clark Elliott, Depaul University | |
Project: Bangalore, Student: Suresh Sreerama | |
Exam Questions | The visual basic code |
As part of exploring the capabilities offered by Visual Basic for developing DCOM applications, I have implemented the class DCOM assignment in Visual Basic (VB). This document attempts to document the steps followed and the things that happen behind the scenes in VB. |
Operating System | Windows NT 4.0 Server, Service Pack 3.0 |
Hardware | Intel Dual Pentium P200, 128MB RAM |
Language/Tools | Microsoft Visual Basic 6.0 |
Browser | Internet Explorer 4.72.xx |
The three parts of the class DCOM Assignment TheServer,
ThePusher, TheControl have been implemented in VB. Currently the implementation
has been tested on a single machine (across processes). In terms of COM/DCOM development, Visual Basic looks like a good tool for prototyping COM/DCOM designs and seems more ideal for rapidly developing windows graphical controls. |
1. Microsoft's COM site |
2. Visual Basic Books Online |
3. Inside COM - Dale Rogerson |
4. HardCode Visual Basic - Bruce McKinney |
5. DS 420, Fall DCOM Assignment, Dr. Clark Elliott's Class Notes/Handouts |
The sole purpose of the TheServer in life is to track a single long value. TheServer is a DCOM server (created via File->New Project->ActiveX EXE) that supports the following interfaces: |
IDataServer
- UpdateData()
The UpdateData() is invoked by external applications (for ex. ThePusher) that change the value, that is served by the Data Server. IConnectionMgr
- Connect()
- Disconnect()
This interface has two methods Connect() and Disconnect(), which can be called by the consumer DCOM applications or Controls (TheControl). As the names suggest, the Connect() and Disconnect() methods serve to establish and terminate a connection with the Server IDataConsumer
- OnDataChange
This is an Interface that must be implemented by the consumer DCOM applications or Controls that intend to consume the data served by the TheServer
The Class TheServerComObject (TheServerComObject.cls) implements the interfaces IDataServer and IConnectionMgr.
Declaring Interfaces in VB
To create an interface in VB, you simply create a class module (vis Project->Add Class Module) with empty methods and properties. For example, the IDataServer interface is declared as follows: Function UpdateData(lValue As Long) As Long
End Function
Implementing an Interface in VB
In the class that you chose to implement an interface, just type Implements <my interface name> and Visual Basic updates the Code Window with an entry for the interface. For example, the TheServerComObject has the following two implement statements: Implements IDataServer
Implements IConnectionMgr
Debugging
I did not use any sophisticated debugging aids other than the MsgBox() API. There is an option in the project properties to make the DCOM server run in Unattended Execution mode. When the DCOM server is set to run in the unattended mode the MsgBox() API (which throws up a dialog box) has no effect. Therefore, the calls to MsgBox() API have been left intact for future debugging.
ThePusher is a regular VB Windows application. (Select File->New
Project->Standard Exe) Upon Startup (In the Form_Load Event) the ThePusher application creates an instance of the IDataServer Interface by calling the VB operator New() API (Use could also use the CreateObject() API). The Pusher application sports a edit box and a button that invokes a method UpdateData(lNewValue) in the IDataServer interface supported by the DataServerApplication. The following brief list of operations/funtions performed by the VB Pusher applicaton and the corresponding ones that were used in the C/C++ DCOM assignment:
|
TheControl is an ActiveX control (created via File->New
Project->ActiveX DLL). This control implements the IDataConsumer
interface and makes use of the IConnectionMgr interface implemented by TheServer.
The IConnectionMgr implementation mimics the behaviour of the IConnectionPoint
interface that the class implemented in the C++ version of the TheServer. TheControl
(in response to the Connect to Server button) passes an instance of itself to the
TheServer (via Connect(....) method. Whenever the value in the Pusher application is changed the new value is reflected in the ActiveX control hosted by IE 4.0. The control looks in IE 4.0 as shown below: |