title: c++: definition of dllimport function not allowed, building with visual studio 2010
body: <p>I'm using visual studio 2010 to build a .dll. I wrote up a trial as:  </p>
  
  <pre><code>// trialDLL.h
  #ifndef TRIALDLL_H_
  #define TRIALDLL_H_
  
  // ... MyMathFuncs class definition omitted
  
  #ifdef __cplusplus
  extern "C"{
  #endif
  
  #ifdef TRIALDLL_EXPORT
  #define TRIALDLL_API __declspec(dllexport)
  #else
  #define TRIALDLL_API __declspec(dllimport)
  #endif
  
  TRIALDLL_API MyMathFuncs* __stdcall new_MyMathFuncs(double offset);
  TRIALDLL_API void __stdcall del_MyMathFuncs(MyMathFuncs *myMath);
  TRIALDLL_API double __stdcall MyAdd(MyMathFuncs* myMath, double a, double b);
  // some other similar stuff
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif
  </code></pre>
  
  <p>And the triallDLL.cpp file:  </p>
  
  <pre><code>// trialDLL.cpp
  #include "trialDLL.h"
  
  TRIALDLL_API MyMathFuncs* __stdcall new_MyMathFuncs(double offset)
  {
      return new MyMathFuncs(offset);
  }
  
  TRIALDLL_API void __stdcall del_MyMathFuncs(MyMathFuncs *myMath)
  {
      delete myMath;
  }
  
  TRIALDLL_API double __stdcall MyAdd(MyMathFuncs *myMath, double a, double b)
  {
      return myMath-&gt;Add(a, b);
  }
  // ... some other definitions
  </code></pre>
  
  <p>With these two files in the project, I added a property sheet to the project through visual studio 2010 property manager and added <code>TRIALDLL_EXPORT</code> to user macros. After all these, the nice Intellisense gives me error for each function defined in the .cpp file and complains "error: a function declared 'dllimport' may not be defined". So it appears that Intellisense doesn't find <code>TRIALDLL_EXPORT</code> defined. I thought it might make a difference if I actually build the project, but the result suggests the same error: "error C2491: 'new_MyMathFuncs' : definition of dllimport function not allowed". Then it is clear that the macro <code>TRIALDLL_EXPORT</code> is still not defined in compiling time.  </p>
  
  <p>After failing to add macro through visual studio, I also tried putting code line: <code>#define TRIALDLL_EXPORT</code> in trialDLL.cpp but it didn't help either. I wonder what's the proper way to do this? How do I inform the compiler that the micro is defined so that <code>TRIALDLL_API</code> evaluates to <code>dllexport</code> rather than <code>dllimport</code>?</p>
  
  <p>Also, if I can build the .dll successfully, is there any systematic way to test/verify the functionality of the .dll?</p>
  
  <p>Thanks for any help in advance! (Although I know it's an issue here on stackoverflow to put appreciation in the question, I feel myself impolite not to do so. Forgive me for any inefficiency caused by these lines.)</p>