I have found a tutorial about how to use DLL, but it use just one function in a DLL.
I am a beginner and i want to use a class in a DLL and not just a function.
I have tried to create 2 programs (one for creating the DLL and one which use the DLL).
But i have a problem.
I use DevCPP.
This is my programs:
In a DLL project:
print.cpp:
print.hCode:#include "print.h" class __declspec(dllexport) Toto { public: int x; void Print(void) { printf("toto\n"); } };
-------------------------Code:#ifndef PRINT_H #define PRINT_H #include <iostream> using namespace std; class __declspec(dllexport) Toto; #endif
In the project which use the DLL (i have linked my .lib file created by the program above):
main.cpp:
print.h:Code:#include "print.h" #include <conio.h> int main() { Toto gogo; gogo.Print(); getch(); return 0; }
I don't use source code created by DevCpp.Code:#ifndef PRINT_H #define PRINT_H #include <iostream> using namespace std; class __declspec(dllimport) Toto; #endif
When i compile the program which create the DLL it works.
But when i compile the program which use the DLL i have this error:
Compilateur: Default compiler
Building Makefile: "D:\asauvegardes\cd_prog6\projets\devcpp\dll\test_ cpp\loader\Makefile.win"
Exécution de make...
make.exe -f "D:\asauvegardes\cd_prog6\projets\devcpp\dll\test_ cpp\loader\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include/c++/mingw32" -I"C:/Dev-Cpp/include/c++/backward" -I"C:/Dev-Cpp/include"
main.cpp: In function `int main()':
main.cpp:8: aggregate `Toto gogo' has incomplete type and cannot be defined
make.exe: *** [main.o] Error 1
Exécution terminée
How can i create and use a class with a DLL?
Thanks.