File mathfuncs.cpp
#include "precompiledheaderspec.h" // stdafx.h or whatever...
#define MATHFUNCS_EXPORTS // (must be before all non-pch includes)
#include "mathfuncs.h"
#include "anything else you need..."
namespace MathFuncs
{
static double MyMathFuncs::Add(double a, double b) { ... }
static double MyMathFuncs::Substract(double a, double b) { ... }
static double MyMathFuncs::Multiplty(double a, double b) { ... }
static double MyMathFuncs::Divide(double a, double b) { ... }
}
File mathfuncs.h
#ifdef MATHFUNCSDLL_EXPORTS
#define MATHFUNCSDLL_API __declspec(dllexport)
#else
#define MATHFUNCSDLL_API // (don't define anything) __declspec(dllimport)
#endif
namespace MathFuncs
{
class MATHFUNCSDLL_API MyMathFuncs
{
public:
static MATHFUNCSDLL_API double Add(double a, double b);
static MATHFUNCSDLL_API double Substract(double a, double b);
static MATHFUNCSDLL_API double Multiplty(double a, double b);
static MATHFUNCSDLL_API double Divide(double a, double b);
};
}
Note the following:
- Add MATHFUNCSDLL_API to the class definition
- The MATHFUNCSDLL_API stuff should only be in the .h file (don't repeat in the .cpp file)
- remove the __declspec(dllimport) from the conditional define