Hi there, I'm trying to build a dll with C++ and I followed this tutorial: http://msdn.microsoft.com/en-us/library/ms235636(v=vs.100).aspx In the article it says, "By default, MATHFUNCSDLL_EXPORTS is defined when your MathFuncsDll project is built." I wrote this trial code: (trialDLL.h)
#ifndef TRIALDLL_H_ #define TRIALDLL_H_ class MyMathFuncs { private: double offset; double getOffset(); public: MyMathFuncs(double offset); double Add(double a, double b); double Multiply(double a, double b); }; #ifdef __cplusplus extern "C"{ #endif #ifdef TRIALDLL_EXPORT #define TRIALDLL_API __declspec(dllexport) #else #define TRIALDLL_API __declspec(dllimport) #endif MyMathFuncs* __stdcall TRIALDLL_API new_MyMathFuncs(double offset); double __stdcall TRIALDLL_API MyAdd(MyMathFuncs* myMath, double a, double b); #ifdef __cplusplus } #endif #endif
And its corresponding definition .cpp file. But when I build it, using visual studio 2010 ultimate, building failed and gives error: trialdll.h(29): error C2059: syntax error : '__declspec(dllimport)' and (the same problem) error C2059: syntax error : '__declspec(dllimport)'. I wonder why is this? If the statement from the tutorial is true, TRIALDLL_API should have been defined as __declspec(dllexport) in the macro rather than __declspec(dllimport). If the statement is false, can I ask for a solution, possibly how to build it on command line?
Thanks a lot to whomever replies and helps.