dotnet / pinvoke

A library containing all P/Invoke code so you don't have to import it every time. Maintained and updated to support the latest Windows OS.
MIT License
2.11k stars 220 forks source link

VerSetConditionMask fails on Win7 #597

Closed vatsan-madhavan closed 1 year ago

vatsan-madhavan commented 2 years ago

VerSetConditionMask relies on the API set DLL api-ms-win-core-sysinfo-l1-2-0, which causes calls to it to fail on Windows 7.

https://github.com/dotnet/pinvoke/blob/2634eea66089c199790fcb72982936fd123bba24/src/Kernel32/Kernel32.cs#L728-L730

 ---> System.DllNotFoundException: Unable to load DLL 'api-ms-win-core-sysinfo-l1-2-0.dll' or one of its dependencies: 
        The specified module could not be found. (0x8007007E)
   at PInvoke.Kernel32.VerSetConditionMask(Int64 ConditionMask, VER_MASK TypeMask, VER_CONDITION Condition)

What's the policy on Win7 support? If our goal is to keep these libraries in general working condition on Win7, it would make sense to point VerSetConditionMask at Kernel32 directly instead of an APISet DLL.

AArnott commented 2 years ago

Have you tried using CsWin32 for this function? I think it would use kernel32.

vatsan-madhavan commented 2 years ago

CsWin32 supports VerSetConditionMask, but I haven't given it a try. I'm frequently dealing with dual-mode API's (ones that are documented & available on both kernel and user mode) which CsWin32 doesn't support today (https://github.com/microsoft/win32metadata/issues/242).

In general, its simpler to rely on one system of P/Invokes [dotnet/pinvoke] over having a hybrid dependency on dotnet/pinvoke for some and CsWin32 for others (although I've found CsWin32 to be very helpful in a few other situations where I didn't expect to need dual-mode API's).