Solved

Help with ATL project and adding an enum

Posted on 2003-11-21
3
453 Views
Last Modified: 2013-11-25
I'm using VC++ 7.0 (.net version) to create an atl project.
I'm trying to figure out how to add an enum to the code.  From the book i'm reading and the sites i've seen it says to add the enum
to the idl file.

typedef
[
      uuid(16CA3FE4-8326-4b07-B438-14590EF9D6F0),
      helpstring("Printer Tray Option")
]
enum printerTrayOption
{
      [helpstring("UpperTray")] UpperTray = 1,
      [helpstring("LowerTray")] LowerTray = 2
}printerTrayOption;

[
      object,
      uuid(30385867-A8AD-46D2-A47B-AA9D4A21EA6C),
      dual,
      helpstring("IPrinterInterface Interface"),
      pointer_default(unique)
]
#line 24 "c:\\projects\\reportmill.interfaces\\src\\interfaces\\printerinterface.h"
interface IPrinterInterface : IDispatch {
#line 27 "c:\\projects\\reportmill.interfaces\\src\\interfaces\\printerinterface.h"
      [id(1),helpstring("method QueryPrinters")] HRESULT  QueryPrinters([out,retval] VARIANT_BOOL *Result);
      [propget,id(2),helpstring("property QuerySize")] HRESULT  QuerySize([out,retval] SHORT *pVal);
      [propget,id(3),helpstring("property Printer")] HRESULT  Printer([out,retval] BSTR *pVal );
      [propput,id(3),helpstring("property Printer")] HRESULT  Printer([in] BSTR newVal);
      [propget,id(4),helpstring("property Size")] HRESULT  Size([out,retval] SHORT *pVal);
      [id(5),helpstring("method QueryPrinterList")] HRESULT  QueryPrinterList([in] SHORT ListIndex, [out,retval] VARIANT_BOOL *Result);
      [propget,id(6),helpstring("property PrinterTray")] HRESULT  PrinterTray([out,retval] enum printerTrayOption *pVal);
      [propput,id(6),helpstring("property PrinterTray")] HRESULT  PrinterTray([in] enum printerTrayOption newVal);
};


And the class printer interface also defines the  (.h):
..
__interface IPrinterInterface : IDispatch
{
..
      [propget, id(6), helpstring("property PrinterTray")] HRESULT PrinterTray([out, retval] printerTrayOption* pVal);
      [propput, id(6), helpstring("property PrinterTray")] HRESULT PrinterTray([in] printerTrayOption newVal);
};

class ATL_NO_VTABLE CPrinterInterface :
      public IPrinterInterface
{
..
public:
      STDMETHOD(get_PrinterTray)( printerTrayOption* pVal);
      STDMETHOD(put_PrinterTray)( printerTrayOption newVal);
};

in the class file:
..
STDMETHODIMP CPrinterInterface::get_PrinterTray(printerTrayOption* pVal)
{
      // TODO: Add your implementation code here

      return S_OK;
}

STDMETHODIMP CPrinterInterface::put_PrinterTray(printerTrayOption newVal)
{
      // TODO: Add your implementation code here

      return S_OK;
}


Now the book i'm reading doesn mention about putting the enum in the .h file just in the idl file.
So when i compile i get an error: error C2061: syntax error: identifier 'printerTrayOption'
which points to the 2 properties that is using the printerTrayOption enum.

So i though i would add the enum that i defined in the idl file into the .h also:
I added it just above the printer interface:
typedef
[
      uuid(16CA3FE4-8326-4b07-B438-14590EF9D6F0),
      helpstring("Printer Tray Option")
]
enum printerTrayOption
{
      [helpstring("UpperTray")] UpperTray = 1,
      [helpstring("LowerTray")] LowerTray = 2
}printerTrayOption;

// IPrinterInterface
[
      object,
      uuid("30385867-A8AD-46D2-A47B-AA9D4A21EA6C"),
      dual,      helpstring("IPrinterInterface Interface"),
      pointer_default(unique)
]
__interface IPrinterInterface : IDispatch
{

      [id(1), helpstring("method QueryPrinters")] HRESULT QueryPrinters([out, retval]VARIANT_BOOL* Result);
      [propget, id(2), helpstring("property QuerySize")] HRESULT QuerySize([out, retval] SHORT* pVal);
      [propget, id(3), helpstring("property Printer")] HRESULT Printer([out, retval] BSTR* pVal);
      [propput, id(3), helpstring("property Printer")] HRESULT Printer([in] BSTR newVal);
      [propget, id(4), helpstring("property Size")] HRESULT Size([out, retval] SHORT* pVal);
      [id(5), helpstring("method QueryPrinterList")] HRESULT QueryPrinterList([in] SHORT ListIndex, [out, retval]VARIANT_BOOL* Result);
      [propget, id(6), helpstring("property PrinterTray")] HRESULT PrinterTray([out, retval] printerTrayOption* pVal);
      [propput, id(6), helpstring("property PrinterTray")] HRESULT PrinterTray([in] printerTrayOption newVal);
};

Now the error i get is:
error C3303: 'uuid': attribute can only be used on 'coclasses, interfaces, classes, unions, enums, structs'
..

My understanding is that you dont need to add the enum to the .h file b/c when compiler sees it, it will update both
.h and .cpp file.  But its not doing it.

Now all i'm doing is building it so that may be the wrong way of trying to get the compiler to notice the idl file.

But in either case i'm stumped not sure what to do now.
Seems so easy but not quite sure.

0
Comment
Question by:netizen1
3 Comments
 

Author Comment

by:netizen1
ID: 9800570
Figured it out.  I was creating the enum code in the temp idl file.  I had to actually create the a new idl fi.e
0
 

Accepted Solution

by:
SpazMODic earned 0 total points
ID: 9820409
PAQed, with points refunded (70)

SpazMODic
EE Moderator
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sum28 challenge 31 112
Where to obtain Oracle Data Provider for .NET 3.5 7 53
Detect file exist or not 3 156
Work with App store 7 52
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question