Hejo, hab gerade ein bisschen mit Dlls rumgespielt und versucht functions die in einer Dll sind in meiner exe aufzurufen und wollte einfach mal fragen wie man das vielleicht noch besser machen könnte, manche Sachen sind da sicher nicht so gut gelöst / unnötig.
Einmal die main.h der Dll:
Einmal die Quelle.cpp der Dll
Und einmal die exe an sich
Einmal die main.h der Dll:
Code:
#ifndef __MAIN_H__
#define __MAIN_H__
#endif
#include <Windows.h>
#define DLL_EXPORT __declspec(dllexport)
#ifdef __cplusplus
extern "C"
{
#endif
int DLL_EXPORT Testfunction(int x);
int DLL_EXPORT Rechnen(int i, int y);
int DLL_EXPORT Ausgeben();
#ifdef __cplusplus
}
#endif
Code:
#include "main.h"
#include <iostream>
int DLL_EXPORT Testfunction(int x = 0){
MessageBox(0,"lololowwwwwwwwwwwl", "wqgqwwwwwgq", MB_OK |MB_ICONINFORMATION);
return x;
}
int DLL_EXPORT Rechnen(int i, int y){
int z = i + y;
return z;
}
int DLL_EXPORT Ausgeben(){
std::cout << "test";
return 1;
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason)
{return 1;}
Code:
#include <iostream>
#include <Windows.h>
using namespace std;
typedef int (*Testfunction)(int);
typedef int (*Rechnen)(int, int);
typedef int (*Ausgeben)();
HINSTANCE hinstDLL;
int main(){
Testfunction MsgBox(0) ;
Rechnen MsgBox2(0) ;
Ausgeben MsgBox3(0 ) ;
hinstDLL = LoadLibrary("RealDLL.dll");
if (hinstDLL != 0)
{
Testfunction= (Testfunction) GetProcAddress(hinstDLL, "Testfunction");
Rechnen = (Rechnen) GetProcAddress(hinstDLL, "Rechnen");
Ausgeben = (Ausgeben) GetProcAddress(hinstDLL, "Ausgeben");
}
if (Testfunction== 0 ) cout << "Message Box failed";
int AusgabeNumeroUno = Testfunction(5);
int AusgabeNumeroDuo = Rechnen (5,2);
int AusgabeNumeroTres = Ausgeben ();
if ( AusgabeNumeroUno == 5 )
{
cout << "Message displayed!" << AusgabeNumeroDuo << AusgabeNumeroTres << endl;
}
Sleep(10000);
FreeLibrary(hinstDLL);
}