Introduction
OK, here's the deal... In the process of developing an ActiveX control for inclusion in a browser, I had developed a need to watch a large amount of data. It became very cumbersome to use the standard breakpoint debugging, and to make matters worse, the control was misbehaving on a remote machine.
Needing to be able to see the data easily, I decided to see if it was possible to create a console window from within the control. A web search didn't turn up anything as far as I could see so I decided to try a quick test.
As it turns out, it was quite simple to do. To do printf()
debugging from within a control, all you need to do is modify your OnCreate()
method as follows:
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
AllocConsole();
freopen ("CONOUT$", "w", stdout );
return 0;
}
You'll also need to include the appropriate headers <stdio.h> and you should now be able to use printf()
from anywhere in your code.
There are certainly other methods of tracing output... but this is guaranteed to be available and viewable on machines that don't have any tools installed.
Note: although I haven't done it, it should also be possible to remap stdin
and take input from the console window should you need to implement a simple debug console.
Just another one for the toolkit... use it as you will.