ReactOS  0.4.12-dev-102-g4b7f1e0
tnmisc.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

BOOL CreateHiddenConsoleProcess (LPCTSTR szChildName, PROCESS_INFORMATION *ppi, LPHANDLE phInWrite, LPHANDLE phOutRead, LPHANDLE phErrRead)
 
BOOL SpawnProcess (char *cmd_line, PROCESS_INFORMATION *pi)
 
int GetWin32Version (void)
 
HWND TelnetGetConsoleWindow (void)
 
bool SetIcon (HWND hConsoleWindow, HANDLE hIcon, LPARAM *pOldBIcon, LPARAM *pOldSIcon, const char *icondir)
 
void ResetIcon (HWND hConsoleWindow, LPARAM oldBIcon, LPARAM oldSIcon)
 

Function Documentation

◆ CreateHiddenConsoleProcess()

BOOL CreateHiddenConsoleProcess ( LPCTSTR  szChildName,
PROCESS_INFORMATION ppi,
LPHANDLE  phInWrite,
LPHANDLE  phOutRead,
LPHANDLE  phErrRead 
)

Definition at line 5 of file tnmisc.cpp.

Referenced by Telnet::Open().

7  {
8  BOOL fCreated;
9  STARTUPINFO si;
11  HANDLE hInRead = INVALID_HANDLE_VALUE;
12  HANDLE hOutWrite = INVALID_HANDLE_VALUE;
13  HANDLE hErrWrite = INVALID_HANDLE_VALUE;
14 
15  // Create pipes
16  // initialize security attributes for handle inheritance (for WinNT)
17  sa.nLength = sizeof( sa );
18  sa.bInheritHandle = TRUE;
20 
21  // create STDIN pipe
22  if( !CreatePipe( &hInRead, phInWrite, &sa, 0 )) {
23  hInRead = INVALID_HANDLE_VALUE;
24  goto error;
25  }
26 
27  // create STDOUT pipe
28  if( !CreatePipe( phOutRead, &hOutWrite, &sa, 0 )) {
29  hOutWrite = INVALID_HANDLE_VALUE;
30  goto error;
31  }
32 
33  // create STDERR pipe
34  if( !CreatePipe( phErrRead, &hErrWrite, &sa, 0 )) {
35  hErrWrite = INVALID_HANDLE_VALUE;
36  goto error;
37  }
38 
39  // process startup information
40  memset( &si, 0, sizeof( si ));
41  si.cb = sizeof( si );
43  // child process' console must be hidden for Win95 compatibility
44  si.wShowWindow = SW_HIDE;
45  // assign "other" sides of pipes
46  si.hStdInput = hInRead;
47  si.hStdOutput = hOutWrite;
48  si.hStdError = hErrWrite;
49 
50  // Create a child process (suspended)
51  fCreated = CreateProcess( NULL,
52  (LPTSTR)szChildName,
53  NULL,
54  NULL,
55  TRUE,
56  0,
57  NULL,
58  NULL,
59  &si,
60  ppi );
61 
62  if( !fCreated )
63  goto error;
64 
65  CloseHandle( hInRead );
66  CloseHandle( hOutWrite );
67  CloseHandle( hErrWrite );
68 
69  return TRUE;
70 
71 error:
72  if (hInRead != INVALID_HANDLE_VALUE) CloseHandle( hInRead );
73  if (hOutWrite != INVALID_HANDLE_VALUE) CloseHandle( hOutWrite );
74  if (hErrWrite != INVALID_HANDLE_VALUE) CloseHandle( hErrWrite );
75  CloseHandle( ppi->hProcess );
76  CloseHandle( ppi->hThread );
77 
78  hInRead =
79  hOutWrite =
80  hErrWrite =
81  ppi->hProcess =
83 
84  return FALSE;
85 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define error(str)
Definition: mkdosfs.c:1605
#define SW_HIDE
Definition: winuser.h:762
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD dwFlags
Definition: winbase.h:807
CHAR * LPTSTR
Definition: xmlstorage.h:192
smooth NULL
Definition: ftsmooth.c:416
#define STARTF_USESHOWWINDOW
Definition: winbase.h:472
#define STARTF_USESTDHANDLES
Definition: winbase.h:480
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD cb
Definition: winbase.h:796
HANDLE hStdOutput
Definition: winbase.h:812
#define CreateProcess
Definition: winbase.h:3572
BOOL WINAPI CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)
Definition: npipe.c:117
LPVOID lpSecurityDescriptor
Definition: compat.h:181
HANDLE hStdInput
Definition: winbase.h:811
WORD wShowWindow
Definition: winbase.h:808
#define memset(x, y, z)
Definition: compat.h:39
HANDLE hStdError
Definition: winbase.h:813
static struct sockaddr_in sa
Definition: adnsresfilter.c:69

◆ GetWin32Version()

int GetWin32Version ( void  )

Definition at line 98 of file tnmisc.cpp.

Referenced by telCommandLine().

98  {
99  // return win32 version; 0 = Win32s, 1 = Win95, 2 = WinNT, 3 = Unknown -crn@ozemail.com.au
100  LPOSVERSIONINFO osv;
101  DWORD retval;
102 
103  osv = new OSVERSIONINFO;
104 
105  osv->dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
106  GetVersionEx (osv);
107  retval = osv->dwPlatformId;
108  delete osv;
109  return (retval);
110 }
OSVERSIONINFOA OSVERSIONINFO
Definition: rtltypes.h:289
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:233
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG dwPlatformId
Definition: rtltypes.h:237
#define GetVersionEx
Definition: winbase.h:3666

◆ ResetIcon()

void ResetIcon ( HWND  hConsoleWindow,
LPARAM  oldBIcon,
LPARAM  oldSIcon 
)

