![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Advanced Visual Basic Techniques
The initialization file entry should specify a value of either zero or one. The value one means new instances of the Visual Basic programming environment should automatically load the server into the Add-Ins menu when they start. Initially an add-in should set this value to zero. Visual Basic will change the value to one when the developer loads the add-in using the Add-In Manager. This will make the add-in automatically load the next time the developer starts the programming environment. The following lines show how the 32-bit version of the PropertySetter add-in is declared in the 32-bit section of the initialization file: [Add-Ins32] PropertySetter.PropSet=0 This entry could be created by editing the initialization file using a text editor. This would be rather cumbersome. Traditionally, an add-in provides a subroutine that creates the appropriate entries in the initialization file. In Visual Basic 4, an add-in project begins execution with the Main subroutine. The add-in can create its initialization file entry in the Main subroutine. Then the developer can make the add-in create its entry by running the application in the development environment. The following code uses the GetPrivateProfileString and WritePrivateProfileString API functions to create an entry for the PropertySetter add-in for the Visual Basic 4 development environment:
#If Win16 Then
Declare Function GetPrivateProfileString Lib Kernel _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Integer, ByVal lpFileName As String) _
As Integer
Declare Function WritePrivateProfileString Lib Kernel _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpString As Any, _
ByVal lplFileName As String) As Integer
#Else
Declare Function GetPrivateProfileString Lib Kernel32 _
Alias GetPrivateProfileStringA _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpDefault As String, _
ByVal lpReturnedString As String, ByVal nSize As Long, _
ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib Kernel32 _
Alias WritePrivateProfileStringA _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, ByVal lpString As Any, _
ByVal lpFileName As String) As Long
#End If
Sub Main()
Dim section As String
Dim val As String * 256
Dim length As Long
Check the correct section of VB.INI.
#If Win16 Then
section = Add-Ins16
#Else
section = Add-Ins32
#End If
See if PropertySetter.PropSet is already in VB.INI.
length = GetPrivateProfileString(section, _
PropertySetter.PropSet, , val, _
256, VB.INI)
If not, add it.
If length = 0 Then _
WritePrivateProfileString section, _
PropertySetter.PropSet , 0, _
VB.INI
End Sub
When an add-in application is run in the Visual Basic 5 development environment, the Main subroutine is not executed. The application, however, can still provide a subroutine to install the add-in. In this case, the developer will need to explicitly invoke the subroutine to create the necessary entry. The developer can do this by executing the subroutine in Visual Basics Immediate window. Creating the Server DLLOnce the appropriate entry has been added to the correct initialization file, the Add-In Manager knows what class objects it should use to connect and disconnect the server from the Add-Ins menu. Before an application can create an instance of a class defined by the server, the system registry needs to contain entries that describe the server in more detail. The registry entries also give the name that the Add-In Manager displays when the developer selects add-ins. This name may be different from the project name. The project name is used by the Add-In Manager to invoke the servers ConnectAddIn and DisconnectAddIn subroutines. If the projects name is MyProject and the class containing the ConnectAddIn subroutine is named Connector, then the Add-In Manager will invoke the subroutine MyProject.Connector.ConnectAddIn. The name placed in the registry tells the Add-In Manager what to display in its list of add-ins. Figure 4.6 shows the Add-In Manager. Here the PropertySetter add-in has the name Property Setter. Dealing directly with the system registry entries needed to set the add-ins name is quite complicated. Fortunately, Visual Basic handles this detail automatically. In Visual Basic 4, when the add-in designer invokes the Make OLE DLL File command from the File menu, Visual Basic creates the appropriate registry entries. Similarly, in Visual Basic 5, when the designer selects the Make PropSet.dll or Make PropSet.exe commands from the File menu, Visual Basic creates these entries. These commands are described further in a few paragraphs.
When Visual Basic makes these entries, it specifies the servers registry name using a value supplied by the Visual Basic programming environment. The add-in designer can set this value by entering the name the Add-In Manager should display in the Description box in the Member Options dialog shown in Figure 4.7. The way the Member Options dialog is accessed is different in Visual Basic 4 and Visual Basic 5. In either case, the add-in designer begins by opening the Object Browser by pressing F2 or by selecting the Object Browser command from the View menu. The designer then selects the class that contains the ConnectAddIn and DisconnectAddIn subroutines. Figure 4.8 shows the Visual Basic 4 Object Browser at this point. When the designer clicks the Object Browsers Options button, the Member Options dialog appears. When using the Visual Basic 5 Object Browser, the designer should locate the class that provides the ConnectAddIn and DisconnectAddIn subroutines and click the right mouse button over that class. This makes a context menu appear, as shown in Figure 4.9. If the designer selects the Properties command from this menu, the Member Options dialog appears. Once the add-ins name is specified, the designer can create the OLE server. In Visual Basic 4, this is done by selecting the Make OLE DLL File command from the File menu. In Visual Basic 5, the designer should select the Make PropSet.dll or Make PropSet.exe command from the File menu. After the designer enters the name of the file that should contain the results and clicks the OK button, Visual Basic creates the file. It also creates the system registry entries that identify the server and tell the Add-In Manager the servers name.
|
|
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.
|