How can you view printf output in a Win32 application (entering with a WinMain) in Visual Studio 2010?
相关问题
- Multiple sockets for clients to connect to
- How to know full paths to DLL's from .csproj f
- Importing NuGet references through a local project
- What is the best way to do a search in a large fil
- Visual Studio 2019 - error MSB8020: The build tool
Strictly answering your question, you may use printf-like functions in a Win32 application in Visual Studio 2010 using the winbase.h
OutputDebugString
function.I wrote a simple program that shows how to do it.
The
OutputDebugString
function takes anLPCSTR
as a parameter. I used thesprintf_s
to format the string before printing.This would print the result to the Visual Studio 2010 output window.
I hope it helps!
Here is a page that will tell you how to do this, including sample code.
You must create a console window using AllocConsole(), then associate the C standard file handles to the HANDLEs of the new console window.
Another way which wouldn't require changing existing printf's and also print to VS output window would go something like this:
For MinGW use "_A_SYSTEM" instead "_O_TEXT". So ported Quintin Willison answer is as follows:
Thanks torak for your answer. It helped me a lot.
I needed a bigger scroll back buffer so made a few additions after taking a look at the API functions. Shared here in case it helps anybody else:
This increases the scroll back (screen buffer) height to 9999 lines.
Tested on Windows XP and Windows 7.
You'll need a console window. By far the easiest way to get one is to change a linker option: Project + Properties, Linker, System, SubSystem = Console. Add a main() method: