25e319a81aad967d50e3d2b496c58581a01c69fa
6 // from the PVAX (http://www.ccas.ru/~posp/popov/spawn.htm)
7 // Create a process with pipes to stdin/out/err
8 BOOL
CreateHiddenConsoleProcess(LPCTSTR szChildName
, PROCESS_INFORMATION
* ppi
,
9 LPHANDLE phInWrite
, LPHANDLE phOutRead
,
13 SECURITY_ATTRIBUTES sa
;
19 // initialize security attributes for handle inheritance (for WinNT)
20 sa
.nLength
= sizeof( sa
);
21 sa
.bInheritHandle
= TRUE
;
22 sa
.lpSecurityDescriptor
= NULL
;
25 if( !CreatePipe( &hInRead
, phInWrite
, &sa
, 0 ))
29 if( !CreatePipe( phOutRead
, &hOutWrite
, &sa
, 0 ))
33 if( !CreatePipe( phErrRead
, &hErrWrite
, &sa
, 0 ))
36 // process startup information
37 memset( &si
, 0, sizeof( si
));
39 si
.dwFlags
= STARTF_USESHOWWINDOW
| STARTF_USESTDHANDLES
;
40 // child process' console must be hidden for Win95 compatibility
41 si
.wShowWindow
= SW_HIDE
;
42 // assign "other" sides of pipes
43 si
.hStdInput
= hInRead
;
44 si
.hStdOutput
= hOutWrite
;
45 si
.hStdError
= hErrWrite
;
47 // Create a child process (suspended)
48 fCreated
= CreateProcess( NULL
,
62 CloseHandle( hInRead
);
63 CloseHandle( hOutWrite
);
64 CloseHandle( hErrWrite
);
69 CloseHandle( hInRead
);
70 CloseHandle( hOutWrite
);
71 CloseHandle( hErrWrite
);
72 CloseHandle( ppi
->hProcess
);
73 CloseHandle( ppi
->hThread
);
79 ppi
->hThread
= INVALID_HANDLE_VALUE
;
84 BOOL
SpawnProcess(char *cmd_line
, PROCESS_INFORMATION
*pi
) {
87 memset(&si
, 0, sizeof(si
));
90 return CreateProcess(cmd_line
, NULL
, NULL
, FALSE
, NORMAL_PRIORITY_CLASS
,
91 CREATE_NEW_CONSOLE
, NULL
, NULL
, &si
, pi
);
95 int GetWin32Version(void) {
96 // return win32 version; 0 = Win32s, 1 = Win95, 2 = WinNT, 3 = Unknown -crn@ozemail.com.au
100 osv
= new OSVERSIONINFO
;
102 osv
->dwOSVersionInfoSize
= sizeof (OSVERSIONINFO
);
104 retval
= osv
->dwPlatformId
;
109 // Paul Brannan 8/7/98
110 // This code is from Michael 'Hacker' Krelin (author of KINSole)
111 // (slightly modified)
112 HWND
TelnetGetConsoleWindow() {
113 DWORD pid
= GetCurrentProcessId(), wpid
;
114 char title
[512], *t
= title
;
117 #ifndef __BORLANDC__ // Ioannou Dec. 8, 1998
118 if(!GetConsoleTitle(title
, sizeof(title
))) t
= NULL
;
121 if((hrv
= FindWindowEx(NULL
, hrv
, "tty", t
)) == NULL
) break;
122 if(!GetWindowThreadProcessId(hrv
, &wpid
)) continue;
123 if(wpid
== pid
) return hrv
;
127 return GetForegroundWindow();
130 // Sets the icon of the console window to hIcon
131 // If hIcon is 0, then use a default icon
132 // hConsoleWindow must be set before calling SetIcon
133 bool SetIcon(HWND hConsoleWindow
, HANDLE hIcon
, LPARAM
*pOldBIcon
, LPARAM
*pOldSIcon
,
134 const char *icondir
) {
135 if(!hConsoleWindow
) return false;
137 // FIX ME!!! The LoadIcon code should work with any compiler!
138 // (Paul Brannan 12/17/98)
139 #ifndef __BORLANDC__ // Ioannou Dec. 8, 1998
141 char filename
[MAX_PATH
]; // load from telnet.ico
142 _snprintf(filename
, MAX_PATH
- 1, "%s%s", icondir
, "telnet.ico");
143 filename
[MAX_PATH
- 1] = '\0';
145 // Note: loading the icon from a file doesn't work on NT
146 // There is no LoadImage in Borland headers - only LoadIcon
147 hIcon
= LoadImage(NULL
, filename
, IMAGE_ICON
, 0, 0, LR_DEFAULTSIZE
+
151 // load the icon from the resource file -crn@ozemail.com.au 16/12/98
153 hIcon
= LoadIcon ((HANDLE
)GetWindowLongPtr(hConsoleWindow
,
154 GWL_HINSTANCE
), "TELNETICON");
160 *pOldBIcon
= SendMessage(hConsoleWindow
, WM_SETICON
, ICON_BIG
,
164 *pOldSIcon
= SendMessage(hConsoleWindow
, WM_SETICON
, ICON_SMALL
,
169 // Otherwise we get a random icon at exit! (Paul Brannan 9/13/98)
174 // Allows SetIcon to be called again by resetting the current icon
175 // Added 12/17/98 by Paul Brannan
176 void ResetIcon(HWND hConsoleWindow
, LPARAM oldBIcon
, LPARAM oldSIcon
) {
178 SendMessage(hConsoleWindow
, WM_SETICON
, ICON_BIG
, (LPARAM
)oldBIcon
);
181 SendMessage(hConsoleWindow
, WM_SETICON
, ICON_SMALL
, (LPARAM
)oldSIcon
);