Writing your C++ DLL code
To create a simple C++ DLL:
- Ensure that classes and class members are exported correctly, especially if they use templates.
- Use
_Exportor the#pragma exportdirective to export specific functions and variables.For example, to create a DLL executable module TRIANGLE, export the
getarea()function, thegetperim()function, the static memberobjectCountand the static constructor forclass triangleusing#pragma export:Figure 1. Using #pragma export to create a DLL executable module TRIANGLE class triangle : public area { public: static int objectCount; getarea(); getperim(); triangle::triangle(void); }; #pragma export(triangle::objectCount) #pragma export(triangle::getarea()) #pragma export(triangle::getperim()) #pragma export(triangle::triangle(void)) - Do not inline the function if you apply the
_Exportkeyword to the function declaration.Figure 2. Using _export to create DLL executable module TRIANGLE class triangle : public area { public: static int _Export objectCount; double _Export getarea(); double _Export getperim(); _Export triangle::triangle(void); }; - Always export static constructors and destructors when using the
_Exportkeyword. - Apply the
_Exportkeyword to a class. This keyword automatically exports static members and defined functions of that class, constructors, and destructors._class Export triangle { public: static int objectCount; double getarea(); double getperim(); triangle::triangle(void); }; - To export all external functions and variables in the compilation unit to the users of this DLL,
you can also use the compiler option
EXPORTALL. For more information about this compiler option, see EXPORTALL | NOEXPORTALL in z/OS XL C/C++ User's Guide. For more information about#pragma exportdirectives , see #pragma export in z/OS XL C/C++ Language Reference. If you use theEXPORTALLoption, you do not need to include#pragma exportor_Exportin your code.