Alexander,
I found the solution to my problem. After digging through the VS.Net
documentation I found the [export] directive which can be placed on the line
above the enum definition in the class header file. The export directive
causes the enum statement to be inserted into the generated idl file making
everyone happy.
Here's what it looks like.
[export]
typedef [helpstring("SessionStatus Enumeration")] enum SessionStatus {
cmInactiveSession = 0,
cmActiveSession = 1
Quote:
} SessionStatus;
// ICMSession
[
object,
uuid("44F0647C-BD90-463F-AC03-47B0B7EFE85D"),
oleautomation, helpstring("ICMSession Interface"),
pointer_default(unique)
]
__interface ICMSession : IUnknown
{
[propget, helpstring("property hSession")] HRESULT hSession([out, retval]
LONG* pVal);
[id(1), helpstring("method Logon")] HRESULT Logon([in] BSTR ServerName,
[in] BSTR UserID, [in] BSTR Password);
[id(2), helpstring("method Logoff")] HRESULT Logoff(void);
[propget, helpstring("property Status")] HRESULT Status([out, retval]
SessionStatus* pVal);
[propput, helpstring("property Status")] HRESULT Status([in] SessionStatus
newVal);
Quote:
};
And the resulting idl looks like...
typedef [
helpstring("SessionStatus Enumeration")
]
#line 7 "c:\\my programs\\vc7\\rcmx7\\rcmx7\\cmsession.h"
enum SessionStatus {
cmInactiveSession = 0,
cmActiveSession = 1,
Quote:
} SessionStatus;
[
object,
uuid(44F0647C-BD90-463F-AC03-47B0B7EFE85D),
oleautomation,
helpstring("ICMSession Interface"),
pointer_default(unique)
]
#line 19 "c:\\my programs\\vc7\\rcmx7\\rcmx7\\cmsession.h"
interface ICMSession : IUnknown {
#line 21 "c:\\my programs\\vc7\\rcmx7\\rcmx7\\cmsession.h"
[propget,helpstring("property hSession")] HRESULT hSession([out,retval]
LONG *pVal);
[id(1),helpstring("method Logon")] HRESULT Logon([in] BSTR ServerName,
[in] BSTR UserID, [in] BSTR Password);
[id(2),helpstring("method Logoff")] HRESULT Logoff();
[propget,helpstring("property Status")] HRESULT Status([out,retval] enum
SessionStatus *pVal);
[propput,helpstring("property Status")] HRESULT Status([in] enum
SessionStatus newVal);
Quote:
};
Before using the export directive the enum SessionStatus would not even show
up in the idl file which then generated the MIDL error.
Regards,
Gregg Walker
Quote:
> When writing in IDL, the only excuse to use a typedef is that you save
> typing "enum" when you reference the enum type. What excuse do you
> have to put it in a C++ source now? Try removing the typedef.
> --
> =====================================
> Alexander Nickolov
> Microsoft MVP [VC], MCSD
> MVP VC FAQ: http://www.mvps.org/vcfaq
> =====================================
> > Can someone help me with this? I have the following typedef setup in my
> VC6
> > idl file.
> > typedef [ helpstring("FieldType") ] enum FieldType {
> > [ helpstring("cmDate") ] cmDate = 0,
> > [ helpstring("cmDecimal") ] cmDecimal = 1,
> > [ helpstring("cmFString") ] cmFString = 2,
> > [ helpstring("cmLong") ] cmLong = 3,
> > [ helpstring("cmShort") ] cmShort = 4,
> > [ helpstring("cmTime") ] cmTime = 5,
> > [ helpstring("cmTimeStamp") ] cmTimeStamp = 6,
> > [ helpstring("cmVString") ] cmVString = 7
> > } FieldType;
> > This allows me to create a property of type FieldType and VB will show
> > allowable values in dropdown when assigning a value to the property.
> > In VS.Net C++ ATL project the IDL definitions no longer go directly in
the
> > idl file. They go into the class header file for the interface.
> > When I add this typedef to the VS.Net ATL project header file I get
syntax
> > errors on the helpstrings before each enum value. If I remove the
> > helpstrings then everthing compiles okay but I get the following error
> from
> > MIDL.
> > error MIDL2011 : unresolved type declaration : [ Parameter 'pVal' of
> > Procedure 'get_Type' ( Interface 'ICMSession' ) ]
> > Below is my class header file for the ICMSession interface. All the
code
> > was generated through wizards with the exception of the typedef.
> > Does anyone know how to setup typedef enum's in VS.Net ATL?
> > Thanks,
> > Gregg Walker
> > *The helpstrings have been removed from the typedef below.
> > // CMSession.h : Declaration of the CCMSession
> > #pragma once
> > #include "resource.h" // main symbols
> > typedef [ helpstring("FieldTypeEnum") ] enum FieldType {
> > cmDate = 0,
> > cmDecimal = 1,
> > cmFString = 2,
> > cmLong = 3,
> > cmShort = 4,
> > cmTime = 5,
> > cmTimeStamp = 6,
> > cmVString = 7
> > } FieldType;
> > // ICMSession
> > [
> > object,
> > uuid("F1B33E96-B8B0-47A6-B4BC-7378777459BD"),
> > oleautomation, helpstring("ICMSession Interface"),
> > pointer_default(unique)
> > ]
> > __interface ICMSession : IUnknown
> > {
> > [propget, helpstring("property hSession")] HRESULT hSession([out,
retval]
> > LONG* pVal);
> > [propget, helpstring("property Type")] HRESULT Type([out, retval]
> FieldType*
> > pVal);
> > };
> > // CCMSession
> > [
> > coclass,
> > threading("apartment"),
> > support_error_info("ICMSession"),
> > vi_progid("rcmx.CMSession"),
> > progid("rcmx.CMSession.1"),
> > version(1.0),
> > uuid("8CC80C65-8A82-42B6-ADED-2395CF51DDAF"),
> > helpstring("CMSession Class")
> > ]
> > class ATL_NO_VTABLE CCMSession :
> > public ICMSession
> > {
> > public:
> > CCMSession()
> > {
> > }
> > DECLARE_PROTECT_FINAL_CONSTRUCT()
> > HRESULT FinalConstruct()
> > {
> > return S_OK;
> > }
> > void FinalRelease()
> > {
> > }
> > public:
> > STDMETHOD(get_hSession)(LONG* pVal);
> > STDMETHOD(get_Type)(FieldType* pVal);
> > };