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

Legend:
Removed from v.938  
changed lines
  Added in v.1007

  ViewVC Help
Powered by ViewVC 1.1.26