我需要手动设置线程的优先级,我使用GetProcessIdOfThread
. 不幸的是,第 3 方库要求我构建代码,Use MFC in a Shared DLL
以便我可以使用afx.h
一些 dll 技巧。
如何使用GetProcessIdOfThread
without之类的功能windows.h
?
我试图包含WinBase.h
,但这会抛出很多废话,编译错误。
我需要手动设置线程的优先级,我使用GetProcessIdOfThread
. 不幸的是,第 3 方库要求我构建代码,Use MFC in a Shared DLL
以便我可以使用afx.h
一些 dll 技巧。
如何使用GetProcessIdOfThread
without之类的功能windows.h
?
我试图包含WinBase.h
,但这会抛出很多废话,编译错误。
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);
我会通过将包装函数放在单独的 .c(pp) 文件中来解决这个问题:
#include <windows.h>
DWORD GetPidFromThread(HANDLE thread)
{
return GetProcessIdOfThread(thread);
}
您可能仍需要替换DWORD
和HANDLE
一些您也可以在其他文件中使用的类型[并使用 的原型制作头文件GetPidFromThread
,但至少您可以合理地安全地隔离这些位。