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

Diff of /sourceforge.net/trunk/seamlessrdp/ServerExe/HookDll/hookdll.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 918 by astrand, Thu Jun 30 08:53:04 2005 UTC revision 930 by astrand, Thu Jun 30 14:14:56 2005 UTC
# Line 1  Line 1 
1  //*********************************************************************************  //*********************************************************************************
2  //  //
3  //Title: Terminal Services Window Clipper  //Title: Terminal Services Window Clipper
4  //  //
5  //Author: Martin Wickett  //Author: Martin Wickett
6  //  //
7  //Date: 2004  //Date: 2004
8  //  //
9  //*********************************************************************************  //*********************************************************************************
10    
11  #include "hookdll.h"  #include "hookdll.h"
12  #include <windows.h>  #include <windows.h>
13  #include <winuser.h>  #include <winuser.h>
14    
15  #include "wtsapi32.h"  #include "wtsapi32.h"
16  #include "Cchannel.h"  #include "Cchannel.h"
17    
18  #define DLL_EXPORT extern "C" __declspec(dllexport)  #define DLL_EXPORT extern "C" __declspec(dllexport)
19    
20  // Shared DATA  // Shared DATA
21  #pragma data_seg ( "SHAREDDATA" )  #pragma data_seg ( "SHAREDDATA" )
22    
23          // this is the total number of processes this dll is currently attached to          // this is the total number of processes this dll is currently attached to
24          int                             iInstanceCount          = 0;          int                             iInstanceCount          = 0;
25          HWND                    hWnd                            = 0;          HWND                    hWnd                            = 0;
26    
27  #pragma data_seg ()  #pragma data_seg ()
28    
29  #pragma comment(linker, "/section:SHAREDDATA,rws")  #pragma comment(linker, "/section:SHAREDDATA,rws")
30    
31  bool                    bHooked        = false;  bool                    bHooked        = false;
32  bool                    bHooked2       = false;  bool                    bHooked2       = false;
33  bool                    bHooked3       = false;  bool                    bHooked3       = false;
34  HHOOK                   hhook          = 0;//cbt  HHOOK                   hhook          = 0;//cbt
35  HHOOK                   hhook2         = 0;//shell  HHOOK                   hhook2         = 0;//shell
36  HHOOK                   hhook3             = 0;//wnd proc  HHOOK                   hhook3             = 0;//wnd proc
37  HINSTANCE               hInst          = 0;  HINSTANCE               hInst          = 0;
38  HANDLE                  m_vcHandle         = 0;  HANDLE                  m_vcHandle         = 0;
39    
40  BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD  ul_reason_for_call, LPVOID lpReserved )  BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD  ul_reason_for_call, LPVOID lpReserved )
41  {  {
42      switch (ul_reason_for_call)      switch (ul_reason_for_call)
43          {          {
44                  case DLL_PROCESS_ATTACH:                  case DLL_PROCESS_ATTACH:
45                          {                          {
46                                  // remember our instance handle                                  // remember our instance handle
47                                  hInst = hinstDLL;                                  hInst = hinstDLL;
48                                  ++iInstanceCount;                                  ++iInstanceCount;
49                                  OpenVirtualChannel();                                  OpenVirtualChannel();
50                                   break;                                   break;
51                          }                          }
52    
53                  case DLL_THREAD_ATTACH:                  case DLL_THREAD_ATTACH:
54                                  break;                                  break;
55                  case DLL_THREAD_DETACH:                  case DLL_THREAD_DETACH:
56                          break;                          break;
57                  case DLL_PROCESS_DETACH:                  case DLL_PROCESS_DETACH:
58                          {                          {
59                                  --iInstanceCount;                                  --iInstanceCount;
60                                  CloseVirtualChannel();                                  CloseVirtualChannel();
61                          }                          }
62                          break;                          break;
63      }      }
64    
65      return TRUE;      return TRUE;
66  }  }
67    
68  LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam )  LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam )
69  {  {
70          if (nCode<0)          if (nCode<0)
71          {          {
72                  return CallNextHookEx(hhook3, nCode, wParam, lParam);                  return CallNextHookEx(hhook3, nCode, wParam, lParam);
73          }          }
74    
75          PCHAR buffer          = NULL;          PCHAR buffer          = NULL;
76          char windowTitle[150] = {""};          char windowTitle[150] = {""};
77          HWND windowHandle     = NULL;          HWND windowHandle     = NULL;
78          char result[255]      = {""};          char result[255]      = {""};
79          char strWindowId[25];          char strWindowId[25];
80          char type[25];          char type[25];
81    
82          LONG b,t,l,r;          LONG b,t,l,r;
83      char strB[5];      char strB[5];
84          char strT[5];          char strT[5];
85          char strL[5];          char strL[5];
86      char strR[5];      char strR[5];
87          RECT rect;          RECT rect;
88    
89          CWPSTRUCT* details = (CWPSTRUCT*) lParam;          CWPSTRUCT* details = (CWPSTRUCT*) lParam;
90    
91          switch( details->message )          switch( details->message )
92          {                {      
93                  case WM_SIZING:                  case WM_SIZING:
94                  case WM_MOVING:                  case WM_MOVING:
95                                                    
96                          windowHandle = details->hwnd;                          windowHandle = details->hwnd;
97                          //get win name                          //get win name
98                          GetWindowText(windowHandle,windowTitle,150);                          GetWindowText(windowHandle,windowTitle,150);
99                                                    
100                          //get an id for it                          //get an id for it
101                          itoa((int)windowHandle, strWindowId, 10);                          itoa((int)windowHandle, strWindowId, 10);
102                                                    
103                          //get coords                          //get coords
104                          GetWindowRect(windowHandle,&rect);                          GetWindowRect(windowHandle,&rect);
105                          b = rect.bottom;                          b = rect.bottom;
106                          t = rect.top;                          t = rect.top;
107                          l = rect.left;                          l = rect.left;
108                          r = rect.right;                          r = rect.right;
109                          ltoa(b,strB,10);                          ltoa(b,strB,10);
110                          ltoa(t,strT,10);                          ltoa(t,strT,10);
111                          ltoa(r,strR,10);                          ltoa(r,strR,10);
112                          ltoa(l,strL,10);                          ltoa(l,strL,10);
113    
114                          ////setup return string                          ////setup return string
115                          strcat(result, "MSG=CALLWNDPROC_WM_MOVING;");                          strcat(result, "MSG=CALLWNDPROC_WM_MOVING;");
116                          strcat( result, "ID=" );                          strcat( result, "ID=" );
117                          strcat( result, strWindowId );                          strcat( result, strWindowId );
118                          strcat( result, ";" );                          strcat( result, ";" );
119                          strcat( result, "TITLE=" );                          strcat( result, "TITLE=" );
120                          strcat( result, windowTitle);                          strcat( result, windowTitle);
121                          strcat( result, ";" );                          strcat( result, ";" );
122                          strcat( result, "POS=" );                          strcat( result, "POS=" );
123                          strcat( result, strL);                          strcat( result, strL);
124                          strcat( result, "~");                          strcat( result, "~");
125                          strcat( result, strT);                          strcat( result, strT);
126                          strcat( result, "~");                          strcat( result, "~");
127                          strcat( result, strR);                          strcat( result, strR);
128                          strcat( result, "~");                          strcat( result, "~");
129                          strcat( result, strB);                          strcat( result, strB);
130                          strcat( result, ";" );                          strcat( result, ";" );
131                                                    
132                          buffer = result;                          buffer = result;
133                                    
134                  break;                  break;
135    
136                  default:                  default:
137                          break;                          break;
138          }          }
139    
140          if (ChannelIsOpen())          if (ChannelIsOpen())
141          {          {
142                  if ( buffer != NULL)                  if ( buffer != NULL)
143                  {                  {
144                          WriteToChannel(buffer);                          WriteToChannel(buffer);
145                  }                  }
146          }          }
147    
148          return CallNextHookEx(hhook3, nCode, wParam, lParam);          return CallNextHookEx(hhook3, nCode, wParam, lParam);
149  }  }
150    
151  LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam )  LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam )
152  {  {
153          if (nCode<0)          if (nCode<0)
154          {          {
155                  return CallNextHookEx(hhook, nCode, wParam, lParam);                  return CallNextHookEx(hhook, nCode, wParam, lParam);
156          }          }
157    
158    
159                  PCHAR buffer          = NULL;                  PCHAR buffer          = NULL;
160    
161    
162                  char windowTitle[150] = {""};                  char windowTitle[150] = {""};
163                  HWND windowHandle     = NULL;                  HWND windowHandle     = NULL;
164                  char result[255]      = {""};                  char result[255]      = {""};
165                  char strWindowId[25];                  char strWindowId[25];
166                  char type[25];                  char type[25];
167    
168    
169                  LONG b,t,l,r;                  LONG b,t,l,r;
170          char strB[5];          char strB[5];
171                  char strT[5];                  char strT[5];
172              char strL[5];              char strL[5];
173          char strR[5];          char strR[5];
174                  RECT rect;                  RECT rect;
175    
176                  int i = 0;//tmp                  int i = 0;//tmp
177                    
178                  switch( nCode )                  switch( nCode )
179                  {                  {
180                          case HCBT_MINMAX:                          case HCBT_MINMAX:
181    
182                                  windowHandle = (HWND)wParam;                                  windowHandle = (HWND)wParam;
183                                  //get win name                                  //get win name
184                                  GetWindowText(windowHandle,windowTitle,150);                                  GetWindowText(windowHandle,windowTitle,150);
185                                                                    
186                                  //get an id for it                                  //get an id for it
187                                  itoa((int)windowHandle, strWindowId, 10);                                  itoa((int)windowHandle, strWindowId, 10);
188                                                                    
189                                  //get operation type(min,max). if max, do not clip at all,if min use window's previous coords                                  //get operation type(min,max). if max, do not clip at all,if min use window's previous coords
190                                  //codes are:                                  //codes are:
191    
192                                  // SW_HIDE= 0  SW_SHOWNORMAL=1  SW_NORMAL=1  SW_SHOWMINIMIZED=2  SW_SHOWMAXIMIZED=3  SW_MAXIMIZE=3                                  // SW_HIDE= 0  SW_SHOWNORMAL=1  SW_NORMAL=1  SW_SHOWMINIMIZED=2  SW_SHOWMAXIMIZED=3  SW_MAXIMIZE=3
193                                  // SW_SHOWNOACTIVATE=4  SW_SHOW=5  SW_MINIMIZE=6  SW_SHOWMINNOACTIVE=7  SW_SHOWNA=8  SW_RESTORE=9                                    // SW_SHOWNOACTIVATE=4  SW_SHOW=5  SW_MINIMIZE=6  SW_SHOWMINNOACTIVE=7  SW_SHOWNA=8  SW_RESTORE=9  
194                                  // SW_SHOWDEFAULT=10  SW_FORCEMINIMIZE=11  SW_MAX=11                                      // SW_SHOWDEFAULT=10  SW_FORCEMINIMIZE=11  SW_MAX=11    
195    
196                                  itoa((int)lParam, type, 10);                                  itoa((int)lParam, type, 10);
197    
198                                  //get coords                                  //get coords
199                                  GetWindowRect(windowHandle,&rect);                                  GetWindowRect(windowHandle,&rect);
200                                  b = rect.bottom;                                  b = rect.bottom;
201                                  t = rect.top;                                  t = rect.top;
202                                  l = rect.left;                                  l = rect.left;
203                                  r = rect.right;                                  r = rect.right;
204                                  ltoa(b,strB,10);                                  ltoa(b,strB,10);
205                                  ltoa(t,strT,10);                                  ltoa(t,strT,10);
206                                  ltoa(r,strR,10);                                  ltoa(r,strR,10);
207                                  ltoa(l,strL,10);                                  ltoa(l,strL,10);
208    
209                                  //get name                                  //get name
210                                  GetWindowText(windowHandle,windowTitle,150);                                  GetWindowText(windowHandle,windowTitle,150);
211    
212                                  ////setup return string                                  ////setup return string
213                                  strcat(result, "MSG=HCBT_MINMAX;");                                  strcat(result, "MSG=HCBT_MINMAX;");
214                                  strcat( result, "ID=" );                                  strcat( result, "ID=" );
215                                  strcat( result, strWindowId );                                  strcat( result, strWindowId );
216                                  strcat( result, ";" );                                  strcat( result, ";" );
217                                  strcat( result, "TITLE=" );                                  strcat( result, "TITLE=" );
218                                  strcat( result, windowTitle);                                  strcat( result, windowTitle);
219                                  strcat( result, ";" );                                  strcat( result, ";" );
220                                  strcat( result, "POS=" );                                  strcat( result, "POS=" );
221                                  strcat( result, strL);                                  strcat( result, strL);
222                                  strcat( result, "~");                                  strcat( result, "~");
223                                  strcat( result, strT);                                  strcat( result, strT);
224                                  strcat( result, "~");                                  strcat( result, "~");
225                                  strcat( result, strR);                                  strcat( result, strR);
226                                  strcat( result, "~");                                  strcat( result, "~");
227                                  strcat( result, strB);                                  strcat( result, strB);
228                                  strcat( result, ";" );                                  strcat( result, ";" );
229                                  strcat( result, "TYPE=" );                                  strcat( result, "TYPE=" );
230                                  strcat( result, type );                                  strcat( result, type );
231                                  strcat( result, ";" );                                  strcat( result, ";" );
232    
233                                  //-------------------------------------------------------------------------------------------------                                  //-------------------------------------------------------------------------------------------------
234                                  // code to prevent minimising windows (can be removed once minimise has been implemented)                                  // code to prevent minimising windows (can be removed once minimise has been implemented)
235                                  i = (int)lParam;                                  i = (int)lParam;
236                                  //if (i==0 || i==2 || i==6 || i==7 || i==8 || i==11)                                  //if (i==0 || i==2 || i==6 || i==7 || i==8 || i==11)
237                                  if ( i==2 || i==6 )                                  if ( i==2 || i==6 )
238                                  {                                  {
239                                          MessageBox(0,"Minimising windows is not allowed in this version. Sorry!","TS Window Clipper", MB_OK);                                          MessageBox(0,"Minimising windows is not allowed in this version. Sorry!","TS Window Clipper", MB_OK);
240                                          return 1;                                          return 1;
241                                  }                                  }
242                                  //-----------------------------------------------------------------------------------------                                  //-----------------------------------------------------------------------------------------
243    
244                                  //-------------------------------------------------------------------------------------------------                                  //-------------------------------------------------------------------------------------------------
245                                  // code to prevent maximising windows (can be removed once maximise has been implemented)                                  // code to prevent maximising windows (can be removed once maximise has been implemented)
246                                  i = (int)lParam;                                  i = (int)lParam;
247                                  //if (i==3 || i==9 || i==11)                                  //if (i==3 || i==9 || i==11)
248                                  if (i==3 || i==11)                                  if (i==3 || i==11)
249                                  {                                  {
250                                          MessageBox(0,"Maximising windows is not allowed in this version. Sorry!","TS Window Clipper", MB_OK);                                          MessageBox(0,"Maximising windows is not allowed in this version. Sorry!","TS Window Clipper", MB_OK);
251                                          return 1;                                          return 1;
252                                  }                                  }
253                                  //-----------------------------------------------------------------------------------------                                  //-----------------------------------------------------------------------------------------
254    
255                                  buffer = result;                                  buffer = result;
256    
257                                  break;                                  break;
258    
259                          case HCBT_MOVESIZE:                          case HCBT_MOVESIZE:
260                    
261                                  windowHandle = (HWND)wParam;                                  windowHandle = (HWND)wParam;
262                                  //get win name                                  //get win name
263                                  GetWindowText(windowHandle,windowTitle,150);                                  GetWindowText(windowHandle,windowTitle,150);
264                                                                    
265                                  //get an id for it                                  //get an id for it
266                                  itoa((int)windowHandle, strWindowId, 10);                                  itoa((int)windowHandle, strWindowId, 10);
267    
268                                  //get coords                                  //get coords
269                                  GetWindowRect(windowHandle,&rect);                                  GetWindowRect(windowHandle,&rect);
270                                  b = rect.bottom;                                  b = rect.bottom;
271                                  t = rect.top;                                  t = rect.top;
272                                  l = rect.left;                                  l = rect.left;
273                                  r = rect.right;                                  r = rect.right;
274                                  ltoa(b,strB,10);                                  ltoa(b,strB,10);
275                                  ltoa(t,strT,10);                                  ltoa(t,strT,10);
276                                  ltoa(r,strR,10);                                  ltoa(r,strR,10);
277                                  ltoa(l,strL,10);                                  ltoa(l,strL,10);
278    
279                                  //get name                                  //get name
280                                  GetWindowText(windowHandle,windowTitle,150);                                  GetWindowText(windowHandle,windowTitle,150);
281    
282                                  ////setup return string                                  ////setup return string
283                                  strcat(result, "MSG=HCBT_MOVESIZE;");                                  strcat(result, "MSG=HCBT_MOVESIZE;");
284                                  strcat( result, "ID=" );                                  strcat( result, "ID=" );
285                                  strcat( result, strWindowId );                                  strcat( result, strWindowId );
286                                  strcat( result, ";" );                                  strcat( result, ";" );
287                                  strcat( result, "TITLE=" );                                  strcat( result, "TITLE=" );
288                                  strcat( result, windowTitle);                                  strcat( result, windowTitle);
289                                  strcat( result, ";" );                                  strcat( result, ";" );
290                                  strcat( result, "POS=" );                                  strcat( result, "POS=" );
291                                  strcat( result, strL);                                  strcat( result, strL);
292                                  strcat( result, "~");                                  strcat( result, "~");
293                                  strcat( result, strT);                                  strcat( result, strT);
294                                  strcat( result, "~");                                  strcat( result, "~");
295                                  strcat( result, strR);                                  strcat( result, strR);
296                                  strcat( result, "~");                                  strcat( result, "~");
297                                  strcat( result, strB);                                  strcat( result, strB);
298                                  strcat( result, ";" );                                  strcat( result, ";" );
299    
300                                  buffer = result;                                  buffer = result;
301    
302                                  break;                                  break;
303                          case HCBT_SETFOCUS:                          case HCBT_SETFOCUS:
304                                  //buffer = "HCBT_SETFOCUS";                                  //buffer = "HCBT_SETFOCUS";
305                                  //not needed yet                                  //not needed yet
306                          break;                          break;
307                          default:                          default:
308                                  break;                                  break;
309                  }                  }
310    
311          if (ChannelIsOpen())          if (ChannelIsOpen())
312          {          {
313                  if ( buffer != NULL)                  if ( buffer != NULL)
314                  {                  {
315                          WriteToChannel(buffer);                          WriteToChannel(buffer);
316                  }                  }
317          }          }
318    
319          return CallNextHookEx(hhook, nCode, wParam, lParam);          return CallNextHookEx(hhook, nCode, wParam, lParam);
320  }  }
321    
322    
323  LRESULT CALLBACK ShellProc(int nCode, WPARAM wParam, LPARAM lParam )  LRESULT CALLBACK ShellProc(int nCode, WPARAM wParam, LPARAM lParam )
324  {  {
325          if (nCode<0)          if (nCode<0)
326          {          {
327                  return CallNextHookEx(hhook, nCode, wParam, lParam);                  return CallNextHookEx(hhook, nCode, wParam, lParam);
328          }          }
329    
330          if (ChannelIsOpen())          if (ChannelIsOpen())
331          {          {
332                  PCHAR buffer          = NULL;                  PCHAR buffer          = NULL;
333    
334                  char windowTitle[150] = {""};                  char windowTitle[150] = {""};
335                  HWND windowHandle     = NULL;                  HWND windowHandle     = NULL;
336                  char result[255]      = {""};                  char result[255]      = {""};
337                  char strWindowId[25];                  char strWindowId[25];
338                  LONG b,t,l,r;                  LONG b,t,l,r;
339          char strB[5];          char strB[5];
340                  char strT[5];                  char strT[5];
341              char strL[5];              char strL[5];
342          char strR[5];          char strR[5];
343                  RECT rect;                  RECT rect;
344    
345                  switch( nCode )                  switch( nCode )
346                          {                          {
347                                  case HSHELL_WINDOWCREATED:                                  case HSHELL_WINDOWCREATED:
348                                                                                    
349                                          //get window id                                          //get window id
350                                          windowHandle = (HWND) wParam;                                          windowHandle = (HWND) wParam;
351                                          itoa((int)windowHandle, strWindowId, 10);                                          itoa((int)windowHandle, strWindowId, 10);
352    
353                                          //get coords                                          //get coords
354                                          GetWindowRect(windowHandle,&rect);                                          GetWindowRect(windowHandle,&rect);
355                                          b = rect.bottom;                                          b = rect.bottom;
356                                          t = rect.top;                                          t = rect.top;
357                                          l = rect.left;                                          l = rect.left;
358                                          r = rect.right;                                          r = rect.right;
359                                          ltoa(b,strB,10);                                          ltoa(b,strB,10);
360                                          ltoa(t,strT,10);                                          ltoa(t,strT,10);
361                                          ltoa(r,strR,10);                                          ltoa(r,strR,10);
362                                          ltoa(l,strL,10);                                          ltoa(l,strL,10);
363    
364                                          //get name                                          //get name
365                                          GetWindowText(windowHandle,windowTitle,150);                                          GetWindowText(windowHandle,windowTitle,150);
366    
367                                          ////setup return string                                          ////setup return string
368                                          strcat(result, "MSG=HSHELL_WINDOWCREATED;");                                          strcat(result, "MSG=HSHELL_WINDOWCREATED;");
369                                          strcat( result, "ID=" );                                          strcat( result, "ID=" );
370                                          strcat( result, strWindowId );                                          strcat( result, strWindowId );
371                                          strcat( result, ";" );                                          strcat( result, ";" );
372                                          strcat( result, "TITLE=" );                                          strcat( result, "TITLE=" );
373                                          strcat( result, windowTitle);                                          strcat( result, windowTitle);
374                                          strcat( result, ";" );                                          strcat( result, ";" );
375                                          strcat( result, "POS=" );                                          strcat( result, "POS=" );
376                                          strcat( result, strL);                                          strcat( result, strL);
377                                          strcat( result, "~");                                          strcat( result, "~");
378                                          strcat( result, strT);                                          strcat( result, strT);
379                                          strcat( result, "~");                                          strcat( result, "~");
380                                          strcat( result, strR);                                          strcat( result, strR);
381                                          strcat( result, "~");                                          strcat( result, "~");
382                                          strcat( result, strB);                                          strcat( result, strB);
383                                          strcat( result, ";" );                                          strcat( result, ";" );
384    
385                                          buffer = result;                                          buffer = result;
386    
387                                          break;                                          break;
388    
389                                  case HSHELL_WINDOWDESTROYED:                                  case HSHELL_WINDOWDESTROYED:
390                                                                    
391                                          //get window id                                          //get window id
392                                          windowHandle = (HWND) wParam;                                          windowHandle = (HWND) wParam;
393                                          itoa((int)windowHandle, strWindowId, 10);                                          itoa((int)windowHandle, strWindowId, 10);
394                                                                                    
395                                          //get name                                          //get name
396                                          GetWindowText(windowHandle,windowTitle,150);                                          GetWindowText(windowHandle,windowTitle,150);
397    
398                                          ////setup return string                                          ////setup return string
399                                          strcat(result, "MSG=HSHELL_WINDOWDESTROYED;");                                          strcat(result, "MSG=HSHELL_WINDOWDESTROYED;");
400                                          strcat( result, "ID=" );                                          strcat( result, "ID=" );
401                                          strcat( result, strWindowId );                                          strcat( result, strWindowId );
402                                          strcat( result, ";" );                                          strcat( result, ";" );
403                                          strcat( result, "TITLE=" );                                          strcat( result, "TITLE=" );
404                                          strcat( result, windowTitle);                                          strcat( result, windowTitle);
405                                          strcat( result, ";" );                                          strcat( result, ";" );
406    
407                                          buffer = result;                                          buffer = result;
408    
409                                          break;                                          break;
410                                  default:                                  default:
411                                          break;                                          break;
412                          }                          }
413    
414                  if ( buffer != NULL)                  if ( buffer != NULL)
415                  {                  {
416                          WriteToChannel(buffer);                          WriteToChannel(buffer);
417                  }                  }
418          }          }
419                    
420          return CallNextHookEx(hhook, nCode, wParam, lParam);          return CallNextHookEx(hhook, nCode, wParam, lParam);
421  }  }
422    
423  DLL_EXPORT void SetCbtHook(void)  DLL_EXPORT void SetCbtHook(void)
424  {  {
425          if (!bHooked)          if (!bHooked)
426          {          {
427                  hhook           = SetWindowsHookEx(WH_CBT, (HOOKPROC)CbtProc, hInst, (DWORD)NULL);                  hhook           = SetWindowsHookEx(WH_CBT, (HOOKPROC)CbtProc, hInst, (DWORD)NULL);
428                  bHooked         = true;                  bHooked         = true;
429          }          }
430    
431          if (!bHooked2)          if (!bHooked2)
432          {          {
433                  hhook2          = SetWindowsHookEx(WH_SHELL, (HOOKPROC)ShellProc, hInst, (DWORD)NULL);                    hhook2          = SetWindowsHookEx(WH_SHELL, (HOOKPROC)ShellProc, hInst, (DWORD)NULL);  
434                  bHooked2                = true;                  bHooked2                = true;
435          }          }
436    
437          if (!bHooked3)          if (!bHooked3)
438          {          {
439                  hhook3          = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)CallWndProc, hInst, (DWORD)NULL);                    hhook3          = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)CallWndProc, hInst, (DWORD)NULL);  
440                  bHooked3                = true;                  bHooked3                = true;
441          }          }
442  }  }
443    
444  DLL_EXPORT      void RemoveCbtHook(void)  DLL_EXPORT      void RemoveCbtHook(void)
445  {  {
446          if(bHooked)          if(bHooked)
447          {          {
448                  UnhookWindowsHookEx(hhook);                      UnhookWindowsHookEx(hhook);    
449                  bHooked = false;                  bHooked = false;
450          }          }
451    
452          if(bHooked2)          if(bHooked2)
453          {          {
454                  UnhookWindowsHookEx(hhook2);                      UnhookWindowsHookEx(hhook2);    
455                  bHooked2 = false;                  bHooked2 = false;
456          }          }
457    
458          if(bHooked3)          if(bHooked3)
459          {          {
460                  UnhookWindowsHookEx(hhook3);                      UnhookWindowsHookEx(hhook3);    
461                  bHooked3 = false;                  bHooked3 = false;
462          }          }
463  }  }
464    
465  DLL_EXPORT int GetInstanceCount()  DLL_EXPORT int GetInstanceCount()
466  {  {
467          return iInstanceCount;          return iInstanceCount;
468  }  }
469    
470  int OpenVirtualChannel()  int OpenVirtualChannel()
471  {  {
472                  m_vcHandle = WTSVirtualChannelOpen(WTS_CURRENT_SERVER_HANDLE,WTS_CURRENT_SESSION,CHANNELNAME);                  m_vcHandle = WTSVirtualChannelOpen(WTS_CURRENT_SERVER_HANDLE,WTS_CURRENT_SESSION,CHANNELNAME);
473                                    
474                  if (m_vcHandle==NULL)                  if (m_vcHandle==NULL)
475                  {                  {
476                          return 0;                          return 0;
477                  }                  }
478                  else                  else
479                  {                  {
480                          return 1;                          return 1;
481                  }                  }
482  }  }
483    
484  int CloseVirtualChannel()  int CloseVirtualChannel()
485  {  {
486          BOOL result = WTSVirtualChannelClose(m_vcHandle);          BOOL result = WTSVirtualChannelClose(m_vcHandle);
487        
488           m_vcHandle = NULL;           m_vcHandle = NULL;
489                    
490          if (result)          if (result)
491          {          {
492                  return 1;                  return 1;
493          }          }
494          else          else
495          {          {
496                  return 0;                  return 0;
497          }          }
498  }  }
499    
500  int ChannelIsOpen()  int ChannelIsOpen()
501  {  {
502          if (m_vcHandle==NULL)          if (m_vcHandle==NULL)
503          {          {
504                  return 0;                  return 0;
505          }          }
506          else          else
507          {          {
508                  return 1;                  return 1;
509          }          }
510  }  }
511    
512  int WriteToChannel(PCHAR buffer)  int WriteToChannel(PCHAR buffer)
513  {  {
514      PULONG bytesRead      = 0;      PULONG bytesRead      = 0;
515          PULONG pBytesWritten  = 0;          PULONG pBytesWritten  = 0;
516    
517          BOOL result = WTSVirtualChannelWrite(m_vcHandle,buffer,(ULONG) strlen(buffer),pBytesWritten);          BOOL result = WTSVirtualChannelWrite(m_vcHandle,buffer,(ULONG) strlen(buffer),pBytesWritten);
518                    
519          if (result)          if (result)
520          {          {
521                  return 1;                  return 1;
522          }          }
523          else          else
524          {          {
525                  return 0;                  return 0;
526          }          }
527  }  }

Legend:
Removed from v.918  
changed lines
  Added in v.930

  ViewVC Help
Powered by ViewVC 1.1.26