Jump to content
  • Advertisement
Sign in to follow this  
lordcorm

AllocConsole/AttachConsole

This topic is 3704 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im making a DLL that will enable my console. But when i enable the console, my printf doesnt show up. (This is using DLL injection BTW)
#include <windows.h>
#include <iostream>

BOOL WINAPI DllMain(HANDLE hinstDLL, DWORD dwReason, 
					LPVOID lpvReserved)
{
	switch(dwReason)
	{

	case DLL_PROCESS_ATTACH:
		{
			AllocConsole();
			AttachConsole(GetProcessId(hinstDLL));
			printf("Can you see me?\n");
			break;
		}

	}
	return true;
}

Any help would be much appriciated. Lordcorm

Share this post


Link to post
Share on other sites
Advertisement
Ok, well, i found out why, and wanted to post here so it would help people when they use the search function :).

The answer is to use _cprintf() instead of printf().

But, now i have one last question. How do i reroute printf() to _cprintf()? Because the DLL am making is so i can enable the console window from a program that is already compiled, and i dont have the source for.

Also, i doubt the program im attaching to uses cout, but is there a way to reroute that to _cprintf()? Im thinking function pointers.

Share this post


Link to post
Share on other sites
You need to redirect STDOUT to your console if you want printf and cout to be output there. You should be able to find an article or two if you search google.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
You need to redirect STDOUT to your console if you want printf and cout to be output there. You should be able to find an article or two if you search google.


Thanks a bunch, sorry i didnt search google before asking.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!