typedef enum syntax changed in VS.Net C++ ATL? 
Author Message
 typedef enum syntax changed in VS.Net C++ ATL?

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

Quote:
} 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);

Quote:
};

// 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()

{

Quote:
}

DECLARE_PROTECT_FINAL_CONSTRUCT()

HRESULT FinalConstruct()

{

return S_OK;

Quote:
}

void FinalRelease()

{

Quote:
}

public:

STDMETHOD(get_hSession)(LONG* pVal);

STDMETHOD(get_Type)(FieldType* pVal);

Quote:
};



Tue, 03 Feb 2004 06:49:29 GMT  
 typedef enum syntax changed in VS.Net C++ ATL?
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
=====================================


Quote:
> 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);

> };



Tue, 03 Feb 2004 07:58:55 GMT  
 typedef enum syntax changed in VS.Net C++ ATL?
I appreciate your instruction on IDL typedef etiquette, however, whether I
use typedef to define a new enum type or just explicitly use enum <mytype>
doesn't help me with my problem. ;>)

The fact is I am using a typedef enum in a VC 6.0 ATL project and I'm able
to define a property that uses my type.  My VB app can use the type to set
values for the property.  Everything works fine.

Now I am trying to upgrade my VC 6.0 ATL project to VS.NET VC ATL project
and things have changed as far as the location of IDL definitions.  They now
go in the class header file (.h) for the interface instead of in the IDL
file (.idl).  So I've got a .h file that now has both the class definitions
for the class object and the IDL definitions.  This is causing a problem
with my enumeration type whether I use typedef enum or enum ...

If anyone has experienced this same problem with VS.NET ATL or knows of a
better way to specify enumerated types that are recognized in VB please let
me know.

Thanks,
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);

> > };



Tue, 03 Feb 2004 08:53:18 GMT  
 typedef enum syntax changed in VS.Net C++ ATL?
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);

> > };



Wed, 04 Feb 2004 00:55:10 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Using enum/ v1_enum in ATL Activex Control in VS .Net

2. Over 3,000 syntax errors from cstdlib and cstdio when porting to VS.Net C++

3. Changes in C# between VS.NET Beta and VS.NET Final versions

4. typedef vs enum

5. typedef enum as subset of another enum

6. Problem catching events from WMP 7.1 in ATL/C++ (VS.net)

7. VS.NET Enterprise Vs VS.NET Professional

8. C# .NET vs C++ .NET

9. enum/c++/ms visual C++.net

10. typedef struct not working under .NET C/C++ compiler

11. C# vs. C++ syntax

12. Visual C++ 6.0 vs. Visual C++ .NET

 

 
Powered by phpBB® Forum Software