cout和printf在内置调试的Dll上无法运行 [英] cout and printf Works On Dll Built In Debug Not Release

查看:87
本文介绍了cout和printf在内置调试的Dll上无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个通常通过SetWindowHookEx注入到控制台应用程序中的DLL.对于DLL将信息输出到控制台(与std :: cout一起使用),这一点很重要.DLL即将完成,直到我尝试在发布模式下构建DLL为止,这使所有cout行都变得无用了.我已经验证了DLL正在注入并且正在执行简单的null取消引用,该引用导致程序在dllmain函数中崩溃.与std :: printf相同.

I've built a DLL that gets injected into a console application usually via SetWindowHookEx. Its important for the DLL to output information to the console which I have been doing with std::cout. The DLL was nearing completion until I tried building the DLL in release mode which rendered all cout lines useless. I've verified the the DLL is injecting and is executing by doing a simple null dereference that causes the program to crash in the dllmain function. Same story with std::printf.

void onAttach()
{
    //WARNING THIS IS A DEMONSTRATION
    std::cout<<"test"<<std::endl;
    //int* intPtr = 0;
    //*intPtr = 3; //This causes a crash
}

// entry point
BOOL WINAPI DllMain ( HMODULE hModule, DWORD dwReason, LPVOID lpReserved )
{
    switch ( dwReason )
    {
        case DLL_PROCESS_ATTACH:
            DisableThreadLibraryCalls ( hModule );
            CreateThread ( NULL, 0, ( LPTHREAD_START_ROUTINE ) onAttach, NULL, 0, NULL );
            return true;
        break;

        case DLL_PROCESS_DETACH:
            return true;
        break;
    }
}

我真的不知道该如何解决这个问题.发布链接程序是否以某种方式排除了依赖关系?

I really don't know how to approach this problem. Is the Release linker somehow excluding dependencies?

我正在使用MSVS 2010和默认的发布/调试配置设置.调试dll约为5137kb,发布dll仅为23kb.

I'm using MSVS 2010 and default release/debug configuration setup. The debug dll is about 5,137kb and the release dll is only 23kb.

推荐答案

我知道@salters是正确的,它指出不应在DLL中进行对其他库的调用,但是经过反复试验,我发现编译该DLL是x64配置的(而不是x86),DLL可以退出"或显示使用"MessageBox"功能,而不会出现任何问题(可能会从许多其他库中调用功能).希望这会有所帮助:).

I know @salters is correct in stating that no calls to other libraries should be made in a DLL, but after trial and error I've found that compiling the DLL's in x64 configuration (instead of x86) the DLL's can "cout" or show use the "MessageBox" function without any issues (can likely call functions from a number of other libraries). Hope this helps :).

这篇关于cout和printf在内置调试的Dll上无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