2 * Copyright 2004 Martin Fuchs
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 // NotifyHook DLL for ROS Explorer
25 // Martin Fuchs, 17.03.2004
29 #include "../utility/utility.h"
31 #include "notifyhook.h"
34 static HINSTANCE s_hInstance
;
35 static UINT WM_GETMODULEPATH
;
36 static HHOOK s_hNotifyHook
;
39 BOOL APIENTRY
DllMain(HINSTANCE hInst
, DWORD dwReason
, LPVOID param
)
42 case DLL_PROCESS_ATTACH
:
44 DisableThreadLibraryCalls(hInst
);
45 WM_GETMODULEPATH
= RegisterWindowMessageA("WM_GETMODULEPATH");
53 struct COPYDATA_STRUCT
{
59 LRESULT CALLBACK
NotifyHookProc(int code
, WPARAM wparam
, LPARAM lparam
)
61 MSG
* pmsg
= (MSG
*)lparam
;
63 if (pmsg
->message
== WM_GETMODULEPATH
) {
64 struct COPYDATA_STRUCT cds
;
67 cds
._hwnd
= pmsg
->hwnd
;
68 cds
._len
= GetWindowModuleFileNameA(pmsg
->hwnd
, cds
._path
, COUNTOF(cds
._path
));
70 data
.dwData
= WM_GETMODULEPATH
;
71 data
.cbData
= sizeof(cds
);
74 SendMessage((HWND
)pmsg
->wParam
, WM_COPYDATA
, (WPARAM
)pmsg
->hwnd
, (LPARAM
)&data
);
79 return CallNextHookEx(s_hNotifyHook
, code
, wparam
, lparam
);
83 UINT
InstallNotifyHook()
85 s_hNotifyHook
= SetWindowsHookEx(WH_GETMESSAGE
, NotifyHookProc
, s_hInstance
, 0);
87 return WM_GETMODULEPATH
;
90 void DeinstallNotifyHook()
92 UnhookWindowsHookEx(s_hNotifyHook
);
97 void GetWindowModulePath(HWND hwnd
)
99 SendMessage(hwnd
, WM_GETMODULEPATH
, 0, 0);
102 // retrieve module path by receiving WM_COPYDATA message
103 DECL_NOTIFYHOOK
int GetWindowModulePathCopyData(LPARAM lparam
, HWND
* phwnd
, LPSTR buffer
, int size
)
105 PCOPYDATASTRUCT data
= (PCOPYDATASTRUCT
) lparam
;
107 if (data
->dwData
== WM_GETMODULEPATH
) {
108 struct COPYDATA_STRUCT
* cds
= (struct COPYDATA_STRUCT
*) data
->lpData
;
111 lstrcpyn(buffer
, cds
->_path
, size
);