A client application uses the registry to find the information required to access your user object. The registry includes information about where to find the files for the PowerBuilder runtime environment and the libraries. It can also contain a pointer to a type library file that documents the properties and methods of the object. When the type library is registered, it lets the user examine the object in an OLE browser. (Instance variables of the object appear as properties in the OLE browser.)
PowerBuilder.Application provides facilities for generating the necessary registry information. To add your object to the registry, you need a registry update file, which contains information to be added to the system’s registration database. The type library is optional—you need it if you want others to be able to inspect your object’s properties and methods in an OLE browser.
To use these functions, you must run a client application that connects to PowerBuilder.Application. (You can run the client application in the development environment.)
Functions for generating registry information include:
GenerateGUID Gets a valid globally unique identifier to serve as the CLSID of your object and its type library
GenerateRegFile Uses the properties of PowerBuilder.Application and other values to generate a registry update file that the Registry Editor (REGEDT32.EXE) can use
GenerateTypeLib Uses the information in the object to generate a type library and updates the registry file with information about the type library
You can use these functions yourself, as shown in the example below, or you can use an installation application that provides tools for creating registry information, such as InstallShield.
Deploying and the registry The registry file that you create on your computer can be used to register your object on your own computer. The path information for files (the object library and the type library) is specific to your machine and is probably not applicable to other machines. To deploy your object, you need to modify the registry update files according to the directories the user specifies for installation, or call functions for modifying the registry itself.
See “Deploying an application that uses the automation server”.
This script takes information from several SingleLineEdit controls and a CheckBox and builds a registry update file and a type library. The script hard-codes version information, but you can use edit boxes to obtain version information too.
The SingleLineEdits and CheckBox used in the following example are shown in Table 20-6.
Object for input |
Data provided |
---|---|
sle_object |
The name of the object in the PowerBuilder library |
sle_progid |
A programmatic identifier you supply |
sle_desc |
A description of your object, which is displayed in the registry |
sle_regfile |
The name of the registry update file you want to generate |
sle_typelibfile |
The name of the type library file you want to generate |
sle_library |
The name of the PowerBuilder library containing the object |
cbx_machinecode |
Whether the library uses compiled code or Pcode |
This program generates a registry update file and type library.
oleObject ole_pb
string ls_reg_guid, ls_tlb_guid
long ll_result, ll_res2
// Connect to the PowerBuilder.Application server
ole_pb = CREATE oleObject
ll_result = ole_pb.ConnectToNewObject &
("PowerBuilder.Application")
IF ll_result < 0 THEN
MessageBox( "Can't Connect", &
"Error connection to PowerBuilder.Application")
RETURN
END IF
// Set properties for the server session, which
// will become the values for the registered object
ole_pb.LibraryList = sle_library.Text
ole_pb.MachineCode = cbx_machinecode.Checked
// Get GUIDs for the object and type library
ll_result = ole_pb.GenerateGUID( REF ls_reg_guid)
ll_res2 = ole_pb.GenerateGUID( REF ls_tlb_guid)
IF ll_result < 0 THEN
MessageBox( "Can't Get GUID", &
"Generating GUID for Reg file failed.")
RETURN
ELSEIF ll_res2 < 0 THEN
MessageBox( "Can't Get GUID", &
"Generating GUID for TypeLib file failed.")
RETURN
END IF
// Use info from user to generate registry update file
// Arguments for GenerateRegFile:
// valid GUID
// Name of uo in PB library
// ProgID as in registry
// Major version, Minor version
// Description
// Name of reg file
ll_result = ole_pb.GenerateRegFile( &
ls_reg_guid, &
sle_object.Text, &
sle_progid.Text, &
1, 0, &
sle_desc.Text, &
sle_RegFile.Text )
IF ll_result < 0 THEN
MessageBox("Can't generate RegFile", &
"result code is " + String(ll_result) )
RETURN
END IF
// Use information that matches the registry update
// file to generate the type library
// Arguments for GenerateTypeLib:
//
// GUID in Reg file
// Name of uo in PB library
// Prog ID as in Reg file
// Locale, Major version, Minor version
// Description
// Help context, Help file
// GUID for TypeLib
// Name of typelib file
// Name of reg file
ll_result = ole_pb.GenerateTypeLib( &
ls_reg_guid, &
sle_object.Text, &
sle_progid.Text, &
0, 1, 0, &
sle_desc.Text, &
0, "", &
ls_tlb_guid, &
sle_typelibfile.text, &
sle_regfile.text)
IF ll_result < 0 THEN
MessageBox("Can't generate TypeLib File", &
"result code is " + String(ll_result) )
RETURN
END IF