jenniferw
asked on
exporting an enum from .dll
How do i export a enum from a .dll
My code:
typedef enum tagFunctionConst{
DRIVER_FUNCTION_INSTALL = 0X01,
DRIVER_FUNCTION_REMOVE = 0x02,
DRIVER_FUNCTION_START = 0x03,
DRIVER_FUNCTION_STOP = 0x04
};
extern "C" __declspec(dllexport) enum tagFunctionConst FunctionConst;
But when i run DUMPBIN/EXPORTS, i can't see the enum.
What am I doing wrong?
And, how do i access an enum with PInvoke?
My code:
typedef enum tagFunctionConst{
DRIVER_FUNCTION_INSTALL = 0X01,
DRIVER_FUNCTION_REMOVE = 0x02,
DRIVER_FUNCTION_START = 0x03,
DRIVER_FUNCTION_STOP = 0x04
};
extern "C" __declspec(dllexport) enum tagFunctionConst FunctionConst;
But when i run DUMPBIN/EXPORTS, i can't see the enum.
What am I doing wrong?
And, how do i access an enum with PInvoke?
An enum is a C/C++ specific construct which does not fit into the scheme of exporting data from a DLL. What you could however do is use an 'int' instead which can easily be exported and can serve the same purpose - and can be accessed from PInvoke using the usual means.
You can't.
An ENUM is a locally defined constant. It doesn't occupy storage unless you declare a variable and store the value of the ENUM into it.
Kent
>>It doesn't occupy storage unless you declare a variable
... which
enum tagFunctionConst FunctionConst;
in fact does.
... which
enum tagFunctionConst FunctionConst;
in fact does.
Yeah -- badly stated on my part. :(
int FunctionConst; // exportable.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
So correct code should be:
typedef enum tagFunctionConst{
DRIVER_FUNCTION_INSTALL = 0X01,
DRIVER_FUNCTION_REMOVE = 0x02,
DRIVER_FUNCTION_START = 0x03,
DRIVER_FUNCTION_STOP = 0x04
};
extern "C" __declspec(dllexport) int FunctionConst;
Should there be anything in the .cpp?
typedef enum tagFunctionConst{
DRIVER_FUNCTION_INSTALL = 0X01,
DRIVER_FUNCTION_REMOVE = 0x02,
DRIVER_FUNCTION_START = 0x03,
DRIVER_FUNCTION_STOP = 0x04
};
extern "C" __declspec(dllexport) int FunctionConst;
Should there be anything in the .cpp?