本文整理匯總了C++中AttachConsole函數的典型用法代碼示例。如果您正苦於以下問題:C++ AttachConsole函數的具體用法?C++ AttachConsole怎麽用?C++ AttachConsole使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了AttachConsole函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: LaunchedFromConsole
BOOL LaunchedFromConsole(void) {
if (!AttachConsole(ATTACH_PARENT_PROCESS)) {
return FALSE;
} else {
return TRUE;
}
}
示例2: WinMain
int APIENTRY
WinMain(HINSTANCE hInstance1,
HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
static char name0[256];
static char *argv[256];
int argc = 1;
int i;
GetModuleFileName(hInstance1, name0, 256);
/* Allocate everything virtually - be on the safe side */
argv[0] = strdup(name0);
lpCmdLine = strdup(lpCmdLine);
for (i = 0; lpCmdLine[i]; i++) {
if (lpCmdLine[i] == ' ' || lpCmdLine[i] == '\t')
lpCmdLine[i] = 0;
else if (!i || !lpCmdLine[i - 1])
argv[argc] = lpCmdLine + i, argc++;
}
/* Attach to parent console if available so output will be visible */
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
/* make sure stdout is not already redirected before redefining */
if (_fileno(stdout) == -1 || _get_osfhandle(fileno(stdout)) == -1)
freopen("CON", "w", stdout);
}
hInstance = hInstance1;
return XaoS_main(argc, argv);
}
示例3: attach_parent_console
static void attach_parent_console()
{
BOOL outRedirected, errRedirected;
outRedirected = IsHandleRedirected(STD_OUTPUT_HANDLE);
errRedirected = IsHandleRedirected(STD_ERROR_HANDLE);
if (outRedirected && errRedirected) {
/* Both standard output and error handles are redirected.
* There is no point in attaching to parent process console.
*/
return;
}
if (AttachConsole(ATTACH_PARENT_PROCESS) == 0) {
/* Console attach failed. */
return;
}
/* Console attach succeeded */
if (outRedirected == FALSE) {
freopen("CONOUT$", "w", stdout);
}
if (errRedirected == FALSE) {
freopen("CONOUT$", "w", stderr);
}
}
示例4: attach_console
void attach_console()
{
bool attached = AttachConsole(ATTACH_PARENT_PROCESS) != 0;
// Only force attach when running a debug build
#if !defined(NDEBUG)
if (!attached)
{
attached = AllocConsole() != 0;
}
#endif
// re-open standard file streams.
// Note, that due to a known bug in the Windows CRT these streams cannot
// be redirected on the command line using the > operator. This is a known
// bug in the Windows CRT and is NOT a defect of this application!
if (attached)
{
freopen("CON", "w", stdout);
freopen("CON", "r", stdin);
freopen("CON", "w", stderr);
}
}
示例5: terminal_init
int terminal_init(void)
{
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
// We have been started by something with a console window.
// Redirect output streams to that console's low-level handles,
// so we can actually use WriteConsole later on.
int hConHandle;
hConHandle = _open_osfhandle((intptr_t)hSTDOUT, _O_TEXT);
*stdout = *_fdopen(hConHandle, "w");
setvbuf(stdout, NULL, _IONBF, 0);
hConHandle = _open_osfhandle((intptr_t)hSTDERR, _O_TEXT);
*stderr = *_fdopen(hConHandle, "w");
setvbuf(stderr, NULL, _IONBF, 0);
}
CONSOLE_SCREEN_BUFFER_INFO cinfo;
DWORD cmode = 0;
GetConsoleMode(hSTDOUT, &cmode);
cmode |= (ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT);
SetConsoleMode(hSTDOUT, cmode);
SetConsoleMode(hSTDERR, cmode);
GetConsoleScreenBufferInfo(hSTDOUT, &cinfo);
stdoutAttrs = cinfo.wAttributes;
return 0;
}
示例6: wWinMain
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpstrCmdLine, int nCmdShow )
{
AttachConsole(ATTACH_PARENT_PROCESS);
int argc;
wchar_t *const *argv=CommandLineToArgvW(lpstrCmdLine,&argc);
if (!argv) return 1;
if (argc==3)
{
if (_wcsicmp(argv[0],L"extract")==0)
{
// extract DLL, CSV
// extracts the string table, the dialog text, and the L10N text from a DLL and stores it in a CSV
return ExtractStrings(argv[1],argv[2]);
}
if (_wcsicmp(argv[0],L"import")==0)
{
// import DLL, CSV
// replaces the string table in the DLL with the text from the CSV
return ImportStrings(argv[1],argv[2]);
}
}
return 0;
}
示例7: SDLAppAttachToConsole
bool SDLAppAttachToConsole() {
if(using_parent_console) return true;
if(gSDLAppConsoleWindow != 0) return false;
// if TERM is set to msys, try and attach to console
// could possibly add other supported TERMs here if there are any
char* term = getenv("TERM");
if(!term || strcmp(term, "msys")!=0) return false;
if(AttachConsole(ATTACH_PARENT_PROCESS)) {
// send stdout to console unless already redirected
if (_fileno(stdout) == -1 || _get_osfhandle(fileno(stdout)) == -1) {
freopen("conout$","w", stdout);
}
// send stderr to console unless already redirected
if (_fileno(stderr) == -1 || _get_osfhandle(fileno(stderr)) == -1) {
freopen("conout$","w", stderr);
}
using_parent_console = true;
}
return using_parent_console;
}
示例8: AppMain
int AppMain(int argc, char **argv)
{
CharacterMode = RGui;
if(strcmp(getDLLVersion(), getRVersion()) != 0) {
MessageBox(0, "R.DLL version does not match", "Terminating",
MB_TASKMODAL | MB_ICONSTOP | MB_OK);
exit(1);
}
cmdlineoptions(argc, argv);
if (!setupui()) {
MessageBox(0, "Error setting up console. Try --vanilla option.",
"Terminating", MB_TASKMODAL | MB_ICONSTOP | MB_OK);
GA_exitapp();
}
/* C writes to stdout/stderr get set to the launching terminal (if
there was one). Needs XP, and works for C but not Fortran. */
if (AttachConsole(ATTACH_PARENT_PROCESS))
{
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
}
Rf_mainloop();
/* NOTREACHED */
return 0;
}
示例9: searchForProcess
void AttachToRLLog::tryConsoleConnection()
{
if (!consoleConnected) {
consoleConnected = false;
RLProcID = searchForProcess(RL);
linesRead = 0;
if (threadFound) {
std::cout << "AttachToRLLog::tryConsoleConnection - attaching to console" << std::endl;
if (AttachConsole(RLProcID))
{
hConsole = CreateFile(L"CONOUT$",
GENERIC_READ | GENERIC_WRITE,
0, 0, OPEN_EXISTING, 0, 0);
consoleConnected = true;
emit rocketLeagueRunning(true);
scanLogTimer = new QTimer(this);
connect(scanLogTimer, SIGNAL(timeout()), this, SLOT(readLatest()));
scanLogTimer->start(100);
}
else
{
std::cout << "AttachToRLLOG: connection to console failed" << std::endl;
QTimer::singleShot(1000, Qt::CoarseTimer, this, SLOT(tryConsoleConnection()));
}
} else {
QTimer::singleShot(1000, Qt::CoarseTimer, this, SLOT(tryConsoleConnection()));
}
}
}
示例10: CheckMounted
void Drive::Umount(HWND)
{
// check mounted
CheckMounted();
// if (GetDriveType(mnt) == DRIVE_NO_ROOT_DIR)
// mounted = false;
if (!mounted)
throw truntime_error(_T("Cannot unmount a not mounted drive"));
// unmount
fuse_unmount(wchar_to_utf8_cstr(mnt).c_str(), NULL);
if (subProcess) {
// attach console to allow sending ctrl-c
AttachConsole(subProcess->pid);
// disable ctrl-c to not exit this process
SetConsoleCtrlHandler(HandlerRoutine, TRUE);
if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, subProcess->pid)
&& !GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, subProcess->pid))
TerminateProcess(subProcess->hProcess, 0);
// force exit
if (WaitForSingleObject(subProcess->hProcess, 2000) == WAIT_TIMEOUT)
TerminateProcess(subProcess->hProcess, 0);
// close the console
FreeConsole();
SetConsoleCtrlHandler(HandlerRoutine, FALSE);
}
CheckMounted();
}
示例11: AllocConsole
bool lConsole::Initialize(void *FileHandle, void *Stream, uint32_t ScreenbufferSize)
{
// Allocate a console if we don't have one.
if (!strstr(GetCommandLineA(), "-nocon"))
{
AllocConsole();
// Take ownership of it.
AttachConsole(GetCurrentProcessId());
// Set the standard streams to use the console.
freopen("CONOUT$", "w", (FILE *)Stream);
// Start the update thread.
if (!UpdateThread.joinable())
{
UpdateThread = std::thread(&lConsole::Int_UpdateThread, this);
UpdateThread.detach();
}
}
// Fill our properties.
ThreadSafe.lock();
this->FileHandle = FileHandle;
this->StreamHandle = Stream;
this->ShouldPrintScrollback = ScreenbufferSize != 0;
this->StartupTimestamp = GetTickCount64();
this->LastTimestamp = this->StartupTimestamp;
this->ScrollbackLineCount = ScreenbufferSize;
this->ScrollbackLines = new lLine[this->ScrollbackLineCount]();
this->ProgressbarCount = 0;
ThreadSafe.unlock();
return true;
}
示例12: AllocConsole
void Log::CreateConsole(LPCSTR caption)
{
AllocConsole();
AttachConsole(GetCurrentProcessId());
freopen("CON", "w", stdout); //-V530
SetConsoleTitleA(caption);
}
示例13: MainThread
bool MainThread()
{
AllocConsole();
AttachConsole( GetCurrentProcessId() );
freopen( "CON", "w", stdout );
gCVars.Initialize();
gMenu.Initialize();
printf("[Quake2 Engine Hook By Firehawk]\n");
printf("ModelView: 0x%x, Viewport: 0x%x, Projection: 0x%x\n", &ModelView, &Viewport, &Projection);
while ( !GameAPI )
GameAPI = GameAPI_t::Get();
while (!RenderAPI)
RenderAPI = RenderAPI_t::Get();
//Just to make sure it's hooked in the beginning
hkGetGameAPI(GameAPI);
hkGetRenderAPI(RenderAPI);
g_Memory.ApplyPatches();
printf("Memory patched!\n");
return true;
}
示例14: AllocConsole
BOOL SysConsole::Open( int x, int y, int w, int h )
{
BOOL r = AllocConsole();
if (!r)
return r;
AttachConsole(GetCurrentProcessId());
MoveWindow(GetConsoleWindow(), x, y, w, h, true);
m_cinbuf = std::cin.rdbuf();
m_console_cin.open("CONIN$");
std::cin.rdbuf(m_console_cin.rdbuf());
m_coutbuf = std::cout.rdbuf();
m_console_cout.open("CONOUT$");
std::cout.rdbuf(m_console_cout.rdbuf());
m_cerrbuf = std::cerr.rdbuf();
m_console_cerr.open("CONOUT$");
std::cerr.rdbuf(m_console_cerr.rdbuf());
FILE *stream;
freopen_s(&stream, "conin$", "r", stdin);
freopen_s(&stream, "conout$", "w", stdout);
freopen_s(&stream, "conout$", "w", stdout);
return r;
}
示例15: AllocConsole
void VulkanBase::setupConsole(std::string title) {
AllocConsole();
AttachConsole(GetCurrentProcessId());
freopen("CON", "w", stdout);
SetConsoleTitle(TEXT(title.c_str()));
if (enableValidation)
std::cout << "Validation enabled\n";
}