What are the various dll, and how skillfully to write classes within them, well written, saving and using.
Hello dear!
I am very interested, I want so many dll in various ways, what would be the skill in this.
So I compiled the file and compiled the dll for it too.
The file was going well, the dll compiled without errors, but it does not work.
I still can not see any class or functions! Every time failure set in wait for the frustrated.
Understanding is looking for, what's the failure, and how especially to write classes using various methods?
I will even lay out the full archive with the contents.
Code:
#include <cstring>
class __declspec(dllexport) Mat {
private:
int x;
int y;
int rezultat;
public:
Mat() : x(0), y(0), rezultat(0) {}
Mat(int _x, int _y ): x(_x), y(_y), rezultat(0) {}
int plus(){ rezultat = x+y; return rezultat;}
int minus(){ rezultat = x-y; return rezultat;}
int mnozhyty(){ rezultat = x*y; return rezultat;}
int dilyty(){ if(y!=0) rezultat = x/y; else rezultat = 0; return rezultat;}
void zadaj(int _x, int _y){ x=_x; y=_y;}
};
__declspec(dllexport) Mat Mat_vydaj_nazovni_functija(int w, int h)
{
Mat m(w, h);
return m;
}
__declspec(dllexport) int rezultat_vydaj_nazovni_functija(int w, int h, char vybor[250])
{
Mat q(w, h);
if(strcmp(vybor,"minus"))
{
return q.minus();
}
else if(strcmp(vybor,"plus"))
{
return q.plus();
}
else if(strcmp(vybor,"mnozhyty"))
{
return q.mnozhyty();
}
else if(strcmp(vybor,"dilyty")==0)
{
return q.dilyty();
}
else
{
return 0;
}
}
Code:
#include <windows.h>
#include <stdio.h>
#include <iostream>
//#include "Mat.hpp"
int main ()
{
HMODULE deskriptor_modula = LoadLibrary ("Mat_dll.dll");
FARPROC adres_funktsii_plus = GetProcAddress (deskriptor_modula, "plus");
char mainchar [255] = "MAIN TSE POCHATOK";
class __declspec(dllimport) Mat {};
Mat mat1;
typedef Mat (*Mat_vydaj_nazovni_functija)(int, int);
Mat_vydaj_nazovni_functija pMat_vydaj_nazovni_functija = (Mat_vydaj_nazovni_functija)GetProcAddress(deskriptor_modula, "Mat_vydaj_nazovni_functija");
if (pMat_vydaj_nazovni_functija != NULL)
{
mat1 = (*pMat_vydaj_nazovni_functija) (70, 10);
//int min mat1;
int *pmat = (int*) &mat1;
std::cout << pmat << std::endl;
}
typedef int (*rezultat_vydaj_nazovni_functija)(int, int, char[250]);
rezultat_vydaj_nazovni_functija prezultat_vydaj_nazovni_functija = (rezultat_vydaj_nazovni_functija)GetProcAddress(deskriptor_modula, "rezultat_vydaj_nazovni_functija");
if (prezultat_vydaj_nazovni_functija != NULL)
{
char vybir[250][4] = { "minus", "plus", "mnozhyty", "dilyty" };
int i=0;
std::cout << vybir[250][0] << " " << "vvedy" << " 0" << std::endl;
std::cout << vybir[250][1] << " " << "vvedy" << " 1" << std::endl;
std::cout << vybir[250][2] << " " << "vvedy" << " 2" << std::endl;
std::cout << vybir[250][3] << " " << "vvedy" << " 3" << std::endl;
std::cin >> i;
int rezultat = (*prezultat_vydaj_nazovni_functija) (70, 10, vybir[250][i]);
//int min mat1;
std::cout << rezultat << std::endl;
}
//
FreeLibrary(deskriptor_modula);
//int mysum = mat1.plus();
int *pmat = (int*) &mat1;
std::cout << pmat << std::endl;
std::cout << mainchar << std::endl;
std::cin >> mainchar;
return 0;
}
Code:
del MAIN.exe
g++ -fpermissive -o MAIN.exe MAIN.cpp
del Mat_dll.dll
g++ -shared -o Mat_dll.dll Mat_dll.cpp
rem tak prykryvaty
pause