Good day! I think you can try the following method: you need two projects - the first with a library, the second with a test program (exe). We add two files to the library project: dllclass.h and dllclass.cpp, here is their implementation:
// dllclass.h #ifdef MAKE_DLL #define CLASS_EXPORT __declspec(dllexport) #else #define CLASS_EXPORT __declspec(dllimport) #endif class F{ public: static int foo(int i); }; // dllclass.cpp int F::foo(int i) { return i + 1; }
Next, in the compiler options, add the preprocessor directive (predefined): MAKE_DLL
The magic is that when you compile a project with a library, the class will be declared as exported , in all other cases it will be imported (see the preprocessor directives in dllclass.h).
Now you need to write a library testing program. In the project with the application, create the file main.cpp and write there something like the following:
// main.cpp #include <dllclass.h> #include <iostream> int main(int argc, char* argv[]) { using namespace std; cout << F::foo(3) << endl; return 0; }
Important: before compiling, you need to specify in the options the paths to the header files of your library and the * .lib file!
Try it, it should help!