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

來源:互聯網
上載者:User

使用Printf()在控制台視窗中調試activex控制項

文章來自:

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 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.

在開發瀏覽器使用的activex控制項的過程中,我需要監測許多資料。使用標準斷點會變得很笨重,而且事情會變得更糟糕,控制項在遠端機器上會表現異常。

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:

結果證明,它是很容易實現的。為了可以在控制項中使用printf(),你所需要的就是按照如下修改oncreate():

 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 should now be able to use printf() from
anywhere in your code.

你應該包括<stdio.h>並且可以在任何地方使用printf()函數。

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.

注釋:雖然我沒有實驗,它應該可以重新對應stdin並且可以從控制台視窗擷取輸入資訊。

Just another one for the toolkit... use it as you will.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.