Definition at line 179 of file tnmisc.cpp.

Referenced by Telnet::~Telnet().

179  {
180 #ifdef ICON_BIG
181  SendMessage(hConsoleWindow, WM_SETICON, ICON_BIG, (LPARAM)oldBIcon);
182 #endif
183 #ifdef ICON_SMALL
184  SendMessage(hConsoleWindow, WM_SETICON, ICON_SMALL, (LPARAM)oldSIcon);
185 #endif
186 }
#define ICON_SMALL
Definition: tnclass.cpp:48
LONG_PTR LPARAM
Definition: windef.h:208
#define SendMessage
Definition: winuser.h:5709
#define ICON_BIG
Definition: tnclass.cpp:51

◆ SetIcon()

bool SetIcon ( HWND  hConsoleWindow,
HANDLE  hIcon,
LPARAM pOldBIcon,
LPARAM pOldSIcon,
const char icondir 
)

Definition at line 136 of file tnmisc.cpp.

Referenced by Telnet::DoInit().

137  {
138  if(!hConsoleWindow) return false;
139 
140 // FIX ME!!! The LoadIcon code should work with any compiler!
141 // (Paul Brannan 12/17/98)
142 #ifndef __BORLANDC__ // Ioannou Dec. 8, 1998
143  if(!hIcon) {
144  char filename[MAX_PATH]; // load from telnet.ico
145  _snprintf(filename, MAX_PATH - 1, "%s%s", icondir, "telnet.ico");
146  filename[MAX_PATH - 1] = '\0';
147 
148  // Note: loading the icon from a file doesn't work on NT
149  // There is no LoadImage in Borland headers - only LoadIcon
150  hIcon = LoadImage(NULL, filename, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE +
152  }
153 #else
154  // load the icon from the resource file -crn@ozemail.com.au 16/12/98
155  if(!hIcon) {
156  hIcon = LoadIcon((HANDLE)GetWindowLongPtr(hConsoleWindow,
157  GWLP_HINSTANCE), "TELNETICON");
158  }
159 #endif
160 
161  if(hIcon) {
162 #ifdef ICON_BIG
163  *pOldBIcon = SendMessage(hConsoleWindow, WM_SETICON, ICON_BIG,
164  (LPARAM)hIcon);
165 #endif
166 #ifdef ICON_SMALL
167  *pOldSIcon = SendMessage(hConsoleWindow, WM_SETICON, ICON_SMALL,
168  (LPARAM)hIcon);
169 #endif
170  return true;
171  } else {
172  // Otherwise we get a random icon at exit! (Paul Brannan 9/13/98)
173  return false;
174  }
175 }
#define IMAGE_ICON
Definition: winuser.h:212
#define LR_LOADFROMFILE
Definition: winuser.h:1082
const char * filename
Definition: ioapi.h:135
#define ICON_SMALL
Definition: tnclass.cpp:48
#define _snprintf
Definition: xmlstorage.h:200
LONG_PTR LPARAM
Definition: windef.h:208
smooth NULL
Definition: ftsmooth.c:416
#define LR_DEFAULTSIZE
Definition: winuser.h:1084
#define MAX_PATH
Definition: compat.h:26
#define GWLP_HINSTANCE
Definition: winuser.h:850
#define SendMessage
Definition: winuser.h:5709
#define LoadImage
Definition: winuser.h:5681
#define LoadIcon
Definition: winuser.h:5679
#define GetWindowLongPtr
Definition: treelist.c:73
#define ICON_BIG
Definition: tnclass.cpp:51

◆ SpawnProcess()

BOOL SpawnProcess ( char cmd_line,
PROCESS_INFORMATION pi 
)

Definition at line 87 of file tnmisc.cpp.

Referenced by Telnet::NewProcess().

87  {
88  STARTUPINFO si;
89 
90  memset(&si, 0, sizeof(si));
91  si.cb = sizeof(si);
92 
94  CREATE_NEW_CONSOLE, NULL, NULL, &si, pi);
95 }
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:181
smooth NULL
Definition: ftsmooth.c:416
#define CREATE_NEW_CONSOLE
Definition: winbase.h:180
DWORD cb
Definition: winbase.h:796
#define CreateProcess
Definition: winbase.h:3572
#define memset(x, y, z)
Definition: compat.h:39

◆ TelnetGetConsoleWindow()

HWND TelnetGetConsoleWindow ( void  )

Definition at line 115 of file tnmisc.cpp.

Referenced by Telnet::DoInit().

115  {
116  DWORD pid = GetCurrentProcessId(), wpid;
117  char title[512], *t = title;
118  HWND hrv = NULL;
119 
120 #ifndef __BORLANDC__ // Ioannou Dec. 8, 1998
121  if(!GetConsoleTitle(title, sizeof(title))) t = NULL;
122 
123  for(;;) {
124  if((hrv = FindWindowEx(NULL, hrv, "tty", t)) == NULL) break;
125  if(!GetWindowThreadProcessId(hrv, &wpid)) continue;
126  if(wpid == pid) return hrv;
127  }
128 #endif
129 
130  return GetForegroundWindow();
131 }
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3835
GLdouble GLdouble t
Definition: gl.h:2047
DWORD WINAPI GetWindowThreadProcessId(HWND, PDWORD)
smooth NULL
Definition: ftsmooth.c:416
#define GetConsoleTitle
Definition: wincon.h:763
#define FindWindowEx
Definition: winuser.h:5644
unsigned long DWORD
Definition: ntddk_ex.h:95
HWND WINAPI GetForegroundWindow(void)
Definition: ntwrapper.h:392
static char title[]
Definition: ps.c:92
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1188