netizen1
asked on
Help with ATL project and adding an enum
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-B4 38-14590EF 9D6F0),
helpstring("Printer Tray Option")
]
enum printerTrayOption
{
[helpstring("UpperTray")] UpperTray = 1,
[helpstring("LowerTray")] LowerTray = 2
}printerTrayOption;
[
object,
uuid(30385867-A8AD-46D2-A4 7B-AA9D4A2 1EA6C),
dual,
helpstring("IPrinterInterf ace Interface"),
pointer_default(unique)
]
#line 24 "c:\\projects\\reportmill. interfaces \\src\\int erfaces\\p rinterinte rface.h"
interface IPrinterInterface : IDispatch {
#line 27 "c:\\projects\\reportmill. interfaces \\src\\int erfaces\\p rinterinte rface.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_Pri nterTray(p rinterTray Option* pVal)
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CPrinterInterface::put_Pri nterTray(p rinterTray Option 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-B4 38-14590EF 9D6F0),
helpstring("Printer Tray Option")
]
enum printerTrayOption
{
[helpstring("UpperTray")] UpperTray = 1,
[helpstring("LowerTray")] LowerTray = 2
}printerTrayOption;
// IPrinterInterface
[
object,
uuid("30385867-A8AD-46D2-A 47B-AA9D4A 21EA6C"),
dual, helpstring("IPrinterInterf ace 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.
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-B4
helpstring("Printer Tray Option")
]
enum printerTrayOption
{
[helpstring("UpperTray")] UpperTray = 1,
[helpstring("LowerTray")] LowerTray = 2
}printerTrayOption;
[
object,
uuid(30385867-A8AD-46D2-A4
dual,
helpstring("IPrinterInterf
pointer_default(unique)
]
#line 24 "c:\\projects\\reportmill.
interface IPrinterInterface : IDispatch {
#line 27 "c:\\projects\\reportmill.
[id(1),helpstring("method QueryPrinters")] HRESULT QueryPrinters([out,retval]
[propget,id(2),helpstring(
[propget,id(3),helpstring(
[propput,id(3),helpstring(
[propget,id(4),helpstring(
[id(5),helpstring("method QueryPrinterList")] HRESULT QueryPrinterList([in] SHORT ListIndex, [out,retval] VARIANT_BOOL *Result);
[propget,id(6),helpstring(
[propput,id(6),helpstring(
};
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)
STDMETHOD(put_PrinterTray)
};
in the class file:
..
STDMETHODIMP CPrinterInterface::get_Pri
{
// TODO: Add your implementation code here
return S_OK;
}
STDMETHODIMP CPrinterInterface::put_Pri
{
// 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-B4
helpstring("Printer Tray Option")
]
enum printerTrayOption
{
[helpstring("UpperTray")] UpperTray = 1,
[helpstring("LowerTray")] LowerTray = 2
}printerTrayOption;
// IPrinterInterface
[
object,
uuid("30385867-A8AD-46D2-A
dual, helpstring("IPrinterInterf
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER