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 _Export or the #pragma export directive
to export specific functions and variables.
For example, to create a DLL executable module TRIANGLE, export the getarea() function, the getperim() function, the static member objectCount and the static constructor for class triangle using #pragma export:
Figure 1. Using #pragma export to create a DLL executable module TRIANGLEclass 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 _Export
keyword 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 _Export keyword.
- Apply the _Export keyword 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. This compiler option is described in z/OS XL C/C++ User's Guide, and #pragma export directives are described in detail in z/OS XL C/C++ Language Reference. If you use the EXPORTALL option, you do not need to include #pragma export or _Export in your code.