Hi! I found this code in i'm going to hook another process using SetWindowsHookEx, and send back back to vb6 here is code:
how come it crash everytime wm_command is clicked? what am i doing wrong?Code://HookDemo.cpp #include <windows.h> #include "WINUSER.H" /*--------------------------------------------- Shared Variables This data is shared between both prcesses. The VB App has access to these variables through the function SetSharedData ---------------------------------------------*/ #pragma data_seg(".shared") HHOOK hmsgHooks = 0; // Hook handle for WH_GETMESSAGE #pragma data_seg() #pragma comment(linker, "/SECTION:.shared,RWS") typedef void (__stdcall *funcp)(long); funcp VBCallback; //--------------------------------------------- // Global Variables, specific to each process //--------------------------------------------- HINSTANCE hInstance; // Global instance handle for DLL //-------------------------------------------- // DLL entry-point //-------------------------------------------- BOOL WINAPI DllMain( HINSTANCE hinstDLL, // handle to DLL module DWORD fdwReason, // reason for calling function LPVOID lpvReserved ) // reserved { // Perform actions based on the reason for calling. switch( fdwReason ) { case DLL_PROCESS_ATTACH: // Initialize once for each new process. // Return FALSE to fail DLL load. hInstance = hinstDLL;//save dll handle for each process break; case DLL_THREAD_ATTACH: // Do thread-specific initialization. break; case DLL_THREAD_DETACH: // Do thread-specific cleanup. break; case DLL_PROCESS_DETACH: // Perform any necessary cleanup. break; } return TRUE; // Successful DLL_PROCESS_ATTACH. } LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam); __declspec(dllexport) int _stdcall InstallFilterDLL(DWORD dwThreadId, long lpCallback) { if (hmsgHooks==0) VBCallback = (funcp)lpCallback; hmsgHooks = SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC) GetMsgProc, (HINSTANCE) hInstance, dwThreadId); ::Sleep(1000L); if (hmsgHooks==0) return GetLastError(); return 0; } __declspec(dllexport) int UnInstallFilterDLL(void) { LRESULT result; if (hmsgHooks != 0){ result = UnhookWindowsHookEx(hmsgHooks); if (result == 0) return GetLastError(); hmsgHooks = 0; } return 0; } LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam) { MSG *lpMsg; //return immediately for negative nCodes if (nCode >= 0){ if (nCode==HC_ACTION){ lpMsg = (MSG *) lParam; if(lpMsg->message == WM_COMMAND) { VBCallback((short)lpMsg->hwnd); } }//end if nCode==Action }//end if nCode >=0 return(CallNextHookEx(hmsgHooks, nCode, wParam, lParam)); } __declspec(dllexport) int fDLL(void) { VBCallback((short)hInstance); return 0; }
i know that function send to vb6 work because i move that function installfilterdll and make send back vb6 nothin wrong, so......
please help
thank thousand




Reply With Quote