![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Advanced Visual Basic Techniques
Trouble ShootingBuilding a remote automation server offers many opportunities to make mistakes. During the later steps in the process, it can be difficult to find and correct problems. The following list describes some of the most likely problems and suggests ways to correct them:
Using RegClassThe Visual Basic code for the client and server applications should not need to be changed between steps 2 and 3. The only difference between these steps is in how the client and server interact. These changes are made using the Remote Automation Connection Manager, the Automation Manager, and possibly the clients references list in the Visual Basic programming environment. The Client and Server subdirectories of the Ch11\Step3 directory on the compact disk contain the client and server applications. The server application is identical to the server used in step 2. The client application has been modified slightly to demonstrate one more feature of remote server programming. The RegClass class provides methods that a program can use to manipulate the system registry on a client computer. Before it can use this class, the client must include a reference to it. The RacReg entry should be selected in the projects References dialog. RegClass objects provide two public methods. The GetAutoServerSettings function returns information about a servers registration on the client computer. This function takes as a parameter the program ID of the server classfor example, TimeManager.TimeSetter. It returns a variant containing an array of four values holding the registration information. Table 11.1 describes the values contained in these four entries. The client application in the Ch11\Step3\Client directory calls the SetCaption subroutine. This routine uses GetAutoServerSettings to decide if the server is local or remote. If it is local, SetCaption sets the caption of the programs main form to Local. Otherwise, it sets the caption to the name of the remote server machine contained in the second value returned by GetAutoServerSettings.
Sub SetCaption()
Dim reg As New RegClass
Dim result As Variant
result = reg.GetAutoServerSettings(TimeManager.TimeSetter)
If Not (IsEmpty(result)) Then
If result(1) Then
Caption = result(2)
Else
Caption = Local
End If
End If
End Sub
RegClass also provides a public SetAutoServerSettings function. A program can use this function to specify local or remote service, the server computer, and the protocol that should be used for a particular server application. The SetLocalServer subroutine that follows prepares the system to use the local server for TimeManager.TimeSetter. The SetRemoteServer subroutine makes the system use a remote server on the indicated computer.
Private Sub SetLocalServer()
Dim reg As New RegClass
if reg.SetAutoServerSettings(False, _
TimeManager.TimeSetter) <> 0 _
Then
MsgBox Error making server local.
End If
End Sub
Private Sub PrepareRemoteServer(machine_name As String, _
server_name As String, protocol_name As String)
Dim reg As New RegClass
if reg.SetAutoServerSettings( _
True, server_name, , _
machine_name, protocol_name) <> 0 _
Then
MsgBox Error making server remote.
End If
End Sub
For instance, a program could use the PrepareRemoteServer subroutine like this: PrepareRemoteServer Beauty, TimeManager.TimeSetter, ncacn_nb_nb This statement indicates that the TimeManager.TimeSetter server should be served remotely by the computer Beauty using the protocol NetBIOS over NetBEUI. SummaryCreating and installing a client/server application is a complicated process, however implementing the application in three stages can make the process much simpler. First, test the server within the client application. Next, test the client and server in separate instances of Visual Basic running on the same computer. Finally, after the application code is thoroughly tested, install and test the server remotely.
|
||||||||||||||||||||||
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.
|