Post List

2014년 12월 25일 목요일

MFC 에서 Debug용 Console 창 띄우기

참고 : http://moguwai.tistory.com/category/개발지식창고/MFC,
         http://kldp.org/node/105369

1. 첫번째 방법

#ifdef _DEBUG
#pragma comment(linker, "/entry:WinMainCRTStartup /subsystem:console")
#endif

를 선언 : stdafx.h에 해 놓으면 편리하다.

cout, printf 등으로 출력하면 console 창에 나온다.

2. 두번째 방법

App의 InitInstance에서 AllocConsole()을 호출한다. 

#ifdef _DEBUG

    if( !
AllocConsole() )
    {
        AfxMessage(_T("Failed to create the console!"), MB_ICONEXCLAMATION);
    }
#endif

해제하기 위해서는 ExitInstance에서 FreeColsole()을 호출한다.
#ifdef _DEBUG
    if( !FreeConsole() )
    {
        AfxMessage(_T("Failed to free the console!"), MB_ICONEXCLAMATION);
    }
#endif

WriteFile( GetStdHandle( STD_OUTPUT_HANDLE ), str , strlen( str ) , &size , NULL );



와 같은 형식으로 출력이 가능하다.

댓글 없음:

댓글 쓰기