Click here to Skip to main content
12,894,708 members (60,052 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 24 Aug 2005

Printf() debugging in a console window from within an ActiveX control

, 30 Aug 2005
Rate this:
Please Sign up or sign in to vote.
Creating a console window from within an ActiveX control.


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)
  // TODO : Add Code for message handler.

  // Call DefWindowProc if necessary. 

  /* create a seperate console window for
     printf (print, println and debug) output */
  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.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Stephen Muccione
Web Developer
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralDebug Techniques Pin
Anonymous31-Aug-05 21:15
sussAnonymous31-Aug-05 21:15 
GeneralRe: Debug Techniques Pin
Stephen Muccione1-Sep-05 1:10
memberStephen Muccione1-Sep-05 1:10 
Questionprintf or fprintf...? Pin
Anonymous30-Aug-05 3:52
sussAnonymous30-Aug-05 3:52 
AnswerRe: printf or fprintf...? Pin
Stephen Muccione30-Aug-05 14:57
memberStephen Muccione30-Aug-05 14:57 
GeneralRe: printf or fprintf...? Pin
LudditeSD14-May-09 5:22
memberLudditeSD14-May-09 5:22 
Generalsome notes Pin
pullover30-Aug-05 3:04
memberpullover30-Aug-05 3:04 
GeneralRe: some notes Pin
Stephen Muccione30-Aug-05 3:39
memberStephen Muccione30-Aug-05 3:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170424.1 | Last Updated 30 Aug 2005
Article Copyright 2005 by Stephen Muccione
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid