Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
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 |
#include <iostream> #include <windows.h> using namespace std; int main () { // DLL Laden HMODULE hDLL = LoadLibrary("test.dll"); if(!hDLL) { // Fehler MessageBox(NULL, "DLL nicht gefunden!!!", "Fehler", MB_OK | MB_ICONHAND); return 1; } // Die Funktion rufen BOOL(__stdcall* pFunc)(LPCSTR, UINT); pFunc = (BOOL (__stdcall*)(LPCSTR, UINT))(GetProcAddress(hDLL, "TestFunc")); if(!pFunc) { MessageBox(NULL, "Funktion nicht vorhanden", "Fehler" , MB_OK | MB_ICONHAND); } // Die Funktion ausführen pFunc("Hallo Welt"); // DLL Freigeben FreeLibrary(hDLL); return 0; } |
Quellcode |
|
1 2 3 4 5 6 7 8 |
Temporäre Dateien und Ausgabedateien für "DLL_Test - Win32 Debug" werden gelöscht. --------------------Konfiguration: DLL_Test - Win32 Debug-------------------- Kompilierung läuft... DLL_Test.cpp c:\programme\microsoft visual studio\myprojects\dll_test\dll_test.cpp(27) : error C2198: 'int (__stdcall *)(const char *,unsigned int)' : too few actual parameters Fehler beim Ausführen von cl.exe. DLL_Test.exe - 1 Fehler, 0 Warnung(en) |
C-/C++-Quelltext |
|
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 |
#include <iostream> #include <windows.h> using namespace std; // Hauptfunktion der DLL BOOL APIENTRY DLLMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID pvReserved) { switch(dwReasonForCall) { case DLL_PROCESS_ATTACH: // Hier z.B.: LogBuch eintrag break; case DLL_PROCESS_DETACH: // Hier z.B.: LogBuch eintrag break; } return TRUE; } extern "C" { __declspec(dllexport) void TestFunc (char Text) { cout << Text << endl; } } |
Alter Hase
C-/C++-Quelltext |
|
1 |
BOOL (__stdcall* pFunc)(LPCSTR, UINT)
|
C-/C++-Quelltext |
|
1 |
void TestFunc(char Text) |
C-/C++-Quelltext |
|
1 2 |
BOOL(__stdcall* pFunc)(LPCSTR, UINT); pFunc = (BOOL (__stdcall*)(LPCSTR, UINT))(GetProcAddress(hDLL, "TestFunc")); |
Administrator
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
//dll void __stdcall TestFunc(char* Text) { MessageBox( 0, Text, "TestFunc", MB_OK ); } //anwendung typedef void (__stdcall *PFUNC) (char*); . . . PFUNC pFunc = (PFUNC) GetProcAddress(hDLL, "TestFunc"); . . . |
Zitat von »"MSVC++"«
...This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
Werbeanzeige