/[rdesktop]/sourceforge.net/trunk/seamlessrdp/ServerExe/main.c
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/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1093 - (hide annotations)
Fri Mar 10 09:47:10 2006 UTC (18 years, 2 months ago) by ossman_
File MIME type: text/plain
File size: 5292 byte(s)
Disable screen saver since its nothing but trouble.

1 ossman_ 1071 /* -*- c-basic-offset: 8 -*-
2     rdesktop: A Remote Desktop Protocol client.
3     Seamless windows - Remote server executable
4 ossman_ 1069
5 ossman_ 1071 Based on code copyright (C) 2004-2005 Martin Wickett
6 ossman_ 1069
7 ossman_ 1071 Copyright (C) Peter Åstrand <astrand@cendio.se> 2005-2006
8     Copyright (C) Pierre Ossman <ossman@cendio.se> 2006
9 ossman_ 1069
10 ossman_ 1071 This program is free software; you can redistribute it and/or modify
11     it under the terms of the GNU General Public License as published by
12     the Free Software Foundation; either version 2 of the License, or
13     (at your option) any later version.
14 ossman_ 1069
15 ossman_ 1071 This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     GNU General Public License for more details.
19 ossman_ 1069
20 ossman_ 1071 You should have received a copy of the GNU General Public License
21     along with this program; if not, write to the Free Software
22     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23     */
24 ossman_ 1069
25 ossman_ 1071 #include <windows.h>
26     #include <stdio.h>
27 ossman_ 1069
28 ossman_ 1074 #include "vchannel.h"
29    
30 ossman_ 1071 #include "resource.h"
31 ossman_ 1069
32 ossman_ 1071 #define APP_NAME "SeamlessRDP Shell"
33 ossman_ 1069
34 ossman_ 1071 /* Global data */
35     static HINSTANCE g_instance;
36 ossman_ 1069
37 ossman_ 1071 typedef void (*set_hooks_proc_t) ();
38     typedef void (*remove_hooks_proc_t) ();
39     typedef int (*get_instance_count_proc_t) ();
40 ossman_ 1069
41 ossman_ 1071 static void
42     message(const char *text)
43 ossman_ 1069 {
44 ossman_ 1071 MessageBox(GetDesktopWindow(), text, "SeamlessRDP Shell", MB_OK);
45 ossman_ 1069 }
46    
47 ossman_ 1075 static char *
48     get_token(char **s)
49     {
50     char *comma, *head;
51     head = *s;
52    
53     if (!head)
54     return NULL;
55    
56     comma = strchr(head, ',');
57     if (comma)
58     {
59     *comma = '\0';
60     *s = comma + 1;
61     }
62     else
63     {
64     *s = NULL;
65     }
66    
67     return head;
68     }
69    
70 ossman_ 1078 static BOOL CALLBACK
71     enum_cb(HWND hwnd, LPARAM lparam)
72 ossman_ 1075 {
73     RECT rect;
74     char title[150];
75     LONG styles;
76     int state;
77    
78     styles = GetWindowLong(hwnd, GWL_STYLE);
79    
80     if (!(styles & WS_VISIBLE))
81     return TRUE;
82    
83 astrand 1091 vchannel_write("CREATE,0x%p,0x%x", hwnd, 0);
84 ossman_ 1075
85 ossman_ 1078 if (!GetWindowRect(hwnd, &rect))
86     {
87 ossman_ 1075 debug("GetWindowRect failed!");
88     return TRUE;
89     }
90    
91 astrand 1091 vchannel_write("POSITION,0x%p,%d,%d,%d,%d,0x%x",
92 ossman_ 1075 hwnd,
93 ossman_ 1078 rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 0);
94 ossman_ 1075
95     GetWindowText(hwnd, title, sizeof(title));
96    
97     /* FIXME: Strip title of dangerous characters */
98    
99     if (styles & WS_MAXIMIZE)
100     state = 2;
101     else if (styles & WS_MINIMIZE)
102     state = 1;
103     else
104     state = 0;
105    
106 astrand 1091 vchannel_write("SETSTATE,0x%p,%s,0x%x,0x%x", hwnd, title, state, 0);
107 ossman_ 1075
108     return TRUE;
109     }
110    
111 ossman_ 1074 static void
112 ossman_ 1075 do_sync(void)
113     {
114     vchannel_block();
115    
116     vchannel_write("SYNCBEGIN,0x0");
117    
118     EnumWindows(enum_cb, 0);
119    
120     vchannel_write("SYNCEND,0x0");
121    
122     vchannel_unblock();
123     }
124    
125     static void
126 ossman_ 1074 process_cmds(void)
127     {
128     char line[VCHANNEL_MAX_LINE];
129     int size;
130    
131 ossman_ 1075 char *p, *tok1, *tok2, *tok3, *tok4, *tok5, *tok6, *tok7, *tok8;
132    
133 ossman_ 1078 while ((size = vchannel_read(line, sizeof(line))) >= 0)
134     {
135 ossman_ 1074 debug("Got: %s", line);
136 ossman_ 1075
137     p = line;
138    
139     tok1 = get_token(&p);
140     tok2 = get_token(&p);
141     tok3 = get_token(&p);
142     tok4 = get_token(&p);
143     tok5 = get_token(&p);
144     tok6 = get_token(&p);
145     tok7 = get_token(&p);
146     tok8 = get_token(&p);
147    
148     if (strcmp(tok1, "SYNC") == 0)
149     do_sync();
150 ossman_ 1074 }
151     }
152    
153 ossman_ 1071 int WINAPI
154     WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmdline, int cmdshow)
155 ossman_ 1069 {
156 ossman_ 1071 HMODULE hookdll;
157 ossman_ 1069
158 ossman_ 1071 set_hooks_proc_t set_hooks_fn;
159     remove_hooks_proc_t remove_hooks_fn;
160     get_instance_count_proc_t instance_count_fn;
161 ossman_ 1069
162 ossman_ 1071 g_instance = instance;
163 ossman_ 1069
164 ossman_ 1084 hookdll = LoadLibrary("seamlessrdp.dll");
165 ossman_ 1071 if (!hookdll)
166     {
167     message("Could not load hook DLL. Unable to continue.");
168     return -1;
169     }
170 ossman_ 1069
171 ossman_ 1071 set_hooks_fn = (set_hooks_proc_t) GetProcAddress(hookdll, "SetHooks");
172     remove_hooks_fn = (remove_hooks_proc_t) GetProcAddress(hookdll, "RemoveHooks");
173     instance_count_fn = (get_instance_count_proc_t) GetProcAddress(hookdll, "GetInstanceCount");
174 ossman_ 1069
175 ossman_ 1071 if (!set_hooks_fn || !remove_hooks_fn || !instance_count_fn)
176     {
177     FreeLibrary(hookdll);
178     message("Hook DLL doesn't contain the correct functions. Unable to continue.");
179     return -1;
180     }
181 ossman_ 1069
182 ossman_ 1071 /* Check if the DLL is already loaded */
183     if (instance_count_fn() != 1)
184     {
185     FreeLibrary(hookdll);
186     message("Another running instance of Seamless RDP detected.");
187     return -1;
188     }
189 ossman_ 1069
190 ossman_ 1074 vchannel_open();
191    
192 ossman_ 1071 set_hooks_fn();
193 ossman_ 1069
194 ossman_ 1077 /* Since we don't see the entire desktop we must resize windows
195     immediatly. */
196     SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, TRUE, NULL, 0);
197    
198 ossman_ 1093 /* Disable screen saver since we cannot catch its windows. */
199     SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0);
200    
201 ossman_ 1071 if (strlen(cmdline) == 0)
202     {
203     message("No command line specified.");
204     return -1;
205     }
206     else
207     {
208     BOOL result;
209     DWORD exitcode;
210     PROCESS_INFORMATION proc_info;
211     STARTUPINFO startup_info;
212 ossman_ 1069
213 ossman_ 1071 memset(&startup_info, 0, sizeof(STARTUPINFO));
214     startup_info.cb = sizeof(STARTUPINFO);
215 ossman_ 1069
216 ossman_ 1071 result = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, 0,
217     NULL, NULL, &startup_info, &proc_info);
218 ossman_ 1069
219 ossman_ 1071 if (result)
220     {
221     do
222     {
223 ossman_ 1074 process_cmds();
224     Sleep(100);
225 ossman_ 1071 GetExitCodeProcess(proc_info.hProcess, &exitcode);
226     }
227     while (exitcode == STILL_ACTIVE);
228 ossman_ 1069
229 ossman_ 1071 // Release handles
230     CloseHandle(proc_info.hProcess);
231     CloseHandle(proc_info.hThread);
232     }
233     else
234     {
235     // CreateProcess failed.
236     char msg[256];
237     _snprintf(msg, sizeof(msg),
238     "Unable to launch the requested application:\n%s", cmdline);
239     message(msg);
240     }
241     }
242 ossman_ 1069
243 ossman_ 1071 remove_hooks_fn();
244 ossman_ 1069
245 ossman_ 1071 FreeLibrary(hookdll);
246 ossman_ 1069
247 ossman_ 1074 vchannel_close();
248    
249 ossman_ 1071 return 1;
250 ossman_ 1069 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26