创建注入外挂DEBUG控制台窗口print输出
// dllmain.cpp : 定义 DLL 应用程序的入口点。 #include "stdafx.h" #include "stdio.h" VOID PRT() { while (true) { printf("ddddddddddd \n"); Sleep(1000); } } VOID startDebugWindow() { //-------控制台用的-------------- HINSTANCE g_hInstance = 0; HANDLE g_hOutput = 0; HWND hwnd = NULL; HMENU hmenu = NULL; CHAR title[] = "不要关闭本窗口!否则主窗口关闭"; HANDLE hdlWrite = NULL; //--------------------- //------------------控制台----------------------- AllocConsole(); freopen("CONOUT$", "w+t", stdout); freopen("CONIN$", "r+t", stdin); g_hOutput = GetStdHandle(STD_OUTPUT_HANDLE); //设置控制台窗口的属性 SetConsoleTitle(title); SetConsoleTextAttribute((HANDLE)g_hOutput, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); while (NULL == hwnd) hwnd = ::FindWindow(NULL, (LPCTSTR)title); //屏蔽掉控制台窗口的关闭按钮,以防窗口被误删除 hmenu = ::GetSystemMenu(hwnd, FALSE); DeleteMenu(hmenu, SC_CLOSE, MF_BYCOMMAND); hdlWrite = GetStdHandle(STD_OUTPUT_HANDLE); //这里也可以使用STD_ERROR_HANDLE TCHAR c[] = {"Hello world!"};WriteConsole(hdlWrite, c, sizeof(c), NULL, NULL); } BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: CreateThread(0, 0, (LPTHREAD_START_ROUTINE)startDebugWindow, 0, 0, 0); CreateThread(0, 0, (LPTHREAD_START_ROUTINE)PRT, 0, 0, 0); case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; }