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?
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.