/[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 937 by astrand, Fri Jul 1 06:50:52 2005 UTC revision 1008 by astrand, Tue Aug 30 12:31:58 2005 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" )
# 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;
93      char strL[5];      RECT *rect = ( RECT * ) details->lParam;
94      char strR[5];      
95      RECT rect;      switch ( details->message ) {
96        
97      CWPSTRUCT *details = (CWPSTRUCT *) lParam;          case WM_SIZING:
98            case WM_MOVING:
99      switch (details->message) {          if ( !( dwStyle & WS_VISIBLE ) )
100      case WM_SIZING:              break;
101      case WM_MOVING:              
102            if ( !( dwStyle & WS_DLGFRAME ) )
103          windowHandle = details->hwnd;              break;
104          //get win name              
105          GetWindowText(windowHandle, windowTitle, 150);          snprintf( result, sizeof( result ),
106                      "POSITION1,0x%p,%d,%d,%d,%d,0x%x",
107          //get an id for it                    details->hwnd,
108          itoa((int) windowHandle, strWindowId, 10);                    rect->left, rect->top,
109                      rect->right - rect->left,
110          //get coords                    rect->bottom - rect->top,
111          GetWindowRect(windowHandle, &rect);                    0 );
112          b = rect.bottom;          result[ sizeof( result ) - 1 ] = '\0';
113          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;  
   
114          break;          break;
115            
116      default:          
117            /* Note: WM_WINDOWPOSCHANGING/WM_WINDOWPOSCHANGED are
118            strange. Sometimes, for example when bringing up the
119            Notepad About dialog, only an WM_WINDOWPOSCHANGING is
120            sent. In some other cases, for exmaple when opening
121            Format->Text in Notepad, both events are sent. Also, for
122            some reason, when closing the Notepad About dialog, an
123            WM_WINDOWPOSCHANGING event is sent which looks just like
124            the event that was sent when the About dialog was opened...  */
125            case WM_WINDOWPOSCHANGING:
126            
127            if ( !( dwStyle & WS_VISIBLE ) )
128                break;
129                
130            if ( !( dwStyle & WS_DLGFRAME ) )
131                break;
132                
133            if ( !( wp->flags & SWP_NOZORDER ) ) {
134                snprintf( result, sizeof( result ),
135                          "ZCHANGE1,0x%p,0x%p,0x%x\n",
136                          details->hwnd,
137                          wp->flags & SWP_NOACTIVATE ? wp->hwndInsertAfter : 0,
138                          0 );
139                result[ sizeof( result ) - 1 ] = '\0';
140                WriteToChannel( result );
141            }
142          break;          break;
143      }          
144            
145      if (ChannelIsOpen()) {          case WM_CREATE:
146          if (buffer != NULL) {          if ( cs->style & WS_DLGFRAME ) {
147              WriteToChannel(buffer);          
148                snprintf( result, sizeof( result ),
149                          "CREATE1,0x%p,0x%x\n",
150                          details->hwnd, 0 );
151                result[ sizeof( result ) - 1 ] = '\0';
152                WriteToChannel( result );
153                
154                snprintf( result, sizeof( result ),
155                          "SETSTATE1,0x%p,%s,0x%x,0x%x\n",
156                          details->hwnd,
157                          cs->lpszName,
158                          1,     // FIXME: Check for WS_MAXIMIZE/WS_MINIMIZE
159                          0 );
160                result[ sizeof( result ) - 1 ] = '\0';
161                WriteToChannel( result );
162                
163                snprintf( result, sizeof( result ),
164                          "POSITION1,0x%p,%d,%d,%d,%d,0x%x",
165                          details->hwnd,
166                          cs->x,
167                          cs->y,
168                          cs->cx,
169                          cs->cy,
170                          0 );
171                result[ sizeof( result ) - 1 ] = '\0';
172                WriteToChannel( result );
173                
174          }          }
175            break;
176            
177            
178            case WM_DESTROY:
179            if ( dwStyle & WS_DLGFRAME ) {
180                snprintf( result, sizeof( result ),
181                          "DESTROY1,0x%p,0x%x\n",
182                          details->hwnd, 0 );
183                result[ sizeof( result ) - 1 ] = '\0';
184                WriteToChannel( result );
185            }
186            
187            break;
188            
189            
190            default:
191            break;
192      }      }
193        
194      return CallNextHookEx(hhook3, nCode, wParam, lParam);      return CallNextHookEx( hWndProc, nCode, wParam, lParam );
195  }  }
196    
197  LRESULT CALLBACK CbtProc(int nCode, WPARAM wParam, LPARAM lParam)  LRESULT CALLBACK CbtProc( int nCode, WPARAM wParam, LPARAM lParam )
198  {  {
199      if (nCode < 0) {      if ( nCode < 0 ) {
200          return CallNextHookEx(hhook, nCode, wParam, lParam);          return CallNextHookEx( hCbtProc, nCode, wParam, lParam );
201      }      }
202        
203        char windowTitle[ 150 ] = { ""
204      PCHAR buffer = NULL;                                };
   
   
     char windowTitle[150] = { "" };  
205      HWND windowHandle = NULL;      HWND windowHandle = NULL;
206      char result[255] = { "" };      char result[ 255 ] = { ""
207      char strWindowId[25];                           };
208      char type[25];      switch ( nCode ) {
209            case HCBT_MINMAX:
210            
211            if ( ( LOWORD( lParam ) == SW_SHOWMINIMIZED )
212                    || ( LOWORD( lParam ) == SW_MINIMIZE ) ) {
213                MessageBox( 0, "Minimizing windows is not allowed in this version. Sorry!", "SeamlessRDP", MB_OK );
214                return 1;
215            }
216            
217            GetWindowText( ( HWND ) wParam, windowTitle, 150 );
218            
219            snprintf( result, sizeof( result ),
220                      "SETSTATE1,0x%p,%s,0x%x,0x%x\n",
221                      ( HWND ) wParam,
222                      windowTitle,
223                      LOWORD( lParam ),
224                      0 );
225            result[ sizeof( result ) - 1 ] = '\0';
226            WriteToChannel( result );
227            break;
228            
229            
230            default:
231            break;
232        }
233        
234        
235        
236        return CallNextHookEx( hCbtProc, nCode, wParam, lParam );
237    }
238    
239    
240    LRESULT CALLBACK ShellProc( int nCode, WPARAM wParam, LPARAM lParam )
241    {
242        if ( nCode < 0 ) {
243            return CallNextHookEx( hShellProc, nCode, wParam, lParam );
244        }
245        
246        char windowTitle[ 150 ] = { ""
247                                  };
248        HWND windowHandle = NULL;
249        char result[ 255 ] = { ""
250                             };
251        char strWindowId[ 25 ];
252      LONG b, t, l, r;      LONG b, t, l, r;
253      char strB[5];      char strW[ 5 ];
254      char strT[5];      char strY[ 5 ];
255      char strL[5];      char strX[ 5 ];
256      char strR[5];      char strH[ 5 ];
257      RECT rect;      RECT rect;
258        
259      int i = 0;                  //tmp      switch ( nCode ) {
260            case HSHELL_WINDOWCREATED:
261      switch (nCode) {          
262      case HCBT_MINMAX:          //get window id
263            windowHandle = ( HWND ) wParam;
264          windowHandle = (HWND) wParam;          itoa( ( int ) windowHandle, strWindowId, 10 );
265          //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);  
   
266          //get coords          //get coords
267          GetWindowRect(windowHandle, &rect);          GetWindowRect( windowHandle, &rect );
268          b = rect.bottom;          b = rect.bottom;
269          t = rect.top;          t = rect.top;
270          l = rect.left;          l = rect.left;
271          r = rect.right;          r = rect.right;
272          ltoa(b, strB, 10);          ltoa( b - t, strH, 10 );
273          ltoa(t, strT, 10);          ltoa( t, strY, 10 );
274          ltoa(r, strR, 10);          ltoa( r - l, strW, 10 );
275          ltoa(l, strL, 10);          ltoa( l, strX, 10 );
276            
277          //get name          //get name
278          GetWindowText(windowHandle, windowTitle, 150);          GetWindowText( windowHandle, windowTitle, 150 );
279            
280          ////setup return string          ////setup return string
281          strcat(result, "MSG=HCBT_MINMAX;");          strcat( result, "MSG=HSHELL_WINDOWCREATED;OP=0;" );
282          strcat(result, "ID=");          strcat( result, "ID=" );
283          strcat(result, strWindowId);          strcat( result, strWindowId );
284          strcat(result, ";");          strcat( result, ";" );
285          strcat(result, "TITLE=");          strcat( result, "TITLE=" );
286          strcat(result, windowTitle);          strcat( result, windowTitle );
287          strcat(result, ";");          strcat( result, ";" );
288          strcat(result, "POS=");          strcat( result, "X=" );
289          strcat(result, strL);          strcat( result, strX );
290          strcat(result, "~");          strcat( result, ";" );
291          strcat(result, strT);          strcat( result, "Y=" );
292          strcat(result, "~");          strcat( result, strY );
293          strcat(result, strR);          strcat( result, ";" );
294          strcat(result, "~");          strcat( result, "H=" );
295          strcat(result, strB);          strcat( result, strH );
296          strcat(result, ";");          strcat( result, ";" );
297          strcat(result, "TYPE=");          strcat( result, "W=" );
298          strcat(result, type);          strcat( result, strW );
299          strcat(result, ";");          strcat( result, "." );
300            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;  
   
301          break;          break;
302            
303      case HCBT_MOVESIZE:          case HSHELL_WINDOWDESTROYED:
304            
305          windowHandle = (HWND) wParam;          //get window id
306          //get win name          windowHandle = ( HWND ) wParam;
307          GetWindowText(windowHandle, windowTitle, 150);          itoa( ( int ) windowHandle, strWindowId, 10 );
308            
         //get an id for it  
         itoa((int) windowHandle, strWindowId, 10);  
   
309          //get coords          //get coords
310          GetWindowRect(windowHandle, &rect);          GetWindowRect( windowHandle, &rect );
311          b = rect.bottom;          b = rect.bottom;
312          t = rect.top;          t = rect.top;
313          l = rect.left;          l = rect.left;
314          r = rect.right;          r = rect.right;
315          ltoa(b, strB, 10);          ltoa( b - t, strH, 10 );
316          ltoa(t, strT, 10);          ltoa( t, strY, 10 );
317          ltoa(r, strR, 10);          ltoa( r - l, strW, 10 );
318          ltoa(l, strL, 10);          ltoa( l, strX, 10 );
319            
320          //get name          //get name
321          GetWindowText(windowHandle, windowTitle, 150);          GetWindowText( windowHandle, windowTitle, 150 );
322            
323          ////setup return string          ////setup return string
324          strcat(result, "MSG=HCBT_MOVESIZE;");          strcat( result, "MSG=HSHELL_WINDOWDESTROYED;OP=1;" );
325          strcat(result, "ID=");          strcat( result, "ID=" );
326          strcat(result, strWindowId);          strcat( result, strWindowId );
327          strcat(result, ";");          strcat( result, ";" );
328          strcat(result, "TITLE=");          strcat( result, "TITLE=" );
329          strcat(result, windowTitle);          strcat( result, windowTitle );
330          strcat(result, ";");          strcat( result, ";" );
331          strcat(result, "POS=");          strcat( result, "X=" );
332          strcat(result, strL);          strcat( result, strX );
333          strcat(result, "~");          strcat( result, ";" );
334          strcat(result, strT);          strcat( result, "Y=" );
335          strcat(result, "~");          strcat( result, strY );
336          strcat(result, strR);          strcat( result, ";" );
337          strcat(result, "~");          strcat( result, "H=" );
338          strcat(result, strB);          strcat( result, strH );
339          strcat(result, ";");          strcat( result, ";" );
340            strcat( result, "W=" );
341          buffer = result;          strcat( result, strW );
342            strcat( result, "." );
343          break;          WriteToChannel( result );
     case HCBT_SETFOCUS:  
         //buffer = "HCBT_SETFOCUS";  
         //not needed yet  
         break;  
     default:  
344          break;          break;
345      }          
346            
     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;  
347          default:          default:
348              break;          break;
         }  
   
         if (buffer != NULL) {  
             WriteToChannel(buffer);  
         }  
349      }      }
350        
351      return CallNextHookEx(hhook, nCode, wParam, lParam);      
352        return CallNextHookEx( hShellProc, nCode, wParam, lParam );
353  }  }
354    
355  DLL_EXPORT void SetCbtHook(void)  DLL_EXPORT void SetHooks( void )
356  {  {
357      if (!bHooked) {      if ( !hCbtProc ) {
358          hhook =          hCbtProc = SetWindowsHookEx( WH_CBT, ( HOOKPROC ) CbtProc, hInst, ( DWORD ) NULL );
             SetWindowsHookEx(WH_CBT, (HOOKPROC) CbtProc, hInst, (DWORD) NULL);  
         bHooked = true;  
     }  
   
     if (!bHooked2) {  
         hhook2 =  
             SetWindowsHookEx(WH_SHELL, (HOOKPROC) ShellProc, hInst,  
                              (DWORD) NULL);  
         bHooked2 = true;  
359      }      }
360        
361      if (!bHooked3) {  #if 0
362          hhook3 =      if ( !hShellProc ) {
363              SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC) CallWndProc, hInst,          hShellProc = SetWindowsHookEx( WH_SHELL, ( HOOKPROC ) ShellProc, hInst, ( DWORD ) NULL );
364                               (DWORD) NULL);      }
365          bHooked3 = true;  #endif
366        
367        if ( !hWndProc ) {
368            hWndProc = SetWindowsHookEx( WH_CALLWNDPROC, ( HOOKPROC ) CallWndProc, hInst, ( DWORD ) NULL );
369      }      }
370  }  }
371    
372  DLL_EXPORT void RemoveCbtHook(void)  DLL_EXPORT void RemoveHooks( void )
373  {  {
374      if (bHooked) {      if ( hCbtProc ) {
375          UnhookWindowsHookEx(hhook);          UnhookWindowsHookEx( hCbtProc );
         bHooked = false;  
376      }      }
377        
378      if (bHooked2) {      if ( hShellProc ) {
379          UnhookWindowsHookEx(hhook2);          UnhookWindowsHookEx( hShellProc );
380          bHooked2 = false;      }
381      }      
382        if ( hWndProc ) {
383      if (bHooked3) {          UnhookWindowsHookEx( hWndProc );
         UnhookWindowsHookEx(hhook3);  
         bHooked3 = false;  
384      }      }
385  }  }
386    
# Line 456  DLL_EXPORT int GetInstanceCount() Line 391  DLL_EXPORT int GetInstanceCount()
391    
392  int OpenVirtualChannel()  int OpenVirtualChannel()
393  {  {
394      m_vcHandle =      m_vcHandle = WTSVirtualChannelOpen( WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, CHANNELNAME );
395          WTSVirtualChannelOpen(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION,      
396                                CHANNELNAME);      if ( m_vcHandle == NULL ) {
   
     if (m_vcHandle == NULL) {  
397          return 0;          return 0;
398      } else {      } else {
399          return 1;          return 1;
# Line 469  int OpenVirtualChannel() Line 402  int OpenVirtualChannel()
402    
403  int CloseVirtualChannel()  int CloseVirtualChannel()
404  {  {
405      BOOL result = WTSVirtualChannelClose(m_vcHandle);      BOOL result = WTSVirtualChannelClose( m_vcHandle );
406        
407      m_vcHandle = NULL;      m_vcHandle = NULL;
408        
409      if (result) {      if ( result ) {
410          return 1;          return 1;
411      } else {      } else {
412          return 0;          return 0;
# Line 482  int CloseVirtualChannel() Line 415  int CloseVirtualChannel()
415    
416  int ChannelIsOpen()  int ChannelIsOpen()
417  {  {
418      if (m_vcHandle == NULL) {      if ( m_vcHandle == NULL ) {
419          return 0;          return 0;
420      } else {      } else {
421          return 1;          return 1;
422      }      }
423  }  }
424    
425  int WriteToChannel(PCHAR buffer)  int WriteToChannel( PCHAR buffer )
426  {  {
427      PULONG bytesRead = 0;      PULONG bytesRead = 0;
428      PULONG pBytesWritten = 0;      PULONG pBytesWritten = 0;
429        
430      BOOL result =      if ( !ChannelIsOpen() )
431          WTSVirtualChannelWrite(m_vcHandle, buffer, (ULONG) strlen(buffer),          return 1;
432                                 pBytesWritten);          
433        BOOL result = WTSVirtualChannelWrite( m_vcHandle, buffer, ( ULONG ) strlen( buffer ), pBytesWritten );
434      if (result) {      
435        if ( result ) {
436          return 1;          return 1;
437      } else {      } else {
438          return 0;          return 0;

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

  ViewVC Help
Powered by ViewVC 1.1.26