Operator Console
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions | Variables
main.cpp File Reference
#include "OperatorConsole.h"
Include dependency graph for main.cpp:

Functions

static void CreatePipes ()
 
static bool InitThread ()
 
static void LaunchProcess ()
 
static void Run ()
 
int WINAPI_tWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, int nCmdShow)
 
int AFXAPI AfxWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, int nCmdShow)
 
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
 

Variables

HANDLE gStderr_Rd = NULL
 
HANDLE gStderr_Wr = NULL
 
HANDLE gStdout_Rd = NULL
 
HANDLE gStdout_Wr = NULL
 

Function Documentation

int AFXAPI AfxWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
_In_ LPTSTR  lpCmdLine,
int  nCmdShow 
)
void CreatePipes ( )
static

References gStderr_Rd, gStderr_Wr, gStdout_Rd, and gStdout_Wr.

Referenced by WinMain().

55 {
56  SECURITY_ATTRIBUTES saAttr;
57 
58  saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
59  saAttr.bInheritHandle = TRUE;
60  saAttr.lpSecurityDescriptor = NULL;
61 
62  // Create a pipe for the child process's STDOUT.
63  // Ensure the read handle to the pipe for STDOUT is not inherited.
64 
65  CreatePipe(&gStdout_Rd, &gStdout_Wr, &saAttr, 0);
66  SetHandleInformation(gStdout_Rd, HANDLE_FLAG_INHERIT, 0);
67 
68  CreatePipe(&gStderr_Rd, &gStderr_Wr, &saAttr, 0);
69  SetHandleInformation(gStderr_Rd, HANDLE_FLAG_INHERIT, 0);
70 
71  SetStdHandle(STD_OUTPUT_HANDLE, gStdout_Wr);
72  SetStdHandle(STD_ERROR_HANDLE, gStderr_Wr);
73 }
HANDLE gStdout_Rd
Definition: main.cpp:17
HANDLE gStderr_Rd
Definition: main.cpp:15
HANDLE gStderr_Wr
Definition: main.cpp:16
HANDLE gStdout_Wr
Definition: main.cpp:18

Here is the caller graph for this function:

static bool InitThread ( )
static
void LaunchProcess ( )
static

References gStderr_Wr, and gStdout_Wr.

79 {
80 // TCHAR cmdline[]=TEXT("\"C:\\Users\\Jeff\\Documents\\Visual Studio 2012\\Projects\\OperatorConsole\\Release\\OperatorConsole.exe\"");
81  TCHAR cmdline[]=TEXT(".\\OperatorConsole.exe");
82  PROCESS_INFORMATION processInfo;
83  STARTUPINFO startInfo;
84  BOOL bSuccess = FALSE;
85 
86  // Set up members of the PROCESS_INFORMATION structure.
87 
88  ZeroMemory( &processInfo, sizeof(PROCESS_INFORMATION) );
89 
90  // Set up members of the STARTUPINFO structure.
91  // This structure specifies the STDIN and STDout handles for redirection.
92 
93  ZeroMemory( &startInfo, sizeof(STARTUPINFO) );
94  startInfo.cb = sizeof(STARTUPINFO);
95  startInfo.hStdError = gStderr_Wr;
96  startInfo.hStdOutput = gStdout_Wr;
97  startInfo.dwFlags |= STARTF_USESTDHANDLES;
98 
99  // Create the child process.
100 
101  bSuccess = CreateProcess(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &startInfo, &processInfo);
102 
103  if (bSuccess)
104  {
105  // Close handles to the child process and its primary thread.
106  // Some applications might keep these handles to monitor the status
107  // of the child process, for example.
108 
109  CloseHandle(processInfo.hProcess);
110  CloseHandle(processInfo.hThread);
111  }
112 }
HANDLE gStderr_Wr
Definition: main.cpp:16
HANDLE gStdout_Wr
Definition: main.cpp:18
void Run ( )
static
35 {
36  BOOL bRet;
37  MSG msg;
38 
39 
40  while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
41  {
42  if (bRet == -1)
43  {
44  // handle the error and possibly exit
45  }
46  else
47  {
48  TranslateMessage(&msg);
49  DispatchMessage(&msg);
50  }
51  }
52 }
int WINAPI_tWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
_In_ LPTSTR  lpCmdLine,
int  nCmdShow 
)
int APIENTRY WinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPSTR  lpCmdLine,
int  nCmdShow 
)

References CreatePipes().

25 {
26  CreatePipes();
27  COperatorConsoleApp *thread = (COperatorConsoleApp *)AfxBeginThread(RUNTIME_CLASS(COperatorConsoleApp), 0, CREATE_SUSPENDED);
28  thread->m_appInstance = hInstance;
29  thread->ResumeThread();
30  ::WaitForSingleObject(thread->m_hThread, INFINITE);
31 }
The main class for the Operator Console Application.
Definition: OperatorConsole.h:174
static void CreatePipes()
Definition: main.cpp:54

Here is the call graph for this function:

Variable Documentation

HANDLE gStderr_Rd = NULL

Referenced by CreatePipes().

HANDLE gStderr_Wr = NULL

Referenced by CreatePipes(), and LaunchProcess().

HANDLE gStdout_Rd = NULL

Referenced by CreatePipes().

HANDLE gStdout_Wr = NULL

Referenced by CreatePipes(), and LaunchProcess().