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
Printable View
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
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.
:)
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:
Save the file as SOMETHING.ODL and then compile it using one of the utilities mentioned above.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;
}
Example (from command prompt).
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.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.