Running a Win API app. from command line
Hi, I have a win32 app (using DirectX) that I want to be able to run from the command line as an option (it is a program for creating terrain textures). Now I have pretty much got it working apart from one minor issue.
I detect when it is run from a cmd prompt and then do AttachConsole( ATTACH_PARENT_PROCESS )
I can then write to the console with WriteConsole(...) fine.
When closing down I call FreeConsole()
Now the problem I have is that the command prompt does not return to the user - the path is not shown after my program exits. Does anyone know how I can fix this?
I just tested this out, and I found that the control does in fact return to the console - in fact control is never actually taken away from the console. I can still type and execute commands in the console window even while my code loops and writes text out. The tricky thing is that execution returns to the command line right away after the app's message loop starts, so the prompt actually prints right after you press Enter (more or less). Once the output starts, the prompt usually gets erased or lost, and when the program exits, the cursor just sits there looking dead.
Somehow the app needs to block the command line until execution finishes, which is a bit tricky because the app runs in a separate process and thread space. Unfortunately I can't offer you any good suggestions for getting around this, but maybe that will get you started.
Somehow the app needs to block the command line until execution finishes, which is a bit tricky because the app runs in a separate process and thread space. Unfortunately I can't offer you any good suggestions for getting around this, but maybe that will get you started.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement