Link to home
Start Free TrialLog in
Avatar of jenniferw
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?
Avatar of jkr
jkr
Flag of Germany image

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.

Yeah -- badly stated on my part.  :(

  int FunctionConst;    // exportable.
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jenniferw
jenniferw

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?