DInput8HookingExample
DInput8HookingExample copied to clipboard
Unable to build using Visual Studio 2022 with the latest SDK
Basically similar issue to this https://stackoverflow.com/questions/7051558/ntqueryinformationprocess-wont-work-in-visual-studio-2010 The reason was due to linking an internal API (ie. Ntdll.dll) directly, where internal APIs are subject to change from one release of Windows to the next. https://github.com/pampersrocker/DInput8HookingExample/blob/b9b7e790fe0deb96c2c7884dcf5b3aac5a88c879/MinimalDInput8Hook/Hook.cpp#L12
Best practice is by importing it dynamically using GetProcAddress
.
For example:
typedef NTSTATUS(NTAPI* TFNNtQueryInformationProcess)(
IN HANDLE ProcessHandle,
IN PROCESSINFOCLASS ProcessInformationClass,
OUT PVOID ProcessInformation,
IN ULONG ProcessInformationLength,
OUT PULONG ReturnLength OPTIONAL
);
TFNNtQueryInformationProcess pfnNtQueryInformationProcess = nullptr;
pfnNtQueryInformationProcess = (TFNNtQueryInformationProcess)GetProcAddress(GetModuleHandle(TEXT("Ntdll.dll")), "NtQueryInformationProcess");
if (!pfnNtQueryInformationProcess) {
// Experimental only, should probably print this on the debug output and fallback to another version of NtQueryInformationProcess (if any)
MessageBox(NULL, TEXT("Failed to get NtQueryInformationProcess"), TEXT("Error"), MB_OK);
}