Win32控制台写入(C/C++)
Win32 console write (C/C++)
我想在C++程序中编写控制台,而不使用"std"库,也就是说,只使用"Windows.h"中的函数。原因是我想深入研究可移植的可执行文件,看到这一个函数被调用,而不是一堆函数层。有人知道如何做到这一点和/或在哪里可以找到"Windows.h"功能指南吗?
使用纯Win API:
HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (stdOut != NULL && stdOut != INVALID_HANDLE_VALUE)
{
DWORD written = 0;
const char *message = "hello world";
WriteConsoleA(stdOut, message, strlen(message), &written, NULL);
}
MSDN是您最好的文档来源之一:
- GetStdHandle
- WriteConsole
替代Win32 API:
#ifndef UNICODE
std::stringstream ss;
ss << TEXT("Hello world!") << std::endl;
OutputDebugString(ss.str().c_str());
OutputDebugStringA(ss.str().c_str());
#endif
#ifdef UNICODE
std::wstringstream wss;
wss << TEXT("Hello world!") << std::endl;
OutputDebugString(ss.str().c_str());
OutputDebugStringW(wss.str().c_str());
#endif
OutputDebugString是一个宏
参考:
- 调试时使用
OutputDebugString
- OutputDebugStringA函数(debugapi.h)-Win32应用程序|Microsoft文档
- OutputDebugStringW函数(debugapi.h)-Win32应用程序| Microsoft文档
相关文章:
- C++:将控制台输出存储在宏中更好吗
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- SSH通过/sbin/SSH无法读取RSA密钥文件(从控制台运行)
- C++控制台应用程序阻止退出
- 如何修复此iFile以将.txt输出到控制台
- 为什么控制台要求输入,即使代码中没有输入
- 在Qt Creator中,如何在连接到正在运行的进程后查看控制台输出
- 控制台输出在 Qt5 中未正确显示
- C++出现控制台错误.我无法识别源代码的问题
- C++程序不会从 Windows 控制台运行
- 有人可以向我解释为什么控制台输出 0 吗?
- Visual Studio 2017 停止工作,并在打开后显示许多控制台窗口
- 如何从 Win32 C++ 应用程序输出到父控制台窗口?
- Win32 API 控制台光标在 WriteConsole 后不移动
- 如何获取控制台窗口的宽度?
- 如何在 Win32 C++控制台应用程序中调用 UWP 类库
- 如何从Windows控制台调用.exe(C++)以在不同的目录(或任何目录)中创建文件夹?
- 来自Visual Studio中控制台项目的exe文件?
- 为什么即使使用 for 循环遍历我的向量,它也没有输出到控制台?(C++)
- 使用 std::string_view 的子字符串控制台输出