• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ AttachConsole函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中AttachConsole函数的典型用法代码示例。如果您正苦于以下问题:C++ AttachConsole函数的具体用法?C++ AttachConsole怎么用?C++ AttachConsole使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了AttachConsole函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: LogFileInitialize

void LogFileInitialize(const char* strFileName)
{
#ifndef DISABLE_LOG

    FILE* f = NULL;
    const char* logFilename;

    if (strFileName == NULL)
    {
        SP_strcpy(LogfilePath, SP_MAX_PATH, "c:\\splog.txt");
        logFilename = GetLogFilename();
    }
    else
    {
        logFilename = strFileName;
        SP_strcpy(LogfilePath, SP_MAX_PATH, strFileName);
    }

    // It is valid for there to be no Log File. However since this
    // is the only place where the log file is initialized, we flag
    // it as something to note in the console.

    if (logFilename != NULL)
    {
        // Open for writing - this will overwrite any previous logfile
#ifdef _WIN32
        fopen_s(&f, logFilename, "w+");    // read binary
#else
        f = fopen(logFilename, "w+");
#endif

        if (f != NULL)
        {
            fprintf(f, "Logging Started: %s\n\n", StringUtils::GetTimeString().c_str());
            fclose(f);
        }
        else
        {
            Log(logERROR, "Unable to open logfile %s for writing \n", logFilename);
        }
    }

#ifdef WIN32

    if (s_ConsoleAttached == false)
    {
        // ensure the log system is attached to a console
        // AttachConsole requires Win 2K or later.
        AttachConsole(ATTACH_PARENT_PROCESS);
        s_ConsoleAttached = true;
    }

#endif

#else
    SP_UNREFERENCED_PARAMETER(strFileName);
#endif   //DISABLE_LOG
}
开发者ID:PlusChie,项目名称:CodeXL,代码行数:58,代码来源:Logger.cpp


示例17: w__openConsole

int w__openConsole(lua_State *L)
{
	static bool is_open = false;

	if (is_open)
	{
		love::luax_pushboolean(L, is_open);
		return 1;
	}

	is_open = true;

	// FIXME: we don't call AttachConsole in Windows XP because it seems to
	// break later AllocConsole calls if it fails. A better workaround might be
	// possible, but it's hard to find a WinXP system to test on these days...
	if (!IsWindowsVistaOrGreater() || !AttachConsole(ATTACH_PARENT_PROCESS))
	{
		// Create our own console if we can't attach to an existing one.
		if (!AllocConsole())
		{
			is_open = false;
			love::luax_pushboolean(L, is_open);
			return 1;
		}

		SetConsoleTitle(TEXT("LOVE Console"));

		const int MAX_CONSOLE_LINES = 5000;
		CONSOLE_SCREEN_BUFFER_INFO console_info;

		// Set size.
		GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &console_info);
		console_info.dwSize.Y = MAX_CONSOLE_LINES;
		SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), console_info.dwSize);
	}

	FILE *fp;

	// Redirect stdout.
	fp = freopen("CONOUT$", "w", stdout);
	if (L && fp == NULL)
		return luaL_error(L, "Console redirection of stdout failed.");

	// Redirect stdin.
	fp = freopen("CONIN$", "r", stdin);
	if (L && fp == NULL)
		return luaL_error(L, "Console redirection of stdin failed.");

	// Redirect stderr.
	fp = freopen("CONOUT$", "w", stderr);
	if (L && fp == NULL)
		return luaL_error(L, "Console redirection of stderr failed.");

	love::luax_pushboolean(L, is_open);
	return 1;
}
开发者ID:RobLoach,项目名称:love,代码行数:56,代码来源:love.cpp


示例18: AllocConsole

void Utils::AllocateConsole(LPCSTR pTitle)
{
	AllocConsole() ;
	AttachConsole(GetCurrentProcessId());
	freopen("CON", "w", stdout) ;
	SetConsoleTitleA(pTitle);
	COORD cordinates = {80, 32766};
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleScreenBufferSize(handle, cordinates);
}
开发者ID:Novo,项目名称:rAPB,代码行数:10,代码来源:Utils.cpp


示例19: GetStdHandle

Console::Console()
{
	// Attach to the parent console if available, otherwise allocate one
	if(!AttachConsole(ATTACH_PARENT_PROCESS)) AllocConsole();

	// Get the input/output handles for the attached console
	m_stderr = GetStdHandle(STD_ERROR_HANDLE);
	m_stdin = GetStdHandle(STD_INPUT_HANDLE);
	m_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
}
开发者ID:zukisoft,项目名称:vm,代码行数:10,代码来源:Console.cpp


示例20: AllocConsole

void Debug::Initialize()
{
	AllocConsole();
	AttachConsole(GetCurrentProcessId());
	consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);

#if _DEBUG
	Debug::Log("Debug Initialized");
#endif
}
开发者ID:ariabonczek,项目名称:NewLumina,代码行数:10,代码来源:Debug.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ AttachThreadInput函数代码示例发布时间:2022-05-30
下一篇:
C++ AttachChild函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap