HOWTO: Provide Constants from an ActiveX Component

Last reviewed: July 3, 1997
Article ID: Q137095
The information in this article applies to:
  • 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 OLE client (container) applications and makes it easier to call into server classes. This article describes two ways to implement this.

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


Keywords : IAPOLE kbcode vb432 vb4win vb5all vb5howto kbhowto
Technology : kbole
Version : 4.0 5.0
Platform : NT WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 3, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.