/[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 933 by astrand, Thu Jun 30 14:46:14 2005 UTC revision 1061 by astrand, Wed Mar 8 09:36:59 2006 UTC
# Line 1  Line 1 
 //*********************************************************************************  
1  //  //
2  //Title: Terminal Services Window Clipper  // Copyright (C) 2004-2005 Martin Wickett
3  //  //
 //Author: Martin Wickett  
 //  
 //Date: 2004  
 //  
 //*********************************************************************************  
4    
5  #include "hookdll.h"  #include "hookdll.h"
6  #include <windows.h>  #include <windows.h>
7  #include <winuser.h>  #include <winuser.h>
8    #include <stdio.h>
9    #include <stdarg.h>
10    
11  #include "wtsapi32.h"  #include "wtsapi32.h"
12  #include "Cchannel.h"  #include "cchannel.h"
13    
14  #define DLL_EXPORT extern "C" __declspec(dllexport)  #define DLL_EXPORT extern "C" __declspec(dllexport)
15    
16  // Shared DATA  // Shared DATA
17  #pragma data_seg ( "SHAREDDATA" )  #pragma data_seg ( "SHAREDDATA" )
18    
19          // 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
20  int iInstanceCount = 0;  int iInstanceCount = 0;
21  HWND hWnd = 0;  HWND hWnd = 0;
22    
# Line 28  HWND hWnd = 0; Line 24  HWND hWnd = 0;
24    
25  #pragma comment(linker, "/section:SHAREDDATA,rws")  #pragma comment(linker, "/section:SHAREDDATA,rws")
26    
27  bool bHooked = false;  #define snprintf _snprintf
28  bool bHooked2 = false;  
29  bool bHooked3 = false;  HHOOK hCbtProc = 0;
30  HHOOK hhook = 0;                //cbt  HHOOK hShellProc = 0;
31  HHOOK hhook2 = 0;               //shell  HHOOK hWndProc = 0;
 HHOOK hhook3 = 0;               //wnd proc  
32  HINSTANCE hInst = 0;  HINSTANCE hInst = 0;
33  HANDLE m_vcHandle = 0;  HANDLE m_vcHandle = 0;
34    
35  BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call,  
36                        LPVOID lpReserved)  void SendDebug( char *format, ... )
37    {
38        va_list argp;
39        char buf [ 256 ];
40        
41        va_start( argp, format );
42        vsprintf( buf, format, argp );
43        va_end( argp );
44        
45        WriteToChannel( "DEBUG1," );
46        WriteToChannel( buf );
47        WriteToChannel( "\n" );
48    }
49    
50    
51    
52    BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpReserved )
53  {  {
54      switch (ul_reason_for_call) {      switch ( ul_reason_for_call ) {
55      case DLL_PROCESS_ATTACH:          case DLL_PROCESS_ATTACH: {
         {  
56              // remember our instance handle              // remember our instance handle
57              hInst = hinstDLL;              hInst = hinstDLL;
58              ++iInstanceCount;              ++iInstanceCount;
59              OpenVirtualChannel();              OpenVirtualChannel();
60              break;              break;
61          }          }
62            
63      case DLL_THREAD_ATTACH:          case DLL_THREAD_ATTACH:
64          break;          break;
65      case DLL_THREAD_DETACH:          case DLL_THREAD_DETACH:
66          break;          break;
67      case DLL_PROCESS_DETACH:          case DLL_PROCESS_DETACH: {
         {  
68              --iInstanceCount;              --iInstanceCount;
69              CloseVirtualChannel();              CloseVirtualChannel();
70          }          }
71          break;          break;
72      }      }
73        
74      return TRUE;      return TRUE;
75  }  }
76    
77  LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)  LRESULT CALLBACK CallWndProc( int nCode, WPARAM wParam, LPARAM lParam )
78  {  {
79      if (nCode < 0) {      if ( nCode < 0 ) {
80          return CallNextHookEx(hhook3, nCode, wParam, lParam);          return CallNextHookEx( hWndProc, nCode, wParam, lParam );
81      }      }
82        
83      PCHAR buffer = NULL;      char windowTitle[ 150 ] = { ""
84      char windowTitle[150] = { "" };                                };
85      HWND windowHandle = NULL;      HWND windowHandle = NULL;
86      char result[255] = { "" };      HWND windowHandle2 = NULL;
87      char strWindowId[25];      char result[ 255 ] = { ""
88      char type[25];                           };
89        CWPSTRUCT *details = ( CWPSTRUCT * ) lParam;
90      LONG b, t, l, r;      CREATESTRUCT *cs = ( CREATESTRUCT * ) details->lParam;
91      char strB[5];      LONG dwStyle = GetWindowLong( details->hwnd, GWL_STYLE );
92      char strT[5];      WINDOWPOS *wp = ( WINDOWPOS * ) details->lParam;
     char strL[5];  
     char strR[5];  
93      RECT rect;      RECT rect;
94        
95      CWPSTRUCT *details = (CWPSTRUCT *) lParam;      switch ( details->message ) {
96        
97      switch (details->message) {          case WM_WINDOWPOSCHANGED:
98      case WM_SIZING:          if ( !( dwStyle & WS_DLGFRAME ) )
99      case WM_MOVING:              break;
100                
101          windowHandle = details->hwnd;          if ( wp->flags & SWP_NOMOVE && wp->flags & SWP_NOSIZE )
102          //get win name              break;
103          GetWindowText(windowHandle, windowTitle, 150);              
104            if ( !GetWindowRect( details->hwnd, &rect ) ) {
105          //get an id for it              SendDebug( "GetWindowRect failed!\n" );
106          itoa((int) windowHandle, strWindowId, 10);              break;
107            }
108          //get coords          
109          GetWindowRect(windowHandle, &rect);          snprintf( result, sizeof( result ),
110          b = rect.bottom;                    "POSITION1,0x%p,%d,%d,%d,%d,0x%x\n",
111          t = rect.top;                    details->hwnd,
112          l = rect.left;                    rect.left, rect.top,
113          r = rect.right;                    rect.right - rect.left,
114          ltoa(b, strB, 10);                    rect.bottom - rect.top,
115          ltoa(t, strT, 10);                    0 );
116          ltoa(r, strR, 10);          result[ sizeof( result ) - 1 ] = '\0';
117          ltoa(l, strL, 10);          WriteToChannel( result );
118            
         ////setup return string  
         strcat(result, "MSG=CALLWNDPROC_WM_MOVING;");  
         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;  
   
119          break;          break;
120            
121      default:          
122            /* Note: WM_WINDOWPOSCHANGING/WM_WINDOWPOSCHANGED are
123            strange. Sometimes, for example when bringing up the
124            Notepad About dialog, only an WM_WINDOWPOSCHANGING is
125            sent. In some other cases, for exmaple when opening
126            Format->Text in Notepad, both events are sent. Also, for
127            some reason, when closing the Notepad About dialog, an
128            WM_WINDOWPOSCHANGING event is sent which looks just like
129            the event that was sent when the About dialog was opened...  */
130            case WM_WINDOWPOSCHANGING:
131            if ( !( dwStyle & WS_DLGFRAME ) )
132                break;
133                
134            if ( !( wp->flags & SWP_NOZORDER ) ) {
135                snprintf( result, sizeof( result ),
136                          "ZCHANGE1,0x%p,0x%p,0x%x\n",
137                          details->hwnd,
138                          wp->flags & SWP_NOACTIVATE ? wp->hwndInsertAfter : 0,
139                          0 );
140                result[ sizeof( result ) - 1 ] = '\0';
141                WriteToChannel( result );
142            }
143          break;          break;
144      }          
145            
146      if (ChannelIsOpen()) {          case WM_CREATE:
147          if (buffer != NULL) {          if ( cs->style & WS_DLGFRAME ) {
148              WriteToChannel(buffer);          
149                if ( cs->cx < 0 || cs->cy < 0 )
150                    break;
151                    
152                snprintf( result, sizeof( result ),
153                          "CREATE1,0x%p,0x%x\n",
154                          details->hwnd, 0 );
155                result[ sizeof( result ) - 1 ] = '\0';
156                WriteToChannel( result );
157                
158                snprintf( result, sizeof( result ),
159                          "SETSTATE1,0x%p,%s,0x%x,0x%x\n",
160                          details->hwnd,
161                          cs->lpszName,
162                          1,         // FIXME: Check for WS_MAXIMIZE/WS_MINIMIZE
163                          0 );
164                result[ sizeof( result ) - 1 ] = '\0';
165                WriteToChannel( result );
166                
167                snprintf( result, sizeof( result ),
168                          "POSITION1,0x%p,%d,%d,%d,%d,0x%x\n",
169                          details->hwnd,
170                          cs->x,
171                          cs->y,
172                          cs->cx,
173                          cs->cy,
174                          0 );
175                result[ sizeof( result ) - 1 ] = '\0';
176                WriteToChannel( result );
177                
178          }          }
179            break;
180            
181            
182            case WM_DESTROY:
183            if ( dwStyle & WS_DLGFRAME ) {
184                snprintf( result, sizeof( result ),
185                          "DESTROY1,0x%p,0x%x\n",
186                          details->hwnd, 0 );
187                result[ sizeof( result ) - 1 ] = '\0';
188                WriteToChannel( result );
189            }
190            
191            break;
192            
193            
194            default:
195            break;
196      }      }
197        
198      return CallNextHookEx(hhook3, nCode, wParam, lParam);      return CallNextHookEx( hWndProc, nCode, wParam, lParam );
199  }  }
200    
201  LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam)  LRESULT CALLBACK CbtProc( int nCode, WPARAM wParam, LPARAM lParam )
202  {  {
203      if (nCode < 0) {      if ( nCode < 0 ) {
204          return CallNextHookEx(hhook, nCode, wParam, lParam);          return CallNextHookEx( hCbtProc, nCode, wParam, lParam );
205      }      }
206        
207        char windowTitle[ 150 ] = { ""
208      PCHAR buffer = NULL;                                };
   
   
     char windowTitle[150] = { "" };  
209      HWND windowHandle = NULL;      HWND windowHandle = NULL;
210      char result[255] = { "" };      char result[ 255 ] = { ""
211      char strWindowId[25];                           };
212      char type[25];      switch ( nCode ) {
213            case HCBT_MINMAX:
214            
215            if ( ( LOWORD( lParam ) == SW_SHOWMINIMIZED )
216                    || ( LOWORD( lParam ) == SW_MINIMIZE ) ) {
217                MessageBox( 0, "Minimizing windows is not allowed in this version. Sorry!", "SeamlessRDP", MB_OK );
218                return 1;
219            }
220            
221            GetWindowText( ( HWND ) wParam, windowTitle, 150 );
222            
223            snprintf( result, sizeof( result ),
224                      "SETSTATE1,0x%p,%s,0x%x,0x%x\n",
225                      ( HWND ) wParam,
226                      windowTitle,
227                      LOWORD( lParam ),
228                      0 );
229            result[ sizeof( result ) - 1 ] = '\0';
230            WriteToChannel( result );
231            break;
232            
233            
234            default:
235            break;
236        }
237        
238        
239        
240        return CallNextHookEx( hCbtProc, nCode, wParam, lParam );
241    }
242    
243    
244    LRESULT CALLBACK ShellProc( int nCode, WPARAM wParam, LPARAM lParam )
245    {
246        if ( nCode < 0 ) {
247            return CallNextHookEx( hShellProc, nCode, wParam, lParam );
248        }
249        
250        char windowTitle[ 150 ] = { ""
251                                  };
252        HWND windowHandle = NULL;
253        char result[ 255 ] = { ""
254                             };
255        char strWindowId[ 25 ];
256      LONG b, t, l, r;      LONG b, t, l, r;
257      char strB[5];      char strW[ 5 ];
258      char strT[5];      char strY[ 5 ];
259      char strL[5];      char strX[ 5 ];
260      char strR[5];      char strH[ 5 ];
261      RECT rect;      RECT rect;
262        
263      int i = 0;                  //tmp      switch ( nCode ) {
264            case HSHELL_WINDOWCREATED:
265      switch (nCode) {          
266      case HCBT_MINMAX:          //get window id
267            windowHandle = ( HWND ) wParam;
268          windowHandle = (HWND) wParam;          itoa( ( int ) windowHandle, strWindowId, 10 );
269          //get win name          
         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);  
   
270          //get coords          //get coords
271          GetWindowRect(windowHandle, &rect);          GetWindowRect( windowHandle, &rect );
272          b = rect.bottom;          b = rect.bottom;
273          t = rect.top;          t = rect.top;
274          l = rect.left;          l = rect.left;
275          r = rect.right;          r = rect.right;
276          ltoa(b, strB, 10);          ltoa( b - t, strH, 10 );
277          ltoa(t, strT, 10);          ltoa( t, strY, 10 );
278          ltoa(r, strR, 10);          ltoa( r - l, strW, 10 );
279          ltoa(l, strL, 10);          ltoa( l, strX, 10 );
280            
281          //get name          //get name
282          GetWindowText(windowHandle, windowTitle, 150);          GetWindowText( windowHandle, windowTitle, 150 );
283            
284          ////setup return string          ////setup return string
285          strcat(result, "MSG=HCBT_MINMAX;");          strcat( result, "MSG=HSHELL_WINDOWCREATED;OP=0;" );
286          strcat(result, "ID=");          strcat( result, "ID=" );
287          strcat(result, strWindowId);          strcat( result, strWindowId );
288          strcat(result, ";");          strcat( result, ";" );
289          strcat(result, "TITLE=");          strcat( result, "TITLE=" );
290          strcat(result, windowTitle);          strcat( result, windowTitle );
291          strcat(result, ";");          strcat( result, ";" );
292          strcat(result, "POS=");          strcat( result, "X=" );
293          strcat(result, strL);          strcat( result, strX );
294          strcat(result, "~");          strcat( result, ";" );
295          strcat(result, strT);          strcat( result, "Y=" );
296          strcat(result, "~");          strcat( result, strY );
297          strcat(result, strR);          strcat( result, ";" );
298          strcat(result, "~");          strcat( result, "H=" );
299          strcat(result, strB);          strcat( result, strH );
300          strcat(result, ";");          strcat( result, ";" );
301          strcat(result, "TYPE=");          strcat( result, "W=" );
302          strcat(result, type);          strcat( result, strW );
303          strcat(result, ";");          strcat( result, "." );
304            WriteToChannel( 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;  
   
305          break;          break;
306            
307      case HCBT_MOVESIZE:          case HSHELL_WINDOWDESTROYED:
308            
309          windowHandle = (HWND) wParam;          //get window id
310          //get win name          windowHandle = ( HWND ) wParam;
311          GetWindowText(windowHandle, windowTitle, 150);          itoa( ( int ) windowHandle, strWindowId, 10 );
312            
         //get an id for it  
         itoa((int) windowHandle, strWindowId, 10);  
   
313          //get coords          //get coords
314          GetWindowRect(windowHandle, &rect);          GetWindowRect( windowHandle, &rect );
315          b = rect.bottom;          b = rect.bottom;
316          t = rect.top;          t = rect.top;
317          l = rect.left;          l = rect.left;
318          r = rect.right;          r = rect.right;
319          ltoa(b, strB, 10);          ltoa( b - t, strH, 10 );
320          ltoa(t, strT, 10);          ltoa( t, strY, 10 );
321          ltoa(r, strR, 10);          ltoa( r - l, strW, 10 );
322          ltoa(l, strL, 10);          ltoa( l, strX, 10 );
323            
324          //get name          //get name
325          GetWindowText(windowHandle, windowTitle, 150);          GetWindowText( windowHandle, windowTitle, 150 );
326            
327          ////setup return string          ////setup return string
328          strcat(result, "MSG=HCBT_MOVESIZE;");          strcat( result, "MSG=HSHELL_WINDOWDESTROYED;OP=1;" );
329          strcat(result, "ID=");          strcat( result, "ID=" );
330          strcat(result, strWindowId);          strcat( result, strWindowId );
331          strcat(result, ";");          strcat( result, ";" );
332          strcat(result, "TITLE=");          strcat( result, "TITLE=" );
333          strcat(result, windowTitle);          strcat( result, windowTitle );
334          strcat(result, ";");          strcat( result, ";" );
335          strcat(result, "POS=");          strcat( result, "X=" );
336          strcat(result, strL);          strcat( result, strX );
337          strcat(result, "~");          strcat( result, ";" );
338          strcat(result, strT);          strcat( result, "Y=" );
339          strcat(result, "~");          strcat( result, strY );
340          strcat(result, strR);          strcat( result, ";" );
341          strcat(result, "~");          strcat( result, "H=" );
342          strcat(result, strB);          strcat( result, strH );
343          strcat(result, ";");          strcat( result, ";" );
344            strcat( result, "W=" );
345          buffer = result;          strcat( result, strW );
346            strcat( result, "." );
347          break;          WriteToChannel( result );
     case HCBT_SETFOCUS:  
         //buffer = "HCBT_SETFOCUS";  
         //not needed yet  
         break;  
     default:  
348          break;          break;
349      }          
350            
     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;  
         char strB[5];  
         char strT[5];  
         char strL[5];  
         char strR[5];  
         RECT rect;  
   
         switch (nCode) {  
         case HSHELL_WINDOWCREATED:  
   
             //get window id  
             windowHandle = (HWND) wParam;  
             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=HSHELL_WINDOWCREATED;");  
             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 HSHELL_WINDOWDESTROYED:  
   
             //get window id  
             windowHandle = (HWND) wParam;  
             itoa((int) windowHandle, strWindowId, 10);  
   
             //get name  
             GetWindowText(windowHandle, windowTitle, 150);  
   
             ////setup return string  
             strcat(result, "MSG=HSHELL_WINDOWDESTROYED;");  
             strcat(result, "ID=");  
             strcat(result, strWindowId);  
             strcat(result, ";");  
             strcat(result, "TITLE=");  
             strcat(result, windowTitle);  
             strcat(result, ";");  
   
             buffer = result;  
   
             break;  
351          default:          default:
352              break;          break;
         }  
   
         if (buffer != NULL) {  
             WriteToChannel(buffer);  
         }  
353      }      }
354        
355      return CallNextHookEx(hhook, nCode, wParam, lParam);      
356        return CallNextHookEx( hShellProc, nCode, wParam, lParam );
357  }  }
358    
359  DLL_EXPORT void SetCbtHook(void)  DLL_EXPORT void SetHooks( void )
360  {  {
361      if (!bHooked) {      if ( !hCbtProc ) {
362          hhook =          hCbtProc = SetWindowsHookEx( WH_CBT, ( HOOKPROC ) CbtProc, hInst, ( DWORD ) NULL );
             SetWindowsHookEx(WH_CBT, (HOOKPROC) CbtProc, hInst, (DWORD) NULL);  
         bHooked = true;  
363      }      }
364        
365      if (!bHooked2) {  #if 0
366          hhook2 =      if ( !hShellProc ) {
367              SetWindowsHookEx(WH_SHELL, (HOOKPROC) ShellProc, hInst,          hShellProc = SetWindowsHookEx( WH_SHELL, ( HOOKPROC ) ShellProc, hInst, ( DWORD ) NULL );
                              (DWORD) NULL);  
         bHooked2 = true;  
368      }      }
369    #endif
370      if (!bHooked3) {      
371          hhook3 =      if ( !hWndProc ) {
372              SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC) CallWndProc, hInst,          hWndProc = SetWindowsHookEx( WH_CALLWNDPROC, ( HOOKPROC ) CallWndProc, hInst, ( DWORD ) NULL );
                              (DWORD) NULL);  
         bHooked3 = true;  
373      }      }
374  }  }
375    
376  DLL_EXPORT void RemoveCbtHook(void)  DLL_EXPORT void RemoveHooks( void )
377  {  {
378      if (bHooked) {      if ( hCbtProc ) {
379          UnhookWindowsHookEx(hhook);          UnhookWindowsHookEx( hCbtProc );
         bHooked = false;  
380      }      }
381        
382      if (bHooked2) {      if ( hShellProc ) {
383          UnhookWindowsHookEx(hhook2);          UnhookWindowsHookEx( hShellProc );
         bHooked2 = false;  
384      }      }
385        
386      if (bHooked3) {      if ( hWndProc ) {
387          UnhookWindowsHookEx(hhook3);          UnhookWindowsHookEx( hWndProc );
         bHooked3 = false;  
388      }      }
389  }  }
390    
# Line 458  DLL_EXPORT int GetInstanceCount() Line 395  DLL_EXPORT int GetInstanceCount()
395    
396  int OpenVirtualChannel()  int OpenVirtualChannel()
397  {  {
398      m_vcHandle =      m_vcHandle = WTSVirtualChannelOpen( WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, CHANNELNAME );
399          WTSVirtualChannelOpen(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION,      
400                                CHANNELNAME);      if ( m_vcHandle == NULL ) {
   
     if (m_vcHandle == NULL) {  
401          return 0;          return 0;
402      }      } else {
     else {  
403          return 1;          return 1;
404      }      }
405  }  }
406    
407  int CloseVirtualChannel()  int CloseVirtualChannel()
408  {  {
409      BOOL result = WTSVirtualChannelClose(m_vcHandle);      BOOL result = WTSVirtualChannelClose( m_vcHandle );
410        
411      m_vcHandle = NULL;      m_vcHandle = NULL;
412        
413      if (result) {      if ( result ) {
414          return 1;          return 1;
415      }      } else {
     else {  
416          return 0;          return 0;
417      }      }
418  }  }
419    
420  int ChannelIsOpen()  int ChannelIsOpen()
421  {  {
422      if (m_vcHandle == NULL) {      if ( m_vcHandle == NULL ) {
423          return 0;          return 0;
424      }      } else {
     else {  
425          return 1;          return 1;
426      }      }
427  }  }
428    
429  int WriteToChannel(PCHAR buffer)  int WriteToChannel( PCHAR buffer )
430  {  {
431      PULONG bytesRead = 0;      PULONG bytesRead = 0;
432      PULONG pBytesWritten = 0;      PULONG pBytesWritten = 0;
433        
434      BOOL result =      if ( !ChannelIsOpen() )
         WTSVirtualChannelWrite(m_vcHandle, buffer, (ULONG) strlen(buffer),  
                                pBytesWritten);  
   
     if (result) {  
435          return 1;          return 1;
436      }          
437      else {      BOOL result = WTSVirtualChannelWrite( m_vcHandle, buffer, ( ULONG ) strlen( buffer ), pBytesWritten );
438        
439        if ( result ) {
440            return 1;
441        } else {
442          return 0;          return 0;
443      }      }
444  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26