1

我需要手动设置线程的优先级,我使用GetProcessIdOfThread. 不幸的是,第 3 方库要求我构建代码,Use MFC in a Shared DLL以便我可以使用afx.h一些 dll 技巧。

如何使用GetProcessIdOfThreadwithout之类的功能windows.h

我试图包含WinBase.h,但这会抛出很多废话,编译错误。

4

2 回答 2

5

Provided your downstream linker settings are correct, you can simply add the function declaration to a project header file of your choosing.

Here's the original declaration in WinBase.h:

WINBASEAPI DWORD WINAPI GetProcessIdOfThread(HANDLE Thread);

If you're not including Windows.h, then you're not going to have most of the used preprocessor macros/definitions necessary for that particular declaration. If you're linking against the static library version of the CRT, this is the equivalent definition:

unsigned long __stdcall GetProcessIdOfThread(void *Thread);

If you're linking against the DLL version of the CRT, you'll need to prefix the declaration with __declspec(dllimport):

__declspec(dllimport) unsigned long __stdcall GetProcessIdOfThread(void *Thread);
于 2013-01-25T20:58:01.197 回答
4

我会通过将包装函数放在单独的 .c(pp) 文件中来解决这个问题:

 #include <windows.h>


 DWORD GetPidFromThread(HANDLE thread)
 {
     return GetProcessIdOfThread(thread);
 }

您可能仍需要替换DWORDHANDLE一些您也可以在其他文件中使用的类型[并使用 的原型制作头文件GetPidFromThread,但至少您可以合理地安全地隔离这些位。

于 2013-01-25T21:11:16.967 回答