Microsoft KB Archive/137095

= How To Provide Constants from an ActiveX Component =

Article ID: 137095

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Control Creation Edition
 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q137095



SUMMARY
The use of constants is an efficient way to keep code clear, easier to document, and more understandable. When you create ActiveX components, it is more efficient to provide constants with the server in a ready-to-use form. This eliminates the need to declare constants in client (container) applications and makes it easier to call into server classes. This article describes two ways to implement constants with your ActiveX component.



MORE INFORMATION
Two ways to provide constants for use with an ActiveX component:

  Use the Property Get function to expose the constants as read-only properties. For example, if MY_CONSTANT is a constant set to the value 4, the following shows how to expose it to client applications: Public Property Get MY_CONSTANT As Integer MY_CONSTANT = 4 End Property   Create a Type Library using Object Description Language (ODL). MkTypLib is the tool used to process ODL source files; it produces a type library (.tlb file) and an optional C- or C++-style header file. The following is an example ODL script that you could use to provide an OLE server with the constant MY_CONSTANT: [        uuid(12345678-AAAA-BBBB-CCCC-000000000000), lcid (0x0000409), ,helpfile("myhelp.hlp") ,helpstring("More info for my server") ,version(1.0) ]

library MyServer {        [uuid(12345678-AAAA-BBBB-CCCC-111111111111),  \\unique guid helpstring("My Constants"), helpcontext(1011389), dllname(mydll)] module Constants { [helpstring("This is the value for MY_CONSTANT"), helpcontext(1012527)]

const short MY_CONSTANT = 4; } \\module }\\ library 

