Hi,
ich versuche eine Funktion aus einer dll aufzurufen. Die Funktion befindet sich dort in einer Klasse. funktionen die nicht in der Klasse sind kaann ich bereits aufrufen, aber wie mach ich das fuer Klassen funktionen?
Hier mal mein Beispiel Programm:
Fuer die DLL:
<<<dlltest.h>>>
<<<dlltest.cpp>>>
...und fuer die Anwendung
Wie kann ich die Funktion "LetterList" in der main.cpp aufrufen?
Danke schon mal
Stefan
ich versuche eine Funktion aus einer dll aufzurufen. Die Funktion befindet sich dort in einer Klasse. funktionen die nicht in der Klasse sind kaann ich bereits aufrufen, aber wie mach ich das fuer Klassen funktionen?
Hier mal mein Beispiel Programm:
Fuer die DLL:
<<<dlltest.h>>>
PHP:
#ifndef _DLLTEST_H_
#define _DLLTEST_H_
#include <iostream>
#include <windows.h>
extern "C" __declspec(dllexport) void NumberList();
class MyClass
{
private:
MyClass();
~MyClass();
public:
void LetterList();
};
#endif
<<<dlltest.cpp>>>
PHP:
#include "dlltest.h"
using namespace std;
void NumberList() {
cout << "NumberList(): ";
for(int i=0; i<10; i++) {
cout << i << " ";
}
cout << endl;
}
MyClass::MyClass(){}
MyClass::~MyClass(){}
void MyClass::LetterList()
{
cout << "LetterList(): ";
for(int i=0; i<26; i++) {
cout << char(97 + i) << " ";
}
cout << endl << endl;
}
...und fuer die Anwendung
PHP:
#include <windows.h>
#include <iostream>
#include <conio.h> //wait on user reaction - _getch() -
typedef void (WINAPI* cfunc)();
using namespace std;
cfunc NumberList;
cfunc LetterList;
int main() {
cout << "Loading library...";
HINSTANCE hLib=LoadLibrary("TheDLL.dll");
if(hLib==NULL)
{cout << "Faild! Unable to load library!" << endl;}
else
{cout << "Done!" << endl;}
cout << "Loading function...";
NumberList=(cfunc)GetProcAddress((HMODULE)hLib, "NumberList");
if((NumberList==NULL))
{
cout << "Faild! Unable to load function." << endl;
_getch();//wait on user reaction
}
else
{
cout << "Done!" << endl;
NumberList();
}
FreeLibrary((HMODULE)hLib);
_getch();//wait on user reaction
return 0;
}
Wie kann ich die Funktion "LetterList" in der main.cpp aufrufen?
Danke schon mal
Stefan