To build a simple C++ DLL, use the _Export keyword or the #pragma export directive to export specific external functions and variables. Ensure that classes and class members are exported correctly, especially if they use templates.
For example, Figure 1 shows how to create a DLL executable module named triangle using the #pragma export directive. This example exports the functions getarea(), getperim(), the static member objectCount, and the constructor for class triangle.
class triangle
{
public:
static int objectCount;
getarea();
getperim();
triangle(void);
};
#pragma export(triangle::objectCount)
#pragma export(triangle::getarea())
#pragma export(triangle::getperim())
#pragma export(triangle::triangle(void))
Similarly, Figure 2 shows how to create a DLL executable module named triangle using the _Export keyword:
{
public:
static int _Export objectCount;
double _Export getarea();
double _Export getperim();
_Export triangle::triangle(void);
};
class triangle
{
public:
static int objectCount;
double getarea();
double getperim();
triangle(void);
};