如何在 Windows 2016 Server 版本 1607 中访问 SetThreadDescription()
How to access SetThreadDescription() in Windows 2016 Server, Version 1607
如果我只是从WinAPI调用SetThreadDescription()
,它可以在Windows 10版本2004上运行。但是,在 Windows 2016 Server 1607 上,它会生成以下消息框:
过程入口点 SetThreadDescription 无法在动态链接库中找到
我的可执行程序的路径遵循消息。
根据这篇文章:
SetThreadDescription 仅通过 Run Time Dynamic Links 在 上可用 视窗服务器 2016, 1607.
所以我尝试了如下动态链接:
typedef HRESULT (WINAPI *TSetThreadDescription)(HANDLE, PCWSTR);
namespace {
TSetThreadDescription gpSetThreadDescription = nullptr;
}
void Initialize() {
HMODULE hKernel32 = GetModuleHandleA("Kernel32.dll");
if (hKernel32 == nullptr) {
cerr << "FATAL: failed to get kernel32.dll module handle, error: " << GetLastError() << endl;
quick_exit(5);
}
gpSetThreadDescription = reinterpret_cast<TSetThreadDescription>(
GetProcAddress(hKernel32, "SetThreadDescription"));
if (gpSetThreadDescription == nullptr) {
cerr << "FATAL: failed to get SetThreadDescription() address, error: " << GetLastError() << endl;
quick_exit(6);
}
}
此代码也适用于 Windows 10。但是,我在Windows Server 127上收到错误2016("找不到指定的过程"(。
我在运行时动态链接方面做错了什么?
显然,尽管MSDN说"DLL:Kernel32.dll",但该函数实际上是KernelBase.DLL
,所以我在更改为
HMODULE hKernelBase = GetModuleHandleA("KernelBase.dll");
相关文章:
- 通过方法访问结构
- 使用不带参数的函数访问结构元素
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- 用于访问容器<T>数据成员的正确 API
- 访问者访问变体并返回不同类型时出错
- 尝试通过多个向量访问变量时,向量下标超出范围
- 无法访问嵌套类.类的使用无效
- 写入位置0x0000000C时发生访问冲突
- 我们可以访问一个不存在的联盟的成员吗
- C++从另一个类访问公共静态向量的正确方法是什么
- 我的简单if-else语句是如何无法访问的代码
- 从C++dll访问C#中的一行主要参数
- 概念TS检查忽略私有访问修饰符
- 访问被拒绝后,c++中的故障保护代码
- 在c++中访问int到类对象的映射时出错
- 我想访问std::unique_ptr中的一个特定元素
- 为什么示例代码访问IUnknown中已删除的内存
- C++:无法访问声明的受保护成员
- 通过指向指针数组的指针访问子类的属性
- 如何使用单独文件中的派生类访问友元函数对象