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_ |
1071 |
#include "resource.h" |
29 |
ossman_ |
1069 |
|
30 |
ossman_ |
1071 |
#define APP_NAME "SeamlessRDP Shell" |
31 |
ossman_ |
1069 |
|
32 |
ossman_ |
1071 |
/* Global data */ |
33 |
|
|
static HINSTANCE g_instance; |
34 |
ossman_ |
1069 |
|
35 |
ossman_ |
1071 |
typedef void (*set_hooks_proc_t) (); |
36 |
|
|
typedef void (*remove_hooks_proc_t) (); |
37 |
|
|
typedef int (*get_instance_count_proc_t) (); |
38 |
ossman_ |
1069 |
|
39 |
ossman_ |
1071 |
static void |
40 |
|
|
message(const char *text) |
41 |
ossman_ |
1069 |
{ |
42 |
ossman_ |
1071 |
MessageBox(GetDesktopWindow(), text, "SeamlessRDP Shell", MB_OK); |
43 |
ossman_ |
1069 |
} |
44 |
|
|
|
45 |
ossman_ |
1071 |
int WINAPI |
46 |
|
|
WinMain(HINSTANCE instance, HINSTANCE prev_instance, LPSTR cmdline, int cmdshow) |
47 |
ossman_ |
1069 |
{ |
48 |
ossman_ |
1071 |
HMODULE hookdll; |
49 |
ossman_ |
1069 |
|
50 |
ossman_ |
1071 |
set_hooks_proc_t set_hooks_fn; |
51 |
|
|
remove_hooks_proc_t remove_hooks_fn; |
52 |
|
|
get_instance_count_proc_t instance_count_fn; |
53 |
ossman_ |
1069 |
|
54 |
ossman_ |
1071 |
g_instance = instance; |
55 |
ossman_ |
1069 |
|
56 |
ossman_ |
1071 |
hookdll = LoadLibrary("hookdll.dll"); |
57 |
|
|
if (!hookdll) |
58 |
|
|
{ |
59 |
|
|
message("Could not load hook DLL. Unable to continue."); |
60 |
|
|
return -1; |
61 |
|
|
} |
62 |
ossman_ |
1069 |
|
63 |
ossman_ |
1071 |
set_hooks_fn = (set_hooks_proc_t) GetProcAddress(hookdll, "SetHooks"); |
64 |
|
|
remove_hooks_fn = (remove_hooks_proc_t) GetProcAddress(hookdll, "RemoveHooks"); |
65 |
|
|
instance_count_fn = (get_instance_count_proc_t) GetProcAddress(hookdll, "GetInstanceCount"); |
66 |
ossman_ |
1069 |
|
67 |
ossman_ |
1071 |
if (!set_hooks_fn || !remove_hooks_fn || !instance_count_fn) |
68 |
|
|
{ |
69 |
|
|
FreeLibrary(hookdll); |
70 |
|
|
message("Hook DLL doesn't contain the correct functions. Unable to continue."); |
71 |
|
|
return -1; |
72 |
|
|
} |
73 |
ossman_ |
1069 |
|
74 |
ossman_ |
1071 |
/* Check if the DLL is already loaded */ |
75 |
|
|
if (instance_count_fn() != 1) |
76 |
|
|
{ |
77 |
|
|
FreeLibrary(hookdll); |
78 |
|
|
message("Another running instance of Seamless RDP detected."); |
79 |
|
|
return -1; |
80 |
|
|
} |
81 |
ossman_ |
1069 |
|
82 |
ossman_ |
1071 |
set_hooks_fn(); |
83 |
ossman_ |
1069 |
|
84 |
ossman_ |
1071 |
if (strlen(cmdline) == 0) |
85 |
|
|
{ |
86 |
|
|
message("No command line specified."); |
87 |
|
|
return -1; |
88 |
|
|
} |
89 |
|
|
else |
90 |
|
|
{ |
91 |
|
|
BOOL result; |
92 |
|
|
DWORD exitcode; |
93 |
|
|
PROCESS_INFORMATION proc_info; |
94 |
|
|
STARTUPINFO startup_info; |
95 |
ossman_ |
1069 |
|
96 |
ossman_ |
1071 |
memset(&startup_info, 0, sizeof(STARTUPINFO)); |
97 |
|
|
startup_info.cb = sizeof(STARTUPINFO); |
98 |
ossman_ |
1069 |
|
99 |
ossman_ |
1071 |
result = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, 0, |
100 |
|
|
NULL, NULL, &startup_info, &proc_info); |
101 |
ossman_ |
1069 |
|
102 |
ossman_ |
1071 |
if (result) |
103 |
|
|
{ |
104 |
|
|
do |
105 |
|
|
{ |
106 |
|
|
Sleep(1000); |
107 |
|
|
GetExitCodeProcess(proc_info.hProcess, &exitcode); |
108 |
|
|
} |
109 |
|
|
while (exitcode == STILL_ACTIVE); |
110 |
ossman_ |
1069 |
|
111 |
ossman_ |
1071 |
// Release handles |
112 |
|
|
CloseHandle(proc_info.hProcess); |
113 |
|
|
CloseHandle(proc_info.hThread); |
114 |
|
|
} |
115 |
|
|
else |
116 |
|
|
{ |
117 |
|
|
// CreateProcess failed. |
118 |
|
|
char msg[256]; |
119 |
|
|
_snprintf(msg, sizeof(msg), |
120 |
|
|
"Unable to launch the requested application:\n%s", cmdline); |
121 |
|
|
message(msg); |
122 |
|
|
} |
123 |
|
|
} |
124 |
ossman_ |
1069 |
|
125 |
ossman_ |
1071 |
remove_hooks_fn(); |
126 |
ossman_ |
1069 |
|
127 |
ossman_ |
1071 |
FreeLibrary(hookdll); |
128 |
ossman_ |
1069 |
|
129 |
ossman_ |
1071 |
return 1; |
130 |
ossman_ |
1069 |
} |