-
Notifications
You must be signed in to change notification settings - Fork 478
Expand file tree
/
Copy pathIsWindowsVersion.h
More file actions
69 lines (60 loc) · 2.13 KB
/
Copy pathIsWindowsVersion.h
File metadata and controls
69 lines (60 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.
#ifndef __ISWINDOWSVERSION_H
#define __ISWINDOWSVERSION_H
#include <VersionHelpers.h>
#include <wil/resource.h>
namespace WindowsVersion
{
inline bool IsExportPresent(
PCWSTR filename,
PCSTR functionName)
{
wil::unique_hmodule dll{ LoadLibraryExW(filename, nullptr, 0) };
if (!dll)
{
const DWORD rcLoadLibraryError = GetLastError();
THROW_HR_IF(HRESULT_FROM_WIN32(rcLoadLibraryError), rcLoadLibraryError != ERROR_MOD_NOT_FOUND);
return false;
}
auto function{ GetProcAddress(dll.get(), functionName) };
if (!function)
{
const DWORD rcGetProcAddressError = GetLastError();
THROW_HR_IF(HRESULT_FROM_WIN32(rcGetProcAddressError), rcGetProcAddressError != ERROR_PROC_NOT_FOUND);
return false;
}
return true;
}
inline bool IsWindows10_19H1OrGreater()
{
// GetPackageInfo2() added to kernelbase.dll in 19H1 (aka NTDDI_WIN10_19H1)
return IsExportPresent(L"kernelbase.dll", "GetPackageInfo2");
}
inline bool IsWindows10_20H1OrGreater()
{
// GetPackageInfo3() added to kernelbase.dll in 20H1 (aka NTDDI_WIN10_VB)
return IsExportPresent(L"kernelbase.dll", "GetPackageInfo3");
}
inline bool IsWindows11_21H2OrGreater()
{
// GetMachineTypeAttributes() added to kernelbase.dll in Windows 11 21H2 (aka NTDDI_WIN10_CO)
return IsExportPresent(L"kernelbase.dll", "GetMachineTypeAttributes");
}
inline bool IsWindows11_22H2OrGreater()
{
// GetPackageGraphRevisionId() added to kernelbase.dll in Windows 11 22H2 (aka NTDDI_WIN10_NI)
return IsExportPresent(L"kernelbase.dll", "GetPackageGraphRevisionId");
}
inline bool IsWindows11_24H1OrGreater()
{
// TryCreatePackageDependency2() added to in Windows 11 24H1 (aka NTDDI_WIN11_GE)
return IsExportPresent(L"kernelbase.dll", "TryCreatePackageDependency2");
}
inline bool IsWindows11_24H2OrGreater()
{
// MsixIsPackageFeatureSupported() added to in Windows 11 24H2 (aka NTDDI_WIN11_GE)
return IsExportPresent(L"appxdeploymentclient.dll", "MsixIsPackageFeatureSupported");
}
}
#endif // __ISWINDOWSVERSION_H