HOWTO: Create Programs in Visual Basic That Use Remote OLE
ID: Q142534
|
The information in this article applies to:
-
Microsoft Visual Basic Enterprise Edition, 16-bit and 32-bit, for Windows, version 4.0
SUMMARY
This article describes the steps to create a new example program that uses
Remote OLE. The first example creates a client-server example illustrating
use of a 32-bit client and a 32-bit server application; the second example
is of a 16-bit client communicating with a 32-bit server application.
MORE INFORMATION
Both examples are very simple, because the purpose of this article is to
illustrate the most basic steps to get a Remote client and server working.
In this article, the 32-bit to 32-bit example involves creating the client
and the server applications on the client workstation, and then
distributing the server application onto the server machine. However, there
is no reason why the reverse process of creating the server and client
applications on the server machine, and then creating a setup for the
client could not also occur.
The 16-bit to 32-Bit example involves creating the 16-bit client and the 32-
bit server applications on the server machine, and then distributing the
client application to a workstation (clearly a 32-bit server cannot be
developed on a 16-bit operating system).
32-Bit Client to 32-Bit Remote Server Example
This example uses a 32-bit client and a 32-bit server. Both the client and
the server machines must be run on either Windows 95 or Windows NT 3.51
(that is, a 32-bit operating systems). In this example, the 'client'
workstation needs to have Visual Basic 4.0, 32-bit edition, installed. A
setup program is created for the server application.
STAGE 1 - CREATION OF THE SERVER APPLICATION
- On the client workstation, start a new project in Visual Basic 4.0, 32-
bit edition. Form1 is created by default. Insert a class module by
choosing Insert.Class Module from the menu. In the class module, type
the following code:
Public Sub Test()
Msgbox "Hi"
End Sub
Remove unnecessary controls from the project by choosing Tools.Custom
Controls from the menu, and clearing all the controls. Since no
controls have been added to the form, all check boxes in the Custom
Controls list box can be cleared. In addition, remove all unnecessary
references from the project. This can be accomplished by selecting
Tools.References and clearing all the entries except for "Visual Basic
For Applications," "Visual Basic objects and procedures," and "Standard
OLE Types." This will save time later on when in the distribution stage
for the server application.
- Press F4 to bring up the property window for the class. Set the
following properties:
Name: TestObj
Instancing: 2 - Creatable Multiuse
Public: True
- Choose Tools.Options from the menu, and choose the Project tab. Set the
following properties:
Project name: TestApp
Select the OLE Server radio button and then press the OK button to
accept the changes.
- Save the project files to a new directory. Now, choose File.Make EXE
from the menu. Make the EXE in the same directory as the VBP project
file. Name the EXE TestAapp.exe.
- Go to Tools.Options from the menu, choose the Project tab. Choose the
ellipsis (three dots) button contained in the right hand side of the
"Compatible OLE Server" box, and select TestApp.exe from the dialog box.
Although this step was not strictly necessary, it is useful because
after selecting the "Compatible OLE Server", Visual Basic will reuse the
ID for the server application, so that client applications that are
bound to that ID will not break if the server application needs to be
recompiled.
- Save the project file again.
STAGE 2 - REGISTER THE SERVER APPLICATION ON THE CLIENT WORKSTATION.
- Register the server locally by running TestApp.exe. Close down the
application by choosing Close from the System menu on the upper-left
corner of Form1. The action of running the server caused it to be
registered locally.
This step is important to ensure that the server application works, and
that it correctly registers.
STAGE 3 - CREATION OF THE CLIENT APPLICATION.
- Start a new project in Visual Basic, 32-bit edition. Form1 is created by
default. Go to the Click event for Form1 and place the following code:
Dim x as New TestApp.TestObj
x.Test
- Go to Tools.References in the menu, and check the entry for TestApp.
- Run the Client application in the Design environment. Click on the form
and the server application should be launched and a MsgBox should
appear.
- Stop the client application in the design environment and then close
down the server application by choosing Close from the System menu on
the still displayed Form1 of the server application.
- Save the client project files to a new directory. Choose Make EXE for
the client application - call it ClientApp.exe. Make the EXE file in
the same location as the VBP file.
- Exit Visual Basic and save the change to the Project file (the change
was the location and name of the executable).
STAGE 4 - TEST THE CLIENT APPLICATION LOCALLY.
- In Explorer in Windows 95, or File Manager in Windows NT 3.51, double-
click on ClientApp.EXE. Click the Form and it should again launch the
server and bring up a MsgBox of "Hi" if successful. Close down the
server and client completely.
STAGE 5 - INSTALLATION OF SERVER APPLICATION ON REMOTE MACHINE
- Choose the Visual Basic 4 32-bit Setup Wizard. Choose the TestApp.vbp
Project file in Step 1. Do not choose the Rebuild EXE option. Choose
the Next button. If Step 2 appears, simply choose the Next button.
- In Step 3 of Setup Wizard you can choose to install the application to
a new directory or to floppy disks. For Steps 4 and 5 simply choose the
Next button.
- In Step 6 of Setup Wizard choose the option to Install in Application
Directory and check the box labeled:
"Yes, install remote OLE automation server components"
Press Next on the Setup Wizard.
- In Step 7 press the Finish button to create the compressed files and
setup program.
- Go to the server machine, and run the setup program from the drive and
directory or floppy disks where Setup Wizard placed the compressed
server files and setup program.
At the completion of the setup program, assuming it completed
successfully, there should be icons for the RemAuto Connection Manager,
the Automation Manager, the server TestApp, and an icon to uninstall the
server application.
STAGE 6 - CONFIGURATION OF OLE SERVER APPLICATION
- The Setup program should have registered the server application. To
ensure it works correctly, run TestApp.exe and then close it down by
choosing Close from the System menu of Form1.
- Start the 32-bit Remote Automation (RemAuto) Connection Manager on the
server. Choose the Client Access tab (this is the only tab we are
concerned with when on the server machine; on the client machine, we
are only concerned with the Server Connection tab).
Highlight TestApp.TestObj and choose the "Allow all Remote Creates"
option, press the Apply button and exit the Remote Connection Manager.
- Start the Automation Manager.
STAGE 7 - CONFIGURATION OF CLIENT WORKSTATION
- Start the 32-bit Remote Connection Manager on the client machine. Go to
the Server Connection Tab.
- Highlight TestApp.TestObj. Fill in the details for network address,
protocol and Authentication. An example would be:
Machine: Machine2
Protocol: TCP/IP
Authentication: None
Choose the Remote menu item from the Register menu. Press the Apply
button and exit the RemAuto Connection Manager.
- Start the Client Application via Explorer or File Manager. Click Form1
of the client application and a Msgbox should appear on the Remote
machine. Click OK to close the message box and watch as the Automation
Manager returns to 0 connection(s) to 0 object(s) when the client-side
object reference is destroyed as the object variable goes out of scope.
Shut down the server and the client applications.
16-Bit Client to 32-Bit Remote Server Example
To follow through these steps, you will need Visual Basic 4.0 16-bit and 32-
bit editions installed on a workstation that is going to represent the
server machine. The server should be running either Windows 95 or Windows
NT 3.51. A setup program for the client application is created. The client
workstation can be running any operating system such as Windows 3.1,
Windows 3.11, Windows 95, or Windows NT 3.51.
STAGE 1 - CREATION OF THE SERVER APPLICATION
- On the server workstation, start a new project in Visual Basic 4, 32-
bit Edition.
- Insert a class module into the Project by choosing Insert.Class Module
from the menu and set the properties of the Class to the following:
Instancing: Creatable MultiUse
Name: RemObject
Public: True
Add the following code to the class module:
Public Sub MyMessage()
MsgBox "Hello there"
End Sub
- Go to Tools.Options from the menu and choose the Project tab. Set
"Project Name" = RemServer. Select the OLE Server radio button and
press the OK button.
- Choose File.Make EXE from the menu. Change the name of the program to
RemSer.exe. Before choosing OK, choose the Options button and check the
"Remote Server Support Files" check box. Now make the EXE file.
- Save the project files to the same location as the EXE file.
- Choose Tools.Options, and select the Project tab. Select the "Compatible
OLE Server" and select the EXE file "RemSer.exe". Choose OK, and then
save the project.
- Exit Visual Basic 4 32-bit edition, saving changes to the files. Go to
File Manager and run the server to ensure that it works.
STAGE 2 - CREATION OF THE CLIENT
- On the server workstation, start Visual Basic 4, 16-bit Edition. Start
a new project, and Form1 is created by default.
Remove unnecessary controls from the project by choosing Tools.Custom
Controls from the menu, and unchecking all the controls. Since no
controls have been added to the form, all check boxes in the Custom
Controls list box can be cleared. In addition, remove all unnecessary
references from the project. This can be accomplished by selecting
Tools.References and clearing all the entries except for "Visual Basic
For Applications," "Visual Basic objects and procedures," and "Standard
OLE Types." This will save time later on when in the distribution stage
for the server application.
- Choose Tools.. References from the menu. Check the entry for RemServer.
- Go to the Form_Click event for Form1, and place the following code:
Dim x As RemServer.RemObject
Set x = New RemServer.RemObject
x.MyMessage
- Save the project files and make an EXE into the same directory as the
project files for the client. From File Manager, run the client EXE on
the server machine, click on the form and it should launch the server
and bring up the message box. Shut down the client and server
applications.
STAGE 3 - CREATION OF THE CLIENT APPLICATION SETUP PROGRAM
- Run the 16-bit edition of the Setup Wizard. In Step 1 choose the VBP
file for the client application--do not select the Rebuild the Project
EXE option.
- Choose the Next button for Step 2, and in Step 3 choose to install into
a brand new directory. In Step4, choose the Add OLE Server button,
change the 'List Files of Type:' text box to show 'Remote OLE Servers'
instead of 'Local OLE Servers'. Locate the VBR file for the server
which should be in the directory where the server EXE was made. It asks
for details when you select the VBR file - type in the Network address
(the Machine name), and choose the protocol (TCP/IP recommended). Leave
Authentication at None. Choose OK and move on to the next step. Skip
through Step 5 by choosing the Next button, and in Step 6 leave the
default, which is "Install in Application Directory". Choose the Next
button and in Step 7 choose the Finish button.
- In File Manager, or Explorer, share the directory that contains the
server files.
STAGE 4 - SETUP OF THE CLIENT
- On the client connect to the shared directory on the server machine
containing the compressed files and the setup program, and run the
setup program to install the client application to the client machine.
STAGE 5 - TESTING IT OUT
- Start the Automation Manager on the server.
- Run the client and click on the client Form. You should get a Message
Box on the server. Close the message box and shut down both the client
and the server.
16-Bit Client to 16-Bit Remote Server
In order to construct a 16-bit to 16-bit example, exactly the same steps
used for the 16-bit client to 32-bit server example can be used, except
that Stage 1 - Creation of the Server (steps 1-7 inclusive) would take
place in Visual Basic 4.0, 16-bit Edition. It is imperative to stress that
the server must run on a 32-bit operating system (Windows 95 or Windows NT
3.51) because the Automation Manager must be running, and this program is
only available as a 32-bit application. In general, it is far preferable to
run a 32-bit server because of performance and reliability reasons.
Troubleshooting Remote OLE Problems
This article is useful for testing if Remote OLE is working at all - if
the steps to create a new Remote OLE example above have been faithfully
reproduced, and errors still occur, then it could indicate that there is
a network configuration or other software problem. For additional
troubleshooting information, please see the following article(s) in the
Microsoft Knowledge Base:
Q141824
: Common Remote OLE Automation Errors
Additional query words:
kbVBp400 kbDSupport kbdse kbVBp
Keywords : kbGrpVBDB
Version : WINDOWS:4.0
Platform : WINDOWS
Issue type :
|