How To Create Programs in Visual Basic That Use Remote OLE
This article was previously published under Q142534
This article has been archived. It is offered "as is" and will no longer be updated.
This article describes the steps to create a new example program that usesRemote OLE. The first example creates a client-server example illustratinguse of a 32-bit client and a 32-bit server application; the second exampleis of a 16-bit client communicating with a 32-bit server application.
Both examples are very simple, because the purpose of this article is toillustrate 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 clientand the server applications on the client workstation, and thendistributing the server application onto the server machine. However, thereis no reason why the reverse process of creating the server and clientapplications on the server machine, and then creating a setup for theclient 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 theclient application to a workstation (clearly a 32-bit server cannot bedeveloped on a 16-bit operating system).
32-Bit Client to 32-Bit Remote Server ExampleThis example uses a 32-bit client and a 32-bit server. Both the client andthe server machines must be run on either Windows 95, Windows 98, Windows 2000, or Windows NT 3.51 (or higher)(that is, a 32-bit operating systems). In this example, the 'client'workstation needs to have Visual Basic 4.0, 32-bit edition, installed. Asetup 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: 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.
Public Sub Test() Msgbox "Hi" End Sub
- 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: TestAppSelect 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, andthat 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, Windows NT 4.0, or Windows 2000, 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: NoneChoose 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 ExampleTo 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 theserver machine. The server should be running either Windows 95, Windows 98, Windows 2000, or Windows NT 3.51(or higher). A setup program for the client application is created. The clientworkstation can be running any operating system such as Windows 3.1,Windows 3.11, Windows 95, Windows 98, Windows 2000, or Windows NT 3.51. (or higher).
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: TrueAdd 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 ServerIn order to construct a 16-bit to 16-bit example, exactly the same stepsused for the 16-bit client to 32-bit server example can be used, exceptthat Stage 1 - Creation of the Server (steps 1-7 inclusive) would takeplace in Visual Basic 4.0, 16-bit Edition. It is imperative to stress thatthe server must run on a 32-bit operating system because the Automation Manager must be running, and this program isonly available as a 32-bit application. In general, it is far preferable torun a 32-bit server because of performance and reliability reasons.
Troubleshooting Remote OLE ProblemsThis article is useful for testing if Remote OLE is working at all - ifthe steps to create a new Remote OLE example above have been faithfullyreproduced, and errors still occur, then it could indicate that there isa network configuration or other software problem. For additionaltroubleshooting information, please see the following article(s) in theMicrosoft Knowledge Base:
141824 : Common Remote OLE Automation Errors
kbVBp400 kbDSupport kbdse kbVBp
Article ID: 142534 - Last Review: 01/10/2015 11:02:29 - Revision: 2.2
Microsoft Visual Basic 4.0 16-bit Enterprise Edition, Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
- kbnosurvey kbarchive kbhowto KB142534