可以使用 _stprintf_s 和 _ui64tow_s 函数将 HANDLE 转换为字符串类型。

示例代码:

#include <Windows.h>
#include <tchar.h>
#include <string>

int main()
{
    HANDLE handle = GetCurrentProcess();
    TCHAR handleStr[20];
    _stprintf_s(handleStr, _T("%llu"), (unsigned long long)handle);
    std::wstring str = handleStr;
    return 0;
}

这里使用了 _T 宏来支持 Unicode 字符串,使用了 unsigned long long 类型来避免 HANDLE 转换为负数。最后将 TCHAR 数组转换为 std::wstring 类型的字符串。

C++ HANDLE 转string

原文地址: https://www.cveoy.top/t/topic/g89T 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录