Sign in to follow this  

AllocConsole/AttachConsole

This topic is 3490 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
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
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

This topic is 3490 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this