ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

notifyhook.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2004 Martin Fuchs
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017  */
00018 
00019 
00020  //
00021  // NotifyHook DLL for ROS Explorer
00022  //
00023  // notifyhook.cpp
00024  //
00025  // Martin Fuchs, 17.03.2004
00026  //
00027 
00028 
00029 #include "../utility/utility.h"
00030 
00031 #include "notifyhook.h"
00032 
00033 
00034 static HINSTANCE s_hInstance;
00035 static UINT WM_GETMODULEPATH;
00036 static HHOOK s_hNotifyHook;
00037 
00038 
00039 BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID param)
00040 {
00041     switch(dwReason) {
00042       case DLL_PROCESS_ATTACH:
00043         s_hInstance = hInst;
00044         DisableThreadLibraryCalls(hInst);
00045         WM_GETMODULEPATH = RegisterWindowMessageA("WM_GETMODULEPATH");
00046         break;
00047     }
00048 
00049     return TRUE;
00050 }
00051 
00052 
00053 struct COPYDATA_STRUCT {
00054     HWND    _hwnd;
00055     int     _len;
00056     char    _path[MAX_PATH];
00057 };
00058 
00059 LRESULT CALLBACK NotifyHookProc(int code, WPARAM wparam, LPARAM lparam)
00060 {
00061     MSG* pmsg = (MSG*)lparam;
00062 
00063     if (pmsg->message == WM_GETMODULEPATH) {
00064         struct COPYDATA_STRUCT cds;
00065         COPYDATASTRUCT data;
00066 
00067         cds._hwnd = pmsg->hwnd;
00068         cds._len = GetWindowModuleFileNameA(pmsg->hwnd, cds._path, COUNTOF(cds._path));
00069 
00070         data.dwData = WM_GETMODULEPATH;
00071         data.cbData = sizeof(cds);
00072         data.lpData = &cds;
00073 
00074         SendMessage((HWND)pmsg->wParam, WM_COPYDATA, (WPARAM)pmsg->hwnd, (LPARAM)&data);
00075 
00076         return 0;
00077     }
00078 
00079     return CallNextHookEx(s_hNotifyHook, code, wparam, lparam);
00080 }
00081 
00082 
00083 UINT InstallNotifyHook()
00084 {
00085     s_hNotifyHook = SetWindowsHookEx(WH_GETMESSAGE, NotifyHookProc, s_hInstance, 0);
00086 
00087     return WM_GETMODULEPATH;
00088 }
00089 
00090 void DeinstallNotifyHook()
00091 {
00092     UnhookWindowsHookEx(s_hNotifyHook);
00093     s_hNotifyHook = 0;
00094 }
00095 
00096 
00097 void GetWindowModulePath(HWND hwnd)
00098 {
00099     SendMessage(hwnd, WM_GETMODULEPATH, 0, 0);
00100 }
00101 
00102  // retrieve module path by receiving WM_COPYDATA message
00103 DECL_NOTIFYHOOK int GetWindowModulePathCopyData(LPARAM lparam, HWND* phwnd, LPSTR buffer, int size)
00104 {
00105     PCOPYDATASTRUCT data = (PCOPYDATASTRUCT) lparam;
00106 
00107     if (data->dwData == WM_GETMODULEPATH) {
00108         struct COPYDATA_STRUCT* cds = (struct COPYDATA_STRUCT*) data->lpData;
00109 
00110         *phwnd = cds->_hwnd;
00111         lstrcpyn(buffer, cds->_path, size);
00112 
00113         return cds->_len;
00114     } else
00115         return 0;
00116 }

Generated on Fri May 25 2012 04:16:41 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.