Use printf () to debug ActiveX controls in the console window
Article from:
Http://www.codeproject.com/Articles/11420/Printf-debugging-in-a-console-window-from-within-a
Introduction
OK, here's the deal... in the process of developing an ActiveX control for processing sion 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.
When developing ActiveX controls used by browsers, I need to monitor a lot of data. Using standard breakpoints can be cumbersome and worse, and controls can run abnormally on remote machines.
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 cocould see so I decided to try a quick test.
All I need is easy to monitor data. I decided to see if it is possible to create a console window from the control. I did not find the answer on the Internet. I decided to test it myself.
As it turns out, it was quite simple to do. To Doprintf()
Debugging from within a control, all you need to do is modify
YourOnCreate()
Method as follows:
The results show that it is easy to implement. To use printf () in the control, you need to modify oncreate () as follows ():
Collapse | copy
Code
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { // TODO : Add Code for message handler. // Call DefWindowProc if necessary. /* create a seperate console window for printf (print, println and debug) output */ AllocConsole(); freopen ("CONOUT$", "w", stdout ); return 0; }
You'll also need to include the appropriate Headers<Stdio. h>And you shoshould now be able to useprintf()
From
Anywhere in your code.
You should include <stdio. h> and can use the printf () function anywhere.
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.
There should be other methods to trace the output, but this can be used without other tools.
Note: Although I haven't done it, It shoshould also be possible to remapstdin
And take input from the console window
Shocould you need to implement a simple debug console.
Note: Although I have not tried it, it should be able to remap stdin and get input information from the console window.
Just another one for the Toolkit... use it as you will.