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

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

  ViewVC Help
Powered by ViewVC 1.1.26