1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <windows.h>
#include <iostream>
// Ptr sur fonction
typedef int (*AdditionDLL)(int, int);
AdditionDLL ptrAdditionDLL;
using namespace std;
int addition(int a, int b)
{
return a + b;
}
int main(void)
{
// Utilisation de la fonction addition du programme courant.
cout << addition(10,5) << endl;
// Utilisation de la fct addition de notre DLL.
// Etape 1 : La charger !
HINSTANCE LoadMe;
LoadMe = LoadLibrary("C:\\Documents and Settings\\Ju`\\Mes documents\\Visual Studio 2008\\Projects\\DLL\\Debug\\DLL.dll");
if (LoadMe)
{
ptrAdditionDLL = (AdditionDLL)GetProcAddress(LoadMe,"addition");
cout << ptrAdditionDLL(10,5) << endl;
FreeLibrary(LoadMe);
}
else
cout << "Owned!" << endl;
system("Pause");
} |