Results 1 to 3 of 3

Thread: Decalring Public Enums...

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Decalring Public Enums...

    OK, I have 2 DLLs I want the same Enums in both...Should I just add a private class and just add all my enums publicly in there.
    God knows why you can't define them in a module?

    Woka

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    In short, yes. Unless you want to repeat the definitions of the enums, you'll just have to create a class module and reference it from both projects.

    And the reason you can't define them in a standard module, then use them outside of the project, is because standard modules don't really have Public scope from the OO standpoint. They have more like Friend scope. Global to the project, but not recognized from anywhere else.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Addicted Member
    Join Date
    Mar 2003
    Location
    Minneapolis, MN
    Posts
    151
    Another alternative is to place the declaration of the Enum within a Type Library.

    The pre-requisites of this approach are that you will need a utility like MKTYPLIB.EXE or MIDL.EXE that will be used to compile the TLB file from an ODL file. You will also need to generate a GUID, like GUIDGEN.EXE.

    Then create an ASCII text file that contains the ODL syntax.

    Example:
    Code:
    //The UUID is the GUID.  The one below is just an example.
    //The HELPSTRING is the description that shows up in the References dialog box in VB
    //The LCID specifies the Local ID
    //    NOTE: 0x00000000 indicates that the type library is not locale specific.
    //The VERSION is the version of the type library.
    [
    uuid(00000000-0000-0000-0000-000000000000),
    helpstring("This Is My Type Library"),
    lcid(0x00000000),
    version(1.0)
    ]
    
    library MyTypLib {
    
        // My enumerator
    
        // Each HELPSTRING below will show up in the Object Browser
    
        typedef
            [ helpstring("This enumerator is for the purpose of _.") ]
        enum {
            [ helpstring("This element of the enum is for the purpose of _.") ]
            Element1 = 0,
            [ helpstring("This element of the enum is for the purpose of _.") ]
            Element2 = 1,
            [ helpstring("This element of the enum is for the purpose of _.") ]
            Element3 = 2
        } MyEnum;
    
    }
    Save the file as SOMETHING.ODL and then compile it using one of the utilities mentioned above.

    Example (from command prompt).
    Code:
    C:\Path\To\MkTypLib\mktyplib.exe /nocpp /nologo /o MakeLib.log /tlb C:\WINDOWS\SYSTEM32\MYTYPLIB.tlb SOMETHING.ODL
    
    // /nocpp indicates that the C Pre-Processor will not be used.
    // /nologo indicates that MKTYPLIB will not display is name and version in the command prompt when ran.
    // /o indicates the Log file that will be used to record either success or an error message.
    // /tlb specifies the path and filename of the TLB to be generated.
    You can then add a reference to the type library to any project. The first time you add a reference to it, you will need to "browse" to select the library. After that, it should just appear as a selectable entry in you list of references.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width