Missing entry points in USER32.dll stops program f

2020-04-21 06:36发布

问题:

I'm writing a C++ program using VS2015 (Platform Toolset v140, Target Platform 8.1) on a Windows 10 machine, and my program ran just fine on Windows 7, 8 and 10 up until recently.

After adding touch support using GetPointerInfo(), I get this pop-up error immediately on execution on Windows 7 machines:

Unable to find an entry point named GetPointerInfo in USER32.dll

MS clearly states that GetPointerInfo() is only supported on Win8 and up, and that's all right, but I don't want to break my program's compatibility with Windows 7 altogether.

I assume Windows 7's version of USER32.DLL doesn't containing the function at all, but adding runtime checks in my program (i.e. only calling GetPointerInfo() if IsWindows8OrGreater() returns true) doesn't do the trick.

In fact, merely compiling my program with any reference to GetPointerInfo() will break Win7 compatibility, no matter if the function is actually called or not. The program won't even enter WinMain(), it just throws me that message and quits.

Again, on Windows 8 and up, everything is working just fine.

How do I solve this?

I have Googled for half a day, but having very little knowledge of DLLs, linker and compiler settings, I obviously don't even know how to phrase my searches because I have come up empty so far.

I have tried both Multi-threaded (/MT) and Multi-threaded DLL (/MD) as my Runtime Library.

I have also tried enabling and disabling Function-Level Linking, but the result remains the same.

回答1:

I assume Windows 7's version of USER32.dll doesn't containing the function at all

That is correct.

but adding runtime checks in my program (i.e. only calling GetPointerInfo on IsWindows8OrGreater) doesn't do the trick. :(

It does if you load the function dynamically at runtime, either by using your linker's delay-loading feature, or using GetProcAddress() directly in your code (the linker's delay loader uses GetProcAddress() internally for you).

In fact, merely compiling my program with any reference to GetPointerInfo will break Win7 compatibility, no matter if the funcion is actually called or not.

That error happens only if you static-link to the function at compile-time without using the linker's delay-load feature.



回答2:

Thanks a lot.

GetProcAddress() is a great method for me. I have encounter the same problem. And I have referenced this website about using GetProcAddress()!

1.write some definitions

typedef BOOL(WINAPI *GetPointerInfoProc)(UINT32,POINTER_INFO *);

2.delay loading library

HMODULE hModule = LoadLibrary(TEXT("user32.dll")); GetPointerInfoProc GetPointerInfo = (GetPointerInfoProc )GetProcAddress(hModule, "GetPointerInfo");

3.call method

GetPointerInfo(pointerId,&pointerInfo)