gpt4 book ai didi

c++ - AllocConsole() 不显示 cout

转载 作者:IT老高 更新时间:2023-10-28 12:49:54 27 4
gpt4 key购买 nike

我有一个 DLL,我在其中使用 AllocConsole() 和 cout 来显示数据以进行调试。
它曾经可以正常工作,但由于我将编译器 (Visual Studio 2012) 更新到最新版本,因此 dll 仅显示控制台,但不显示打印/输出。
我不知道为什么会这样。
有什么想法吗?

我的部分代码

__declspec(dllexport) INT APIENTRY DllMain(HMODULE hDLL, DWORD Reason, LPVOID Reserved)
{
switch(Reason)
{
case DLL_PROCESS_ATTACH:
AllocConsole();

DisableThreadLibraryCalls(hDLL);

//
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)pSend, MySend);
if(DetourTransactionCommit() == NO_ERROR)
cout << "[" << MySend << "] successfully detoured." << endl;

但什么都没有显示。

最佳答案

我隐约记得您可能需要将标准输出重定向到控制台。不过我可能是错的(因为你的代码之前工作过):

AllocConsole();
freopen("CONOUT$", "w", stdout);
std::cout << "This works" << std::endl;

关于c++ - AllocConsole() 不显示 cout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15543571/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com