/[rdesktop]/sourceforge.net/trunk/seamlessrdp/ServerExe/HookDll/hookdll.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /sourceforge.net/trunk/seamlessrdp/ServerExe/HookDll/hookdll.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1080 - (hide annotations)
Thu Mar 9 15:57:10 2006 UTC (18 years, 2 months ago) by ossman_
File MIME type: text/plain
File size: 5513 byte(s)
Remove handling of WM_WINDOWPOSCHANGING and move that into WM_WINDOWPOSCHANGED
since the former isn't always sent.

1 ossman_ 1071 /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.
3     Seamless windows - Remote server hook DLL
4 ossman_ 1069
5 ossman_ 1071 Based on code copyright (C) 2004-2005 Martin Wickett
6    
7     Copyright (C) Peter Åstrand <astrand@cendio.se> 2005-2006
8     Copyright (C) Pierre Ossman <ossman@cendio.se> 2006
9    
10     This program is free software; you can redistribute it and/or modify
11     it under the terms of the GNU General Public License as published by
12     the Free Software Foundation; either version 2 of the License, or
13     (at your option) any later version.
14    
15     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     GNU General Public License for more details.
19    
20     You should have received a copy of the GNU General Public License
21     along with this program; if not, write to the Free Software
22     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23     */
24    
25 ossman_ 1069 #include <stdio.h>
26     #include <stdarg.h>
27    
28 ossman_ 1071 #include <windows.h>
29     #include <winuser.h>
30 ossman_ 1069
31 ossman_ 1073 #include "../vchannel.h"
32 ossman_ 1071
33 ossman_ 1069 #define DLL_EXPORT __declspec(dllexport)
34    
35     // Shared DATA
36     #pragma data_seg ( "SHAREDDATA" )
37    
38     // this is the total number of processes this dll is currently attached to
39 ossman_ 1071 int g_instance_count = 0;
40 ossman_ 1069
41     #pragma data_seg ()
42    
43     #pragma comment(linker, "/section:SHAREDDATA,rws")
44    
45 ossman_ 1071 static HHOOK g_cbt_hook = NULL;
46     static HHOOK g_wndproc_hook = NULL;
47 ossman_ 1069
48 ossman_ 1071 static HINSTANCE g_instance = NULL;
49 ossman_ 1069
50 ossman_ 1071 static HANDLE g_mutex = NULL;
51 ossman_ 1069
52 ossman_ 1071 static LRESULT CALLBACK
53     wndproc_hook_proc(int code, WPARAM cur_thread, LPARAM details)
54 ossman_ 1069 {
55 ossman_ 1079 HWND hwnd;
56     UINT msg;
57     WPARAM wparam;
58     LPARAM lparam;
59 ossman_ 1069
60 ossman_ 1079 LONG style;
61 ossman_ 1069
62 ossman_ 1071 if (code < 0)
63     goto end;
64 ossman_ 1069
65 ossman_ 1079 hwnd = ((CWPSTRUCT *) details)->hwnd;
66     msg = ((CWPSTRUCT *) details)->message;
67     wparam = ((CWPSTRUCT *) details)->wParam;
68     lparam = ((CWPSTRUCT *) details)->lParam;
69    
70     style = GetWindowLong(hwnd, GWL_STYLE);
71    
72     if (style & WS_CHILD)
73     goto end;
74    
75 ossman_ 1071 switch (msg)
76     {
77 ossman_ 1069
78 ossman_ 1071 case WM_WINDOWPOSCHANGED:
79 ossman_ 1079 {
80     RECT rect;
81     WINDOWPOS *wp = (WINDOWPOS *) lparam;
82 ossman_ 1069
83 ossman_ 1079 if (wp->flags & SWP_SHOWWINDOW)
84     {
85     // FIXME: Now, just like create!
86     debug("SWP_SHOWWINDOW for %p!", hwnd);
87     vchannel_write("CREATE1,0x%p,0x%x", hwnd, 0);
88 ossman_ 1069
89 ossman_ 1079 // FIXME: SETSTATE
90 ossman_ 1069
91 ossman_ 1079 if (!GetWindowRect(hwnd, &rect))
92     {
93     debug("GetWindowRect failed!\n");
94     break;
95     }
96     vchannel_write("POSITION1,0x%p,%d,%d,%d,%d,0x%x",
97     hwnd,
98     rect.left, rect.top,
99     rect.right - rect.left,
100     rect.bottom - rect.top, 0);
101     }
102 ossman_ 1069
103 ossman_ 1079 if (wp->flags & SWP_HIDEWINDOW)
104     vchannel_write("DESTROY1,0x%p,0x%x", hwnd, 0);
105    
106     if (!(style & WS_VISIBLE))
107     break;
108    
109 ossman_ 1080 if (!(wp->flags & SWP_NOMOVE && wp->flags & SWP_NOSIZE))
110     {
111     if (!GetWindowRect(hwnd, &rect))
112     {
113     debug("GetWindowRect failed!\n");
114     break;
115     }
116 ossman_ 1079
117 ossman_ 1080 vchannel_write("POSITION1,0x%p,%d,%d,%d,%d,0x%x",
118     hwnd,
119     rect.left, rect.top,
120     rect.right - rect.left,
121     rect.bottom - rect.top, 0);
122 ossman_ 1071 }
123 ossman_ 1079
124     if (!(wp->flags & SWP_NOZORDER))
125 ossman_ 1080 {
126 ossman_ 1079 vchannel_write("ZCHANGE1,0x%p,0x%p,0x%x",
127     hwnd,
128     wp->flags & SWP_NOACTIVATE ? wp->
129     hwndInsertAfter : 0, 0);
130 ossman_ 1080 }
131 ossman_ 1069
132 ossman_ 1071 break;
133 ossman_ 1079 }
134 ossman_ 1069
135 ossman_ 1071 case WM_DESTROY:
136     vchannel_write("DESTROY1,0x%p,0x%x", hwnd, 0);
137     break;
138 ossman_ 1069
139 ossman_ 1071 default:
140     break;
141     }
142    
143     end:
144     return CallNextHookEx(g_wndproc_hook, code, cur_thread, details);
145 ossman_ 1069 }
146    
147 ossman_ 1071 static LRESULT CALLBACK
148     cbt_hook_proc(int code, WPARAM wparam, LPARAM lparam)
149 ossman_ 1069 {
150 ossman_ 1071 char title[150];
151 ossman_ 1069
152 ossman_ 1071 if (code < 0)
153     goto end;
154 ossman_ 1069
155 ossman_ 1071 switch (code)
156     {
157     case HCBT_MINMAX:
158     {
159 ossman_ 1079 int show, state;
160 ossman_ 1069
161 ossman_ 1071 show = LOWORD(lparam);
162 ossman_ 1069
163 ossman_ 1071 if ((show == SW_SHOWMINIMIZED) || (show == SW_MINIMIZE))
164     {
165     MessageBox(0,
166     "Minimizing windows is not allowed in this version. Sorry!",
167     "SeamlessRDP", MB_OK);
168     return 1;
169     }
170 ossman_ 1069
171 ossman_ 1071 GetWindowText((HWND) wparam, title, sizeof(title));
172 ossman_ 1069
173 ossman_ 1071 /* FIXME: Strip title of dangerous characters */
174 ossman_ 1069
175 ossman_ 1079 if (show == SW_SHOWNORMAL)
176     state = 0;
177     else if (show == SW_SHOWMINIMIZED)
178     state = 1;
179     else if (show == SW_SHOWMAXIMIZED)
180     state = 2;
181 ossman_ 1071 vchannel_write("SETSTATE1,0x%p,%s,0x%x,0x%x",
182 ossman_ 1079 (HWND) wparam, title, state, 0);
183 ossman_ 1071 break;
184     }
185 ossman_ 1069
186 ossman_ 1071 default:
187     break;
188     }
189 ossman_ 1069
190 ossman_ 1071 end:
191     return CallNextHookEx(g_cbt_hook, code, wparam, lparam);
192 ossman_ 1069 }
193    
194 ossman_ 1071 DLL_EXPORT void
195     SetHooks(void)
196 ossman_ 1069 {
197 ossman_ 1071 if (!g_cbt_hook)
198     g_cbt_hook = SetWindowsHookEx(WH_CBT, cbt_hook_proc, g_instance, 0);
199 ossman_ 1069
200 ossman_ 1071 if (!g_wndproc_hook)
201     g_wndproc_hook = SetWindowsHookEx(WH_CALLWNDPROC, wndproc_hook_proc, g_instance, 0);
202 ossman_ 1069 }
203    
204 ossman_ 1071 DLL_EXPORT void
205     RemoveHooks(void)
206 ossman_ 1069 {
207 ossman_ 1071 if (g_cbt_hook)
208     UnhookWindowsHookEx(g_cbt_hook);
209 ossman_ 1069
210 ossman_ 1071 if (g_wndproc_hook)
211     UnhookWindowsHookEx(g_wndproc_hook);
212 ossman_ 1069 }
213    
214 ossman_ 1071 DLL_EXPORT int
215     GetInstanceCount()
216 ossman_ 1069 {
217 ossman_ 1071 return g_instance_count;
218 ossman_ 1069 }
219    
220 ossman_ 1071 BOOL APIENTRY
221     DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpReserved)
222 ossman_ 1069 {
223 ossman_ 1071 switch (ul_reason_for_call)
224     {
225     case DLL_PROCESS_ATTACH:
226     // remember our instance handle
227     g_instance = hinstDLL;
228 ossman_ 1069
229 ossman_ 1073 g_mutex = CreateMutex(NULL, FALSE, "Local\\SeamlessDLL");
230 ossman_ 1071 if (!g_mutex)
231     return FALSE;
232 ossman_ 1069
233 ossman_ 1071 WaitForSingleObject(g_mutex, INFINITE);
234     ++g_instance_count;
235     ReleaseMutex(g_mutex);
236 ossman_ 1069
237 ossman_ 1071 vchannel_open();
238 ossman_ 1069
239 ossman_ 1071 break;
240 ossman_ 1069
241 ossman_ 1071 case DLL_THREAD_ATTACH:
242     break;
243 ossman_ 1069
244 ossman_ 1071 case DLL_THREAD_DETACH:
245     break;
246 ossman_ 1069
247 ossman_ 1071 case DLL_PROCESS_DETACH:
248     WaitForSingleObject(g_mutex, INFINITE);
249     --g_instance_count;
250     ReleaseMutex(g_mutex);
251 ossman_ 1069
252 ossman_ 1071 vchannel_close();
253 ossman_ 1069
254 ossman_ 1071 CloseHandle(g_mutex);
255 ossman_ 1069
256 ossman_ 1071 break;
257     }
258 ossman_ 1069
259 ossman_ 1071 return TRUE;
260 ossman_ 1069 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26