HOWTO: Provide Constants from an ActiveX Component

ID: Q137095


The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 6.0
  • Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise Editions for Windows, version 5.0
  • Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0


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:

  1. 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 


  2. 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 



REFERENCES

MkTypLib comes with Win32 Software Development Kit (SDK) for Windows NT and Microsoft Visual C++ version 2.0 or later

For more information on Type Libraries and ODL, please see the Win32 SDK.

Additional query words: kbVBp400 kbVBp500 kbVBp600 kbVBp kbdsd kbDSupport KBSERVER KBACTIVEX KBDLL

Keywords : kbGrpVB
Version :
Platform : NT WINDOWS
Issue type : kbhowto


Last Reviewed: January 5, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.