21. How do I set up a remote automation server and client?
The following is a step by step tutorial on setting up a remote
automation server and client.
I will be using the two sample programs helo_svr (server) and helo_cli
(client) located in samples\remauto\hello of the VB subdirectory. The
process described here will be a manual set up for illustrative
purposes. The Setup Wizard automates this process when you create
distribution disks.
- Load the OLE server, helo_svr project and select File-Make EXE to
compile the program. On the File-Save dialog, click the Option button
and make sure the Remote Server Support Files check box is checked.
This will be needed by the client. Compile the program.
- Install the program on the server machine along with the Remote
Automation Manager. If you are using the Setup Wizard, be sure the
'Install Remote OLE Automation...' check box is checked so that the
needed files are included. If you are running the server on the
development machine, then setup is not necessary for this
demonstration.
- On the server machine, run the RemAuto Connection Manager. In the
left pane select the entry HelloProj.HelloClass. Select the Server
Connection tab and enter the appropriate information in the Network
Address, Network Protocol and Authentication Level fields. The
settings I used were:
- Network Address: \\rclar9 (machine name).
- Network Protocol: Named Pipes.
- Authentication Level: Default.
Click the Client Access tab and select 'Allow All Remote Creates'. In
an actual deployment, this will need to be whatever is required by the
business.
On the Server Connection tab, click the Apply button to set up the
server. Run the OLE server and the Automation Manager on the server
machine. The OLE server is now ready.
- Compile the client project, helo_cli.
- Install the client on the client machine. If you are using the
Setup Wizard, on step 4 click the 'Add OLE servers' button and then
select the helo_svr.vbr file you created when you compiled the server.
An additional dialog will be displayed. Fill out the appropriate
information that you entered when you set up the server, and continue.
- Setup Wizard will register the client on the target machine (if
you used Setup Wizard) but I will go over the process to illustrate
the necessary steps. You will need the helo_svr.vbr and helo_svr.tlb
files that were created when you compiled the server. On the client
machine, run the CLIREG16 (16 bit) or CLIREG32 (32 bit), which ever is
appropriate, passing the proper parameters. These programs are in
\clisvr of the VB subdirectory.
Page 137 of the 'Building Client/Server Applications with Visual
Basic' lists the all the parameters of the registration utility. I
found that I needed to pass both the TLB and VBR file in order for the
client to work properly. Page 135 in the same manual, lists the
network protocols and the representative clireg string. If you dont
specify the server or protocol, the clireg program will prompt you for
the information.
- Run the helo_cli program. On the server machine the Automation
manager will indicate 1 connection to 1 object.
Note: I ran this process successfully on one machine, in addition to
two separate machine. Obviously, remote means more than one machine,
but the concepts still work even if you only have one machine
available. You can verify that the system is indeed using the remote
automation tools by closing the Automation Manager and running the
client program. You should get a 'No more endpoints available...'
error.
The difficulty with this process, I found, is the network protocols.
You have to be sure that you specify the correct information or the
client will not be able to find the server. Also, be sure that the
OLE server is running, or you will get an 'OLE Automation server
cannot create object' error.
22. Should I set properties on a remote OLE server or pass
parameters?
It is always faster to pass parameters than it is to set individual
properties. Use optional parameters and set the necessary properties
in the beginning of the code module. This will reduce the number of
calls needed to server and improve performance, at the cost of some
additional code in the module.
23. What is the difference in using ByRef and ByVal calls to a remote
OLE server?
Using a ByRef actually passes a data pointer to a Function/Sub, so it
is much faster for in-process subroutines. It is slower though, on
remote servers, since the data must be copied twice. Since a pointer
cannot span across machines, OLE must copy the value to the target
machine, and then copy the value back to client, since it has no way
to know if the data was changed.
Using ByVal though, the data is copied once to the server, as in a
normal Function/Sub call. This reduces the cross-network calls, and
improves performance.
Sources Used in this FAQ:
- OLE Remote Automation: Synopsis and Analysis. The Cushing Group.
Copyright 1995, The Cushing Group. http://www.cushing.com/.
- Creating OLE Servers with Microsoft Visual Basic. Craig Lokken,
Mary Anne Kobylka, Microsoft Corporation. Copyright 1995, Microsoft
Corporation. http://www.microsoft.com/
- Building Client/Server Applications with Visual Basic. Microsoft
Corporation. Copyright 1995, Microsoft Corporation.
- Professional Features, Creating OLE Servers. Microsoft
Corporation. Copyright 1995, Microsoft Corporation.
- Visual Basic Help File. Microsoft Corporation. Copyright
1991-1995, Microsoft Corporation.
- Microsoft Knowledge Base. Microsoft Corporation. Copyright 1995,
Microsoft Corporation.
More information can be found at:
http://www.microsoft.com/vbasic/vbfeatur/remauto/REMAUTO.HTM
http://www.microsoft.com/vbasic/
Please contact Richard Clark (clarkr@flash.net) for
additions or errors in this document. The document is provided as is, and is used at the
risk of the reader.