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

Legend:
Removed from v.932  
changed lines
  Added in v.933

  ViewVC Help
Powered by ViewVC 1.1.26