> For the complete documentation index, see [llms.txt](https://jen-hsuan-hsieh.gitbook.io/debugging-tools-experience/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jen-hsuan-hsieh.gitbook.io/debugging-tools-experience/422chu-cuo-gong-ju/4221visual-studio/4221zhong-duan-9ede3a-visual-studio.md).

# 5.1.1.輸出debug訊息

* 1.用途
  * 在不開啟視窗的情況下顯示debug訊息
* 2.用法
  * 有Visual studio的情況下: 加入OutputDebugString
    * 範例程式碼

      ```
      #include "stdafx.h"
      #include <stdio.h>
      #include <stdlib.h>
      #include <time.h>
      #include <windows.h>
      int main()
      {
      int sum = 0, i = 0;
      srand((unsigned)time(NULL));
      for (i = 0; i<1000; i++){ /* break point here */
      if (rand() % 100 == 0) {
          sum = sum + 1;
          OutputDebugString(_T("Hello, OutputDebugString.\n"));
      }
      }
      return 0;
      }
      ```
    * 視窗輸出 ![](https://github.com/jenhsuan/debugging-tools-experience/tree/91ad7a157f155ea77065c5600800bb4627bd1ae2/assets/螢幕快照%202017-06-19%20上午10.10.00.png)
  * 沒有Visual studio的情況下: 搭配使用DebugView
    * 1.下載[debugView](https://technet.microsoft.com/en-us/sysinternals/bb896647.aspx?f=255\&MSPPError=-2147217396)
    * 2.擊點安裝
    * 3.測試: 開啟debugView並確定Capture Win32有選起來, 並執行exe, debugview應該已經抓到輸出訊息

      ![](https://github.com/jenhsuan/debugging-tools-experience/tree/91ad7a157f155ea77065c5600800bb4627bd1ae2/assets/螢幕快照%202017-06-19%20上午10.03.40.png)

      ![](https://github.com/jenhsuan/debugging-tools-experience/tree/91ad7a157f155ea77065c5600800bb4627bd1ae2/assets/螢幕快照%202017-06-19%20上午10.07.07.png)
