当前位置: 首页>>代码示例>>C++>>正文


C++ AttachConsole函数代码示例

本文整理汇总了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;
  }
}
开发者ID:meh,项目名称:MSYS2-packages,代码行数:7,代码来源:main.c

示例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);
}
开发者ID:Azizou,项目名称:XaoS,代码行数:31,代码来源:ui_win32.c

示例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);
	}
}
开发者ID:HappyerKing,项目名称:wireshark,代码行数:28,代码来源:sshdump.c

示例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);
   }
}
开发者ID:evilrix,项目名称:sweetie-rush,代码行数:25,代码来源:main.cpp

示例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;
}
开发者ID:LiminWang,项目名称:mpv,代码行数:28,代码来源:terminal-win.c

示例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;
}
开发者ID:madnessw,项目名称:thesnow,代码行数:26,代码来源:LocalizeCS.cpp

示例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;
}
开发者ID:JickLee,项目名称:Core,代码行数:27,代码来源:sdlapp.cpp

示例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;
}
开发者ID:edzer,项目名称:cxxr,代码行数:29,代码来源:rgui.c

示例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()));
        }
    }

}
开发者ID:FireFlyForLife,项目名称:Rocket-League-Chroma-Control,代码行数:30,代码来源:attachtorllog.cpp

示例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();
}
开发者ID:HirasawaRUS,项目名称:encfs4win,代码行数:33,代码来源:drives.cpp

示例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;
}
开发者ID:KerriganEN,项目名称:OpenNetPlugin,代码行数:35,代码来源:lConsole.cpp

示例12: AllocConsole

void Log::CreateConsole(LPCSTR caption)
{
	AllocConsole();
	AttachConsole(GetCurrentProcessId());
	freopen("CON", "w", stdout); //-V530
	SetConsoleTitleA(caption);
}
开发者ID:FaceHunter,项目名称:hAPI,代码行数:7,代码来源:Log.cpp

示例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;
}
开发者ID:xghozt,项目名称:Q2Bot,代码行数:26,代码来源:Main.cpp

示例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;
		}
开发者ID:dotminic,项目名称:code,代码行数:25,代码来源:SysConsole.cpp

示例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";
}
开发者ID:Alexandcoats,项目名称:vulkan-terrain,代码行数:8,代码来源:VulkanBase.cpp


注:本文中的AttachConsole函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。