TypeLib Browser 2.05

TypeLib browser and code generator for PowerBASIC

 

Home
Photos
Links
SED Editor
TypeLib Browser
Data Access
COM
WebBrowser
WMI
MAPI
GDI+
DirectX
Scripting
VB6 ActiveX
Other ActiveX
Other Wrappers

The TypeLib Browser is a tool designed to let you to examine the contents of COM servers and ActiveX controls and to provide alternate ways to use them or to give workarounds to features still not available in the Power Basic compilers, such events sink.

Besides letting you to inspect all the information available in the typelibs, it generates wrapper functions that use direct VTable calls.

If the Ansi strings box is checked, the functions will include code to automatically convert string parameters to Unicode and returned string values to Ansi.

Checking the Check null pointers box the browser will add code to check if pthis is null and exit the function or procedure with an error code of %E_POINTER (&H80004003). This will protect you from GPFs caused by null pointers.

If the DLL code box is checked, the wrapper functions will be aliased and exported, and the declares will be also aliased and include the name of the DLL (the Prefix is used as the name; change it if needed with a find and replace operation in your editor).

If the Automation box is checked, information for dual interfaces will be shown in the treeview using the IDispatch interface view instead of the VTable view.

If the Add enum prefix box is checked, the name of the enumerations are added to the constants. This is useful to avoid conflicts between different enumerations having one or more members with the same name that other enumerations.

Double click the wanted typelib in the ListView to retrieve the information.

Click the Code button to generate the wrapper functions.

Please note that if the Use globals box is checked, the functions will use a global variable, <Prefix>_HRESULT, to store the result code and, if the DLL box is also checked, two additional functions —<Prefix>Error and <Prefix>Result— are generated. This option isn't intended for general use, but to make wrappers that can be tweaked to make them easier to use. The Proto declares and the CALL DWORD must remain unaltered, but the function header and the rest of the code can be modified.

If you have chosen to build a DLL, to use it you will need to generate the declares with the MenugCodegDeclares option and save them to a file.

If the component fires events, you can generate code for events sink with the MenugCodegEvents options. If there are more than one events interface, a dialog allows to select all of them or check the ones that you want. The generated class allows to sink events of multiple instances of the same control; they are differentiated by the cookie, which is the address of the address of the virtual table of the generated class and that is passed as pCookie to all the event functions. The pthis of the control is saved in the virtual table of the class and retrieved in each function. You can use it to call methods and properties of the control if you use prototypes or wrapper functions, or you can convert it to a dispatch variable using TB_MakeDispatchVariant (included in TB_COM32.INC) and use PB Automation. To advise and unadvise from events sink use the generated ConnectEvents/DisconnectEvents functions.

The events code uses HeapAlloc to allocate memory for the virtual table of the class and HeapFree to release it. When you call the <Prefix>_ConnectEvents function the reference counter is incremented and when you call the <Prefix>_DisconnectEvents it is decremented. If the reference counter is zero the memory is freed. To avoid memory leaks or GPFs, each call to ConnectEvents must be matched with a call to DisconnectEvents (using the cookie returned in the call to ConnectEvents). A good place to call the ConnectEvents function is the %WM_INITDIALOG (if you are using DDT) or %WM_CREATE (if you are using SDK) messages. To call the <Prefix>_DisconnectEvents, a good place is the %WM_DESTROY message. If you use this method, you can avoid the use of global variables storing the cookies in static variables in the main dialog callback (DDT) or main window procedure (SDK).

 

 

 

 

 

 

 

 

 

Other options

 

 

The Code menu contains the following options:

Enumerations: Generates a list of all the constants of all the enumerations.

Identifiers: Generates a list with all the ProgIDs, ClsIDs and IIDs.

Declares: Generates the appropriate declarations to use the wrapper functions.

Prototypes: Generates all the code you can need to call the methods and properties using direct VTable calls using CALL DWORD: ProgIDs, enumerations, types and unions, VTables and declaration templates.

Assuming that lpRecordset has a valid reference to an ADO recordset, you can call the methods and properties in three ways (the example uses the get_State property):

a) If you have dimed lpRecordset as Dword Ptr:


Call Dword @@lpRecordset[55] Using _

ADODBRecordset15_get_State(lpRecordset, plObjState) To hr
 

b) If you have dimed lpRecordset as ADODBConnectionVtbl Ptr:
 

Call Dword @@lpRecordset.get_State Using _

AdoRecordset15_get_State(lpRecordset, plObjState) To hr

c) If you have dimensioned lpRecordset as ADODBConnectionObject:
 

Call Dword @lpRecordset.@lpVtbl.get_State Using _

AdoRecordset15_get_State(lpRecordset, plObjState) To hr

VTables: Generates an structure (TYPE) for each interface containing all the methods and properties of it.

Modules: Modules can contain constants and declarations of external functions. This option generates a list of the constants, that you can copy and paste into your main code if needed. They aren't automatically added to the constants listings because in many cases they belong to external components or DLLs. It also generates declares for the functions.
 

Structures: Generates declarations for all the structures (if any) in the form TYPE/END TYPE.

 

Typedefs: Generates a list of all the typedefs (if any) in the form of macros.

 

PB-like interfaces: These interfaces are not intended to duplicate the functionality provided by the Power Basic COM Browser, but to allow to use components that it refuses because don't have a ProgID, such Accessibility (OLEACC.DLL), or can't be found in the registry, such TypeLib Information (TLBINF32.DLL).

 

DispiDs: Generates equates with the DispID values in the form of %DispID_<Interface name>_<method/property name>.

 

Offsets: Generates equates with the VTable offsets in the form of %VTO_<Prefix><Interface name>_<method/property name>. A list of the
offsets for the standard IUnknown, IDispatch, IEnumVARIANT, IFont and IPicture interfaces are included in the file TB_COM32.INC.


The Events menu includes the options JACOM events (Automation) and JACOM events (IUnknown). They generate callback functions suitable to be used with JACOMPB25. The diference among them is that the code generated for Automation uses dispatch variables and the other pointers.

 

 

Other notes

 

 

The MenugOpen option allows to load typelibs—or DLLs, OCXs or EXE  files containing a typelib—from disk. This is only useful when the  typelib is not registered.

The MenugSave as... allows to save the generated code to a file.

The MenugReload TypeLibs option refreshes the list of registered typelibs that appears in the ListView. This is only useful if you register a new component while working with the browser.

The file TB_COM32.INC contains some important wrapper functions, such TB_CreateObject, that lets you to create instances of any object passing his ProgID or ClsID; IUnknown_Release, that lets you to release any object or interface; TB_CreateControlLic, that lets you to create instances of licensed OCXs and attach them to a window, and AtlAxGetDispatch, that retrieves the dispatch interface of an OCX giving the handle of the window that hosts it. Also declarations for API functions to deal with variants and safearrays and a wrapper function called TB_CallByName that allows you to call any method or property giving his name and passing parameters as an array of variants.

The file TB_ENUM.INC contains the source code for a collection's enumerator and an example of how to use it.

 

 

Important notes

 

 

Some components, such Excel, have methods with more than 31 parameters, that together with the pthis parameter exceed the maximum of 32 parameters allowed by the PowerBasic compiler. These functions will need to use another technique, such calling DispCallFunc.

When using ATL and some OCXs, such the ones that come with Visual Studio 6, you must make sure that the %WM_DESTROY message is processed when the user closes the application clicking the T button. Use the following code (%WM_CLOSE always calls %WM_DESTROY).
 

CASE %WM_SYSCOMMAND
   ' Capture this message and send a %WM_CLOSE message
   ' or the program will remain in memory

   IF (wParam AND &HFFF0) = %SC_CLOSE THEN
      SendMessage hWnd, %WM_CLOSE, wParam, lParam
      EXIT FUNCTION
   END IF


Some parameters are marked as optional [opt], but when doing direct VTable calls you have to pass all the parameters. If the optional parameter is a Variant, you can't simply pass 0, "" or an EMPTY variant, either pass the correct value or use a variant filled with the value ERROR %DISP_E_PARAMNOTFOUND.

If the parameter is a variant and the value that it will contain is a dispatch interface, use the helper function TB_MakeDispatchVariant included in TB_COM32.INC to make a dispatch variable.

If the parameter is a variant that must contain a boolean value, use the helper function TB_MakeBoolVariant.

 

 

Disclaimer

 


This software and accompanying documentation are provided "as is" and without warranties as to performance or merchantability or any other warranties whether expressed or implied. Because of the various hardware and software environments into which this application may be used, no warranty of fitness for a particular purpose is offered. The user must assume the entire risk of using this software. In no case shall any of the contributors to this project be liable for any incidental, special or consequential damages or loss, including, without limitation, lost profits or the inability to use equipment or access data. This is true even if we are advised of the possibility of such damages. We also don't have any obligation of' fix eventual bugs or to add new features.

 

What is new in this version

 

  * Added a new option, "PwrDev Events". It generates events code suitable to be used with this the PwrDev visual designer.


  * The inherited interface is now shown instead of the implied interface.


  * Some components have help and documentation strings with embedded carriage returns. Added code to remove them in order of not to break the line.


  * Some components have spaces in the names of enumeration members! Added code to replace spaces with underscores.


  * Bug fix: In the TreeView mode, the variable used to store the default value was not cleared and some parameters were shown with wrong default values.


  * Changed "IF ISFALSE pthis..." To "IF pthis = 0..." because the direct comparison is faster.

 

 

Downloads

 

 

TLB_205.ZIP (262 Kb) (18 Jul 2006)

 

 

 

Home Photos Links SED Editor TypeLib Browser Data Access COM WebBrowser WMI MAPI GDI+ DirectX Scripting VB6 ActiveX Other ActiveX Other Wrappers

 

 

Page last updated on Saturday, 04 November 2006 00:15:31 +0100