J'aimerais utiliser des pointeurs de fonction mais j'ai un petit problème.
Voilà le code de mon entete.h pour la bibliothèque et fichier.exe
la bibliotgèque :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #ifdef __cplusplus extern "C" { #endif #include <windows.h> #ifdef BUILD_DLL #define DLL_EXPORT __declspec(dllexport) LRESULT CALLBACK GetMsgProc(int code, WPARAM wParam, LPARAM lParam); #else #define DLL_EXPORT __declspec(dllimport) #endif typedef void (*fontion_traitement)(WPARAM,LPARAM); int DLL_EXPORT start(fontion_traitement); #ifdef __cplusplus } #endif
la console :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 #include "main.h" HINSTANCE hInstance ; HHOOK hHook ; fontion_traitement fonction; LRESULT CALLBACK GetMsgProc(int code, WPARAM wParam, LPARAM lParam) { if( code >=0 ) { if( code == HCBT_MINMAX ) { fonction(wParam,lParam); } } return CallNextHookEx(hHook,code,wParam,lParam); } int DLL_EXPORT start(fontion_traitement fonctionX) { fonction = fonctionX ; if(!hHook) hHook = SetWindowsHookExA(WH_CBT,GetMsgProc,hInstance,0); return (int)hHook; } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { switch (fdwReason) { case DLL_PROCESS_ATTACH: hInstance = hinstDLL; break; case DLL_PROCESS_DETACH: // detach from process break; case DLL_THREAD_ATTACH: // attach to thread break; case DLL_THREAD_DETACH: // detach from thread break; } return TRUE; // succesful }
Mais le problème, mon code ne marche pas. D'ou viens le problème ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include "main.h" #include <iostream> void Loop() { MSG message ; while(GetMessage(&message,NULL,0,0)) { TranslateMessage(&message); DispatchMessage(&message); } } void toto(WPARAM wParam,LPARAM lParam) { std::cout << "Traitements de..." } int main() { std::cout << start(toto); Loop(); std::cout << "Hello world!" << std::endl; return 0; }
Partager