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

Contents of /sourceforge.net/trunk/seamlessrdp/ServerExe/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1074 - (show annotations)
Thu Mar 9 13:24:35 2006 UTC (18 years, 3 months ago) by ossman_
File MIME type: text/plain
File size: 3526 byte(s)
Basic infrastructure for retrieving commands in the server.

1 /* -*- c-basic-offset: 8 -*-
2 rdesktop: A Remote Desktop Protocol client.
3 Seamless windows - Remote server executable
4
5 Based on code copyright (C) 2004-2005 Martin Wickett
6
7 Copyright (C) Peter Åstrand <astrand@cendio.se> 2005-2006
8 Copyright (C) Pierre Ossman <ossman@cendio.se> 2006
9
10 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
15 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
20 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
25 #include <windows.h>
26 #include <stdio.h>
27
28 #include "vchannel.h"
29
30 #include "resource.h"
31
32 #define APP_NAME "SeamlessRDP Shell"
33
34 /* Global data */
35 static HINSTANCE g_instance;
36
37 typedef void (*set_hooks_proc_t) ();
38 typedef void (*remove_hooks_proc_t) ();
39 typedef int (*get_instance_count_proc_t) ();
40
41 static void
42 message(const char *text)
43 {
44 MessageBox(GetDesktopWindow(), text, "SeamlessRDP Shell", MB_OK);
45 }
46
47 static void
48 process_cmds(void)
49 {
50 char line[VCHANNEL_MAX_LINE];
51 int size;
52
53 while ((size = vchannel_read(line, sizeof(line))) >= 0) {
54 debug("Got: %s", line);
55 }
56 }
57
58 int WINAPI
59 WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmdline, int cmdshow)
60 {
61 HMODULE hookdll;
62
63 set_hooks_proc_t set_hooks_fn;
64 remove_hooks_proc_t remove_hooks_fn;
65 get_instance_count_proc_t instance_count_fn;
66
67 g_instance = instance;
68
69 hookdll = LoadLibrary("hookdll.dll");
70 if (!hookdll)
71 {
72 message("Could not load hook DLL. Unable to continue.");
73 return -1;
74 }
75
76 set_hooks_fn = (set_hooks_proc_t) GetProcAddress(hookdll, "SetHooks");
77 remove_hooks_fn = (remove_hooks_proc_t) GetProcAddress(hookdll, "RemoveHooks");
78 instance_count_fn = (get_instance_count_proc_t) GetProcAddress(hookdll, "GetInstanceCount");
79
80 if (!set_hooks_fn || !remove_hooks_fn || !instance_count_fn)
81 {
82 FreeLibrary(hookdll);
83 message("Hook DLL doesn't contain the correct functions. Unable to continue.");
84 return -1;
85 }
86
87 /* Check if the DLL is already loaded */
88 if (instance_count_fn() != 1)
89 {
90 FreeLibrary(hookdll);
91 message("Another running instance of Seamless RDP detected.");
92 return -1;
93 }
94
95 vchannel_open();
96
97 set_hooks_fn();
98
99 if (strlen(cmdline) == 0)
100 {
101 message("No command line specified.");
102 return -1;
103 }
104 else
105 {
106 BOOL result;
107 DWORD exitcode;
108 PROCESS_INFORMATION proc_info;
109 STARTUPINFO startup_info;
110
111 memset(&startup_info, 0, sizeof(STARTUPINFO));
112 startup_info.cb = sizeof(STARTUPINFO);
113
114 result = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, 0,
115 NULL, NULL, &startup_info, &proc_info);
116
117 if (result)
118 {
119 do
120 {
121 process_cmds();
122 Sleep(100);
123 GetExitCodeProcess(proc_info.hProcess, &exitcode);
124 }
125 while (exitcode == STILL_ACTIVE);
126
127 // Release handles
128 CloseHandle(proc_info.hProcess);
129 CloseHandle(proc_info.hThread);
130 }
131 else
132 {
133 // CreateProcess failed.
134 char msg[256];
135 _snprintf(msg, sizeof(msg),
136 "Unable to launch the requested application:\n%s", cmdline);
137 message(msg);
138 }
139 }
140
141 remove_hooks_fn();
142
143 FreeLibrary(hookdll);
144
145 vchannel_close();
146
147 return 1;
148 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26