Click here to Skip to main content
Licence 
First Posted 24 Aug 2005
Views 30,670
Bookmarked 18 times

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

By | 30 Aug 2005 | Article
Creating a console window from within an ActiveX control.

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)
 {
  // 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 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.

License

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

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralDebug Techniques PinsussAnonymous21:15 31 Aug '05  
GeneralRe: Debug Techniques PinmemberStephen Muccione1:10 1 Sep '05  
Questionprintf or fprintf...? PinsussAnonymous3:52 30 Aug '05  
AnswerRe: printf or fprintf...? PinmemberStephen Muccione14:57 30 Aug '05  
GeneralRe: printf or fprintf...? PinmemberLudditeSD5:22 14 May '09  
Generalsome notes Pinmemberpullover3:04 30 Aug '05  
GeneralRe: some notes PinmemberStephen Muccione3:39 30 Aug '05  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.5.120517.1 | Last Updated 30 Aug 2005
Article Copyright 2005 by Stephen Muccione
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid