Did you know that the entry point of a C++ program can be changed. It can be set from the linker option.
ProjectProperties -> Linker -> Advanced -> Entry Point
In the entry point we can set any function name and that will be the starting point of the program. Try it and have fun :).
How to have a console running behind your MFC or Win32 Application:
Well at times this things come in handy. Suppose you have made a MFC project and have initialized OpenGL in one of the windows. Now while drawing on the window you need to watch some values of animation. In such a case as the values of animation are being update continiously, to see those values via a message box will be very pathetic. The other way to see the values might be to dump them in a file and then see the files. Wouldn't it be better if you could have a console window running behind the MFC windows you have created. Well having a console running at the same time would be easy to debug things on run time as we can have printf statements dumping values in the console, while at the same time the MFC windows are working as usual.
This can be acheived very easily.
SubSytem can be set via :
ProjectProperties -> Linker -> System -> SubSystem
Entry Point can be set via :
ProjectProperties -> Linker -> Advanced -> Entry Point
A bit of playing around with the linker options. When you open a MFC project you have the following set as default :
The subsystem value is set as : Windows(/SUBSYSTEM:WINDOWS)
And for Entry point the value will be wWinMainCRTStartup if you are using MicrosoftVisual Studio 2003 or 2005. For VC6 the value will be winMainCRTStartup.
Changes needed to bring a console :
Set value of the subsytem to be : Console(/SUBSYSTEM:CONSOLE)
When you set the subsytem the Entry Point value will be blank. We need to set it to have the value it initally had that is wWinMainCRTStartup or winMainCRTStartup.
Thats all. Run the program and you will have a console running at the back where you can dump all the information you need.
Hope this helps.
-Reza
No comments:
Post a Comment