/[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

Annotation of /sourceforge.net/trunk/seamlessrdp/ServerExe/HookDll/hookdll.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 995 - (hide annotations)
Mon Aug 29 09:10:13 2005 UTC (18 years, 9 months ago) by astrand
File size: 19290 byte(s)
Added temporary stubs for WM_CREATE and WM_DESTROY.

1 astrand 930 //
2 astrand 938 // Copyright (C) 2004-2005 Martin Wickett
3 astrand 930 //
4    
5     #include "hookdll.h"
6     #include <windows.h>
7     #include <winuser.h>
8 astrand 995 #include <stdio.h>
9 astrand 930
10     #include "wtsapi32.h"
11     #include "Cchannel.h"
12    
13 astrand 993 #define DLL_EXPORT extern "C" __declspec(dllexport)
14 astrand 930
15     // Shared DATA
16     #pragma data_seg ( "SHAREDDATA" )
17    
18 astrand 937 // this is the total number of processes this dll is currently attached to
19 astrand 933 int iInstanceCount = 0;
20     HWND hWnd = 0;
21 astrand 930
22     #pragma data_seg ()
23    
24     #pragma comment(linker, "/section:SHAREDDATA,rws")
25    
26 astrand 933 bool bHooked = false;
27     bool bHooked2 = false;
28     bool bHooked3 = false;
29 astrand 994 HHOOK hhook = 0; //cbt
30     HHOOK hhook2 = 0; //shell
31     HHOOK hhook3 = 0; //wnd proc
32 astrand 933 HINSTANCE hInst = 0;
33     HANDLE m_vcHandle = 0;
34 astrand 930
35 astrand 994 BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpReserved )
36 astrand 930 {
37 astrand 993 switch ( ul_reason_for_call ) {
38     case DLL_PROCESS_ATTACH: {
39 astrand 933 // remember our instance handle
40     hInst = hinstDLL;
41     ++iInstanceCount;
42     OpenVirtualChannel();
43     break;
44     }
45 astrand 993
46     case DLL_THREAD_ATTACH:
47 astrand 933 break;
48 astrand 993 case DLL_THREAD_DETACH:
49 astrand 933 break;
50 astrand 993 case DLL_PROCESS_DETACH: {
51 astrand 933 --iInstanceCount;
52     CloseVirtualChannel();
53     }
54     break;
55 astrand 930 }
56 astrand 993
57 astrand 930 return TRUE;
58     }
59    
60 astrand 993 LRESULT CALLBACK CallWndProc( int nCode, WPARAM wParam, LPARAM lParam )
61 astrand 930 {
62 astrand 993 if ( nCode < 0 ) {
63     return CallNextHookEx( hhook3, nCode, wParam, lParam );
64 astrand 933 }
65 astrand 993
66 astrand 933 PCHAR buffer = NULL;
67 astrand 993 char windowTitle[ 150 ] = { ""
68     };
69 astrand 933 HWND windowHandle = NULL;
70 astrand 994 HWND windowHandle2 = NULL;
71 astrand 993 char result[ 255 ] = { ""
72     };
73     char strWindowId[ 25 ];
74     char type[ 25 ];
75    
76 astrand 933 LONG b, t, l, r;
77 astrand 994 char strX[ 5 ];
78     char strY[ 5 ];
79     char strW[ 5 ];
80     char strH[ 5 ];
81 astrand 933 RECT rect;
82 astrand 993
83     CWPSTRUCT *details = ( CWPSTRUCT * ) lParam;
84 astrand 995 CREATESTRUCT *cs = ( CREATESTRUCT * ) details->lParam;
85     LONG dwStyle = GetWindowLong( details->hwnd, GWL_STYLE );
86 astrand 993
87     switch ( details->message ) {
88     case WM_SIZING:
89 astrand 994 windowHandle = details->hwnd;
90     //get win name
91     GetWindowText( windowHandle, windowTitle, 150 );
92    
93     //get an id for it
94     itoa( ( int ) windowHandle, strWindowId, 10 );
95    
96     //get coords
97     GetWindowRect( windowHandle, &rect );
98     b = rect.bottom;
99     t = rect.top;
100     l = rect.left;
101     r = rect.right;
102     ltoa( b - t, strH, 10 );
103     ltoa( t, strY, 10 );
104     ltoa( r - l, strW, 10 );
105     ltoa( l, strX, 10 );
106    
107     ////setup return string
108     strcat( result, "MSG=CALLWNDPROC_WM_SIZING;OP=6;" );
109     strcat( result, "ID=" );
110     strcat( result, strWindowId );
111     strcat( result, ";" );
112     strcat( result, "TITLE=" );
113     strcat( result, windowTitle );
114     strcat( result, ";" );
115     strcat( result, "X=" );
116     strcat( result, strX );
117     strcat( result, ";" );
118     strcat( result, "Y=" );
119     strcat( result, strY );
120     strcat( result, ";" );
121     strcat( result, "H=" );
122     strcat( result, strH );
123     strcat( result, ";" );
124     strcat( result, "W=" );
125     strcat( result, strW );
126     strcat( result, "." );
127    
128     buffer = result;
129    
130     break;
131 astrand 993 case WM_MOVING:
132    
133 astrand 933 windowHandle = details->hwnd;
134     //get win name
135 astrand 993 GetWindowText( windowHandle, windowTitle, 150 );
136    
137 astrand 933 //get an id for it
138 astrand 993 itoa( ( int ) windowHandle, strWindowId, 10 );
139    
140 astrand 933 //get coords
141 astrand 993 GetWindowRect( windowHandle, &rect );
142 astrand 933 b = rect.bottom;
143     t = rect.top;
144     l = rect.left;
145     r = rect.right;
146 astrand 994 ltoa( b - t, strH, 10 );
147     ltoa( t, strY, 10 );
148     ltoa( r - l, strW, 10 );
149     ltoa( l, strX, 10 );
150 astrand 993
151 astrand 933 ////setup return string
152 astrand 994 strcat( result, "MSG=CALLWNDPROC_WM_MOVING;OP=2;" );
153 astrand 993 strcat( result, "ID=" );
154     strcat( result, strWindowId );
155     strcat( result, ";" );
156     strcat( result, "TITLE=" );
157     strcat( result, windowTitle );
158     strcat( result, ";" );
159 astrand 994 strcat( result, "X=" );
160     strcat( result, strX );
161 astrand 993 strcat( result, ";" );
162 astrand 994 strcat( result, "Y=" );
163     strcat( result, strY );
164     strcat( result, ";" );
165     strcat( result, "H=" );
166     strcat( result, strH );
167     strcat( result, ";" );
168     strcat( result, "W=" );
169     strcat( result, strW );
170     strcat( result, "." );
171 astrand 993
172 astrand 933 buffer = result;
173 astrand 993
174 astrand 933 break;
175 astrand 993
176 astrand 994
177     case WM_WINDOWPOSCHANGING:
178    
179     windowHandle = details->hwnd;
180     //windowHandle2 = details->hwndInsertAfter;
181     //get win name
182     GetWindowText( windowHandle, windowTitle, 150 );
183    
184     //get an id for it
185     itoa( ( int ) windowHandle, strWindowId, 10 );
186    
187     //get coords
188     GetWindowRect( windowHandle, &rect );
189     b = rect.bottom;
190     t = rect.top;
191     l = rect.left;
192     r = rect.right;
193     ltoa( b - t, strH, 10 );
194     ltoa( t, strY, 10 );
195     ltoa( r - l, strW, 10 );
196     ltoa( l, strX, 10 );
197    
198     ////setup return string
199     strcat( result, "MSG=CALLWNDPROC_WM_WINDOWPOSCHANGING;OP=7;" );
200     strcat( result, "ID=" );
201     strcat( result, strWindowId );
202     strcat( result, ";" );
203     strcat( result, "TITLE=" );
204     strcat( result, windowTitle );
205     strcat( result, ";" );
206     strcat( result, "X=" );
207     strcat( result, strX );
208     strcat( result, ";" );
209     strcat( result, "Y=" );
210     strcat( result, strY );
211     strcat( result, ";" );
212     strcat( result, "H=" );
213     strcat( result, strH );
214     strcat( result, ";" );
215     strcat( result, "W=" );
216     strcat( result, strW );
217     strcat( result, "." );
218    
219     buffer = result;
220    
221     break;
222     case WM_WINDOWPOSCHANGED:
223    
224     windowHandle = details->hwnd;
225     //windowHandle2 = details->hwndInsertAfter;
226     //get win name
227     GetWindowText( windowHandle, windowTitle, 150 );
228    
229     //get an id for it
230     itoa( ( int ) windowHandle, strWindowId, 10 );
231    
232     //get coords
233     GetWindowRect( windowHandle, &rect );
234     b = rect.bottom;
235     t = rect.top;
236     l = rect.left;
237     r = rect.right;
238     ltoa( b - t, strH, 10 );
239     ltoa( t, strY, 10 );
240     ltoa( r - l, strW, 10 );
241     ltoa( l, strX, 10 );
242    
243     ////setup return string
244     strcat( result, "MSG=CALLWNDPROC_WM_WINDOWPOSCHANGED;OP=8;" );
245     strcat( result, "ID=" );
246     strcat( result, strWindowId );
247     strcat( result, ";" );
248     strcat( result, "TITLE=" );
249     strcat( result, windowTitle );
250     strcat( result, ";" );
251     strcat( result, "X=" );
252     strcat( result, strX );
253     strcat( result, ";" );
254     strcat( result, "Y=" );
255     strcat( result, strY );
256     strcat( result, ";" );
257     strcat( result, "H=" );
258     strcat( result, strH );
259     strcat( result, ";" );
260     strcat( result, "W=" );
261     strcat( result, strW );
262     strcat( result, "." );
263    
264     buffer = result;
265    
266     break;
267    
268 astrand 995
269     case WM_CREATE:
270     if ( cs->style & WS_DLGFRAME ) {
271     sprintf( result, "DEBUG:WM_CREATE:%dx%d at %d,%d, title=%s, menu=%p, window=%p, WS_BORDER=%d, WS_DLGFRAME=%d, WS_POPUP=%d",
272     cs->cx, cs->cy, cs->x, cs->y, cs->lpszName, cs->hMenu, details->hwnd,
273     cs->style & WS_BORDER, cs->style & WS_DLGFRAME,
274     cs->style & WS_POPUP );
275     buffer = result;
276     }
277    
278     break;
279    
280    
281     case WM_DESTROY:
282     if ( dwStyle & WS_DLGFRAME ) {
283     sprintf( result, "WM_DESTROY:%p", details->hwnd );
284     buffer = result;
285     }
286    
287     break;
288    
289 astrand 993 default:
290 astrand 933 break;
291     }
292 astrand 993
293     if ( ChannelIsOpen() ) {
294     if ( buffer != NULL ) {
295     WriteToChannel( buffer );
296 astrand 933 }
297     }
298 astrand 993
299     return CallNextHookEx( hhook3, nCode, wParam, lParam );
300 astrand 930 }
301    
302 astrand 993 LRESULT CALLBACK CbtProc( int nCode, WPARAM wParam, LPARAM lParam )
303 astrand 930 {
304 astrand 993 if ( nCode < 0 ) {
305     return CallNextHookEx( hhook, nCode, wParam, lParam );
306 astrand 933 }
307 astrand 993
308    
309 astrand 933 PCHAR buffer = NULL;
310 astrand 993
311    
312     char windowTitle[ 150 ] = { ""
313     };
314 astrand 933 HWND windowHandle = NULL;
315 astrand 993 char result[ 255 ] = { ""
316     };
317     char strWindowId[ 25 ];
318     char type[ 25 ];
319    
320    
321 astrand 933 LONG b, t, l, r;
322 astrand 994 char strW[ 5 ];
323     char strY[ 5 ];
324     char strX[ 5 ];
325     char strH[ 5 ];
326 astrand 933 RECT rect;
327 astrand 993
328 astrand 994 int i = 0; //tmp
329 astrand 993
330     switch ( nCode ) {
331     case HCBT_MINMAX:
332    
333     windowHandle = ( HWND ) wParam;
334 astrand 933 //get win name
335 astrand 993 GetWindowText( windowHandle, windowTitle, 150 );
336    
337 astrand 933 //get an id for it
338 astrand 993 itoa( ( int ) windowHandle, strWindowId, 10 );
339    
340 astrand 933 //get operation type(min,max). if max, do not clip at all,if min use window's previous coords
341     //codes are:
342 astrand 993
343 astrand 937 // SW_HIDE= 0 SW_SHOWNORMAL=1 SW_NORMAL=1 SW_SHOWMINIMIZED=2 SW_SHOWMAXIMIZED=3 SW_MAXIMIZE=3
344     // SW_SHOWNOACTIVATE=4 SW_SHOW=5 SW_MINIMIZE=6 SW_SHOWMINNOACTIVE=7 SW_SHOWNA=8 SW_RESTORE=9
345     // SW_SHOWDEFAULT=10 SW_FORCEMINIMIZE=11 SW_MAX=11
346 astrand 993
347     itoa( ( int ) lParam, type, 10 );
348    
349 astrand 933 //get coords
350 astrand 993 GetWindowRect( windowHandle, &rect );
351 astrand 933 b = rect.bottom;
352     t = rect.top;
353     l = rect.left;
354     r = rect.right;
355 astrand 994 ltoa( b - t, strW, 10 );
356     ltoa( t, strY, 10 );
357     ltoa( r - l, strH, 10 );
358     ltoa( l, strX, 10 );
359 astrand 993
360 astrand 933 //get name
361 astrand 993 GetWindowText( windowHandle, windowTitle, 150 );
362    
363 astrand 933 ////setup return string
364 astrand 994 strcat( result, "MSG=HCBT_MINMAX;OP=4;" );
365    
366     // SW_SHOWNOACTIVATE=4 SW_SHOW=5 SW_MINIMIZE=6 SW_SHOWMINNOACTIVE=7 SW_SHOWNA=8 SW_RESTORE=9
367     // SW_SHOWDEFAULT=10 SW_FORCEMINIMIZE=11 SW_MAX=11
368 astrand 993 strcat( result, "ID=" );
369     strcat( result, strWindowId );
370     strcat( result, ";" );
371     strcat( result, "TITLE=" );
372     strcat( result, windowTitle );
373     strcat( result, ";" );
374 astrand 994 strcat( result, "X=" );
375     strcat( result, strX );
376 astrand 993 strcat( result, ";" );
377 astrand 994 strcat( result, "Y=" );
378     strcat( result, strY );
379     strcat( result, ";" );
380     strcat( result, "H=" );
381     strcat( result, strH );
382     strcat( result, ";" );
383     strcat( result, "W=" );
384     strcat( result, strW );
385     strcat( result, ";" );
386 astrand 993 strcat( result, "TYPE=" );
387     strcat( result, type );
388 astrand 994 strcat( result, "." );
389 astrand 993
390 astrand 933 //-------------------------------------------------------------------------------------------------
391     // code to prevent minimising windows (can be removed once minimise has been implemented)
392 astrand 994 //i = (int)lParam;
393 astrand 933 //if (i==0 || i==2 || i==6 || i==7 || i==8 || i==11)
394 astrand 994 //if ( i==2 || i==6 )
395     //{
396     // MessageBox(0,"Minimising windows is not allowed in this version. Sorry!","TS Window Clipper", MB_OK);
397     // return 1;
398     //}
399 astrand 933 //-----------------------------------------------------------------------------------------
400 astrand 993
401 astrand 933 //-------------------------------------------------------------------------------------------------
402     // code to prevent maximising windows (can be removed once maximise has been implemented)
403 astrand 994 //i = (int)lParam;
404 astrand 933 //if (i==3 || i==9 || i==11)
405 astrand 994 //if (i==3 || i==11)
406     //{
407     // MessageBox(0,"Maximising windows is not allowed in this version. Sorry!","TS Window Clipper", MB_OK);
408     // return 1;
409     //}
410 astrand 933 //-----------------------------------------------------------------------------------------
411 astrand 993
412 astrand 933 buffer = result;
413 astrand 993
414 astrand 933 break;
415 astrand 993
416     case HCBT_MOVESIZE:
417    
418     windowHandle = ( HWND ) wParam;
419 astrand 933 //get win name
420 astrand 993 GetWindowText( windowHandle, windowTitle, 150 );
421    
422 astrand 933 //get an id for it
423 astrand 993 itoa( ( int ) windowHandle, strWindowId, 10 );
424    
425 astrand 933 //get coords
426 astrand 993 GetWindowRect( windowHandle, &rect );
427 astrand 933 b = rect.bottom;
428     t = rect.top;
429     l = rect.left;
430     r = rect.right;
431 astrand 994 ltoa( b - t, strH, 10 );
432     ltoa( t, strY, 10 );
433     ltoa( r - l, strW, 10 );
434     ltoa( l, strX, 10 );
435 astrand 993
436 astrand 933 //get name
437 astrand 993 GetWindowText( windowHandle, windowTitle, 150 );
438    
439 astrand 933 ////setup return string
440 astrand 994 strcat( result, "MSG=HCBT_MOVESIZE;OP=5;" );
441 astrand 993 strcat( result, "ID=" );
442     strcat( result, strWindowId );
443     strcat( result, ";" );
444     strcat( result, "TITLE=" );
445     strcat( result, windowTitle );
446     strcat( result, ";" );
447 astrand 994 strcat( result, "X=" );
448     strcat( result, strX );
449 astrand 993 strcat( result, ";" );
450 astrand 994 strcat( result, "Y=" );
451     strcat( result, strY );
452     strcat( result, ";" );
453     strcat( result, "H=" );
454     strcat( result, strH );
455     strcat( result, ";" );
456     strcat( result, "W=" );
457     strcat( result, strW );
458     strcat( result, "." );
459 astrand 993
460 astrand 933 buffer = result;
461 astrand 993
462 astrand 933 break;
463 astrand 993 case HCBT_SETFOCUS:
464 astrand 933 //buffer = "HCBT_SETFOCUS";
465     //not needed yet
466     break;
467 astrand 993 default:
468 astrand 933 break;
469     }
470 astrand 993
471     if ( ChannelIsOpen() ) {
472     if ( buffer != NULL ) {
473     WriteToChannel( buffer );
474 astrand 933 }
475     }
476 astrand 993
477     return CallNextHookEx( hhook, nCode, wParam, lParam );
478 astrand 930 }
479    
480    
481 astrand 993 LRESULT CALLBACK ShellProc( int nCode, WPARAM wParam, LPARAM lParam )
482 astrand 930 {
483 astrand 993 if ( nCode < 0 ) {
484     return CallNextHookEx( hhook, nCode, wParam, lParam );
485 astrand 933 }
486 astrand 993
487     if ( ChannelIsOpen() ) {
488 astrand 933 PCHAR buffer = NULL;
489 astrand 993
490     char windowTitle[ 150 ] = { ""
491     };
492 astrand 933 HWND windowHandle = NULL;
493 astrand 993 char result[ 255 ] = { ""
494     };
495     char strWindowId[ 25 ];
496 astrand 933 LONG b, t, l, r;
497 astrand 994 char strW[ 5 ];
498     char strY[ 5 ];
499     char strX[ 5 ];
500     char strH[ 5 ];
501 astrand 933 RECT rect;
502 astrand 993
503     switch ( nCode ) {
504     case HSHELL_WINDOWCREATED:
505    
506 astrand 933 //get window id
507 astrand 993 windowHandle = ( HWND ) wParam;
508     itoa( ( int ) windowHandle, strWindowId, 10 );
509    
510 astrand 933 //get coords
511 astrand 993 GetWindowRect( windowHandle, &rect );
512 astrand 933 b = rect.bottom;
513     t = rect.top;
514     l = rect.left;
515     r = rect.right;
516 astrand 994 ltoa( b - t, strH, 10 );
517     ltoa( t, strY, 10 );
518     ltoa( r - l, strW, 10 );
519     ltoa( l, strX, 10 );
520 astrand 993
521 astrand 933 //get name
522 astrand 993 GetWindowText( windowHandle, windowTitle, 150 );
523    
524 astrand 933 ////setup return string
525 astrand 994 strcat( result, "MSG=HSHELL_WINDOWCREATED;OP=0;" );
526 astrand 993 strcat( result, "ID=" );
527     strcat( result, strWindowId );
528     strcat( result, ";" );
529     strcat( result, "TITLE=" );
530     strcat( result, windowTitle );
531     strcat( result, ";" );
532 astrand 994 strcat( result, "X=" );
533     strcat( result, strX );
534 astrand 993 strcat( result, ";" );
535 astrand 994 strcat( result, "Y=" );
536     strcat( result, strY );
537     strcat( result, ";" );
538     strcat( result, "H=" );
539     strcat( result, strH );
540     strcat( result, ";" );
541     strcat( result, "W=" );
542     strcat( result, strW );
543     strcat( result, "." );
544 astrand 993
545 astrand 933 buffer = result;
546 astrand 993
547 astrand 933 break;
548 astrand 993
549     case HSHELL_WINDOWDESTROYED:
550    
551 astrand 933 //get window id
552 astrand 993 windowHandle = ( HWND ) wParam;
553     itoa( ( int ) windowHandle, strWindowId, 10 );
554    
555 astrand 994 //get coords
556     GetWindowRect( windowHandle, &rect );
557     b = rect.bottom;
558     t = rect.top;
559     l = rect.left;
560     r = rect.right;
561     ltoa( b - t, strH, 10 );
562     ltoa( t, strY, 10 );
563     ltoa( r - l, strW, 10 );
564     ltoa( l, strX, 10 );
565    
566 astrand 933 //get name
567 astrand 993 GetWindowText( windowHandle, windowTitle, 150 );
568    
569 astrand 933 ////setup return string
570 astrand 994 strcat( result, "MSG=HSHELL_WINDOWDESTROYED;OP=1;" );
571 astrand 993 strcat( result, "ID=" );
572     strcat( result, strWindowId );
573     strcat( result, ";" );
574     strcat( result, "TITLE=" );
575     strcat( result, windowTitle );
576     strcat( result, ";" );
577 astrand 994 strcat( result, "X=" );
578     strcat( result, strX );
579     strcat( result, ";" );
580     strcat( result, "Y=" );
581     strcat( result, strY );
582     strcat( result, ";" );
583     strcat( result, "H=" );
584     strcat( result, strH );
585     strcat( result, ";" );
586     strcat( result, "W=" );
587     strcat( result, strW );
588     strcat( result, "." );
589 astrand 993
590 astrand 933 buffer = result;
591 astrand 993
592 astrand 933 break;
593 astrand 993 default:
594 astrand 933 break;
595     }
596 astrand 993
597     if ( buffer != NULL ) {
598     WriteToChannel( buffer );
599 astrand 933 }
600     }
601 astrand 993
602     return CallNextHookEx( hhook, nCode, wParam, lParam );
603 astrand 930 }
604    
605 astrand 993 DLL_EXPORT void SetCbtHook( void )
606 astrand 930 {
607 astrand 993 if ( !bHooked ) {
608 astrand 994 hhook = SetWindowsHookEx( WH_CBT, ( HOOKPROC ) CbtProc, hInst, ( DWORD ) NULL );
609 astrand 933 bHooked = true;
610     }
611 astrand 993
612     if ( !bHooked2 ) {
613 astrand 994 hhook2 = SetWindowsHookEx( WH_SHELL, ( HOOKPROC ) ShellProc, hInst, ( DWORD ) NULL );
614 astrand 933 bHooked2 = true;
615     }
616 astrand 993
617     if ( !bHooked3 ) {
618 astrand 994 hhook3 = SetWindowsHookEx( WH_CALLWNDPROC, ( HOOKPROC ) CallWndProc, hInst, ( DWORD ) NULL );
619 astrand 933 bHooked3 = true;
620     }
621 astrand 930 }
622    
623 astrand 993 DLL_EXPORT void RemoveCbtHook( void )
624 astrand 930 {
625 astrand 993 if ( bHooked ) {
626     UnhookWindowsHookEx( hhook );
627 astrand 933 bHooked = false;
628     }
629 astrand 993
630     if ( bHooked2 ) {
631     UnhookWindowsHookEx( hhook2 );
632 astrand 933 bHooked2 = false;
633     }
634 astrand 993
635     if ( bHooked3 ) {
636     UnhookWindowsHookEx( hhook3 );
637 astrand 933 bHooked3 = false;
638     }
639 astrand 930 }
640    
641     DLL_EXPORT int GetInstanceCount()
642     {
643 astrand 933 return iInstanceCount;
644 astrand 930 }
645    
646     int OpenVirtualChannel()
647     {
648 astrand 994 m_vcHandle = WTSVirtualChannelOpen( WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, CHANNELNAME );
649    
650 astrand 993 if ( m_vcHandle == NULL ) {
651 astrand 933 return 0;
652 astrand 937 } else {
653 astrand 933 return 1;
654     }
655 astrand 930 }
656    
657     int CloseVirtualChannel()
658     {
659 astrand 993 BOOL result = WTSVirtualChannelClose( m_vcHandle );
660    
661 astrand 933 m_vcHandle = NULL;
662 astrand 993
663     if ( result ) {
664 astrand 933 return 1;
665 astrand 937 } else {
666 astrand 933 return 0;
667     }
668 astrand 930 }
669    
670     int ChannelIsOpen()
671     {
672 astrand 993 if ( m_vcHandle == NULL ) {
673 astrand 933 return 0;
674 astrand 937 } else {
675 astrand 933 return 1;
676     }
677 astrand 930 }
678    
679 astrand 993 int WriteToChannel( PCHAR buffer )
680 astrand 930 {
681 astrand 933 PULONG bytesRead = 0;
682     PULONG pBytesWritten = 0;
683 astrand 993
684 astrand 994 BOOL result = WTSVirtualChannelWrite( m_vcHandle, buffer, ( ULONG ) strlen( buffer ), pBytesWritten );
685    
686 astrand 993 if ( result ) {
687 astrand 933 return 1;
688 astrand 937 } else {
689 astrand 933 return 0;
690     }
691 astrand 930 }

  ViewVC Help
Powered by ViewVC 1.1.26