0

I have a c++ class that I've defined in a header file testclass.hpp the code works fine in as an .exe now I want to use it for a dll and I don't know how to do it I visted MSDN site and did what they tell there but in didn'T help , any idea how to do this. here a code example :

#ifndef TESTCLASS_H
#define TESTCLASS_H

#include <iostream>


class Test{
    private: 
     int variable1;
     int variable2;
    public:
     Test(float,int);
     ~Test();
     void doStuff();
     int getstuff();

};
#endif

and this is what I tried :

#ifndef TESTCLASS_H
#define TESTCLASS_H
#ifndef TESTCLASSDLL_EXPORTS
#define TESTCLASSDLL_API __declspec(dllexport) 
#else
#endif
#define TESTCLASSDLL_API __declspec(dllimport) 
#include <iostream>


class Test{
    private: 
    static __declspec(dllexport) int variable1;
    static __declspec(dllexport) int variable2;
    public:
    TESTCLASSDLL_API Test(float,int);
    TESTCLASSDLL_API ~Test();
    TESTCLASSDLL_API void doStuff();
    TESTCLASSDLL_API int getstuff();

};
#endif 
Engine
  • 5,360
  • 18
  • 84
  • 162
  • 2
    And you didn't put declare that as `class TESTCLASSDLL_API Test` because...? – WhozCraig Oct 07 '13 at 07:47
  • @WhozCraig I don't get what you mean – Engine Oct 07 '13 at 07:56
  • I mean it would appear you want to export the class, including its members (both function and variables). You can do that by simply using your macro from above and wedging it between `class` and your class name. All the declspec and macro use inside your class is not needed. – WhozCraig Oct 07 '13 at 07:59
  • ok? can you please write a code example so I can understand it thanks in advance! – Engine Oct 07 '13 at 08:00
  • 1
    nope, but I can send you [somewhere that has already done so](http://stackoverflow.com/search?q=%5Bc%2B%2B%5D+%5Bwindows%5D+exporting+a+class+from+a+dll). – WhozCraig Oct 07 '13 at 08:03

0 Answers0