Article ID: 143258
Article Last Modified on 7/1/2004
[
// The Universal Unique identifier (UUID), needs to be generated by
// using uuid.exe program. Then, you paste the value into the type
// library.
uuid(006da100-110f-11cf-83b2-00aa0068851c),
// The Help String 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 the version number of the type library.
version(1.0)
]
// This is the name of the type library. It comes up in the object
// browser as the first piece of the library description in the
// "Libraries/Projects" combo box.
library MyLib
{
// 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;
// You need to define string constants in a module.
// Modules also need to reference a dll name. In this case you 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 call a function located in the Windows API, specifically
// User32.dll. Now you see why you need a dll name here, this is
// where the API function will come from.
[dllname("user32.dll")]
module APIDeclare
{
// Give the API function a descriptive help line, this will
// be seen in the Object browser. Then, you can declare the
// function. The entry attribute specifies the identifier for the
// entry point into the dll.
// The in attribute specifies a parameter as a value going into
// the function.
//Note that the following two lines need to be all on one line.
[helpstring("Test API function Declaration"), entry("CloseWindow")]_
boolean
CloseWindow([in] long Winhndl);
};
}
mktyplib /nocpp test.odl
Successfully generated type library 'test.tlb'.
Private Sub Command1_Click()
Dim x As Boolean
'Call the Windows API function CloseWindow without making one
'declare at all. Note that the CloseWindow API will close the current
'window.
x = CloseWindow(Me.hWnd)
'Now print out the value of the constants in the type library
'using message boxes.
MsgBox mylibConst1
MsgBox mylibConst2
MsgBox mylibConst3
MsgBox mystr
End Sub
Keywords: kbhowto KB143258