How to Create Constants and DLL Declarations in a Type LibraryLast reviewed: May 20, 1996Article ID: Q143258 |
The information in this article applies to:
SUMMARYIt can be very useful to package constant definitions and DLL declarations in a type Library. Visual Basic 4.0 allows you to access type libraries and their contents. Once you have made a reference to the type library, you can view its information in Visual Basic's own Object Browser. Type Libraries are also superior in that you can also provide help strings along with the declarations to always let the user know what a definition is for.
MORE INFORMATIONTo create a type library, you need the command line programs UUID.EXE and MKTYPLIB.EXE. These programs are provided with Visual C++. Suppose we wanted to create a type library with three integer constants, a string constant, and one Windows API declaration. The following is the Object Description Language (ODL) code needed to produce the type library. Read through the ODL and there will be comments explaining what each section is and why we need them. [ //The Universal Unique identifier (UUID), needs to be generated by using //uuid.exe program. You then paste the value into the type library. uuid(006da100-110f-11cf-83b2-00aa0068851c), //The Help String is what comes up in the object browser as the second //piece of the library description in the "Libraries/Projects" combo box. helpstring("Constants TypeLib"), //The Locale Identifier (LCID) , identifies the language the type library //applies to. lcid(0x9), //This is just simply the version number of the type library. version(1.0) ] //This is the name of the type library. It is what comes up in the object //browser as the first piece of the library description in the //"Libraries/Projects" combo box. library MyLib { //Here is how we define numeric constants... typedef enum tagConst { mylibConst1, //Make the constant mylibconst1 equal to 0 mylibConst2=5, //Make the constant mylibconst2 equal to 5 mylibConst3=7 //Make the constant mylibconst3 equal to 7 }Constants; //For string constants we need to define them in a module //Modules also need to reference a dll name, in this case we don't need //to, so just give it a bogus name. [dllname("bogus")] module MoreConstants { //Define a constant mystr and assign it the value StringConstant. const LPSTR mystr="StringConstant"; }; //Now let's call a function located in the Windows API, specifically //User32.dll Now you see why we need a dllname here, this is where our //API function will come from. [dllname("user32.dll")] module APIDeclare { //Let's give the API function a descriptive help line, this will be //seen in the Object browser. Then we can declare the function //itself. //The entry attribute specifies the identifier for the entry //point into the dll //The in attribute specifies a parameter is a value going into the //function. //Note the following two lines need to be all on one line..[helpstring("Test API function Declaration"), entry("CloseWindow")] boolean CloseWindow([in] long Winhndl); };} To compile this code, copy it into a text file and call it test.odl. Next run the command line program MkTypLib like this.
mktyplib /nocpp test.odlThen you will see the message:
Successfully generated type library 'test.tlb'. To Use the Type Library from Visual Basic 4.0
REFERENCESOLE 2 Programmers Reference Volume 2
|
Additional reference words: 4.00 vb4all vb4win
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |