Console Attachment problem

Started by
2 comments, last by rip-off 12 years, 6 months ago
what im doing is injecting a dll into my program. This dll is then allocating a console and outputting debug information. The problem is when im done with my console and i close it the program also closes with it. it's almost like the console becomes one with the program. Any help on how to resolve this issue? i am using the following code to make and write to my console




AllocConsole();
freopen("CONOUT{:content:}quot;, "wb", stdout);

printf(" DEBUG CONSOLE YAY ");


fclose(stdout);
FreeConsole();
Advertisement
You can try using CreateProcess() followed by AttachConsole instead. That should create them in separate processes.
if i use createprocess() then it will have it's own address space. I still want access to the program im wanting to debug's addresspace as well. Will this still work? Also createprocess won't work with a dll correct? the debug console code would need to be in a .exe?
You have two options with consoles. One is to create one yourself in the process. When the process dies, so will the console. A second option is to attach to the parent console, if any. If you then run the program from the command line, it will attach to that console, which will persist when the program ends.

I believe Seraph was advocating the latter, except with a stub executable that would call CreateProcess() on the executable you want to inject. I do not believe Seraph was not suggesting you invoke CreateProcess() inside the injected process, so I won't try to address your questions (I don't know the answers anyway).

This topic is closed to new replies.

Advertisement