detects windows version, enables providers, sets event filters in realtime mode
| 233 | |
| 234 | // detects windows version, enables providers, sets event filters in realtime mode |
| 235 | ULONG EnableProviders( |
| 236 | TRACEHANDLE sessionHandle, |
| 237 | GUID const& sessionGuid, |
| 238 | PMTraceConsumer* pmConsumer) |
| 239 | { |
| 240 | ULONG status = 0; |
| 241 | |
| 242 | // Lookup what OS we're running on |
| 243 | // |
| 244 | // We can't use helpers like IsWindows8Point1OrGreater() since they FALSE |
| 245 | // if the application isn't built with a manifest. |
| 246 | bool isWin81OrGreater = false; |
| 247 | bool isWin11OrGreater = false; |
| 248 | { |
| 249 | auto hmodule = LoadLibraryExA("ntdll.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); |
| 250 | if (hmodule != NULL) { |
| 251 | auto pRtlGetVersion = (LONG (WINAPI*)(RTL_OSVERSIONINFOW*)) GetProcAddress(hmodule, "RtlGetVersion"); |
| 252 | if (pRtlGetVersion != nullptr) { |
| 253 | RTL_OSVERSIONINFOW info = {}; |
| 254 | info.dwOSVersionInfoSize = sizeof(info); |
| 255 | status = (*pRtlGetVersion)(&info); |
| 256 | if (status == 0 /* STATUS_SUCCESS */) { |
| 257 | // win8.1 = version 6.3 |
| 258 | // win11 = version 10.0 build >= 22000 |
| 259 | isWin81OrGreater = info.dwMajorVersion > 6 || (info.dwMajorVersion == 6 && info.dwMinorVersion >= 3); |
| 260 | isWin11OrGreater = info.dwMajorVersion > 10 || (info.dwMajorVersion == 10 && info.dwBuildNumber >= 22000); |
| 261 | } |
| 262 | } |
| 263 | FreeLibrary(hmodule); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | // Scope filtering based on event ID only works on Win8.1 or greater. |
| 268 | bool filterEventIds = isWin81OrGreater; |
| 269 | pmConsumer->mFilteredEvents = filterEventIds; |
| 270 | |
| 271 | return EnableProvidersListing(sessionHandle, &sessionGuid, pmConsumer, filterEventIds, isWin11OrGreater); |
| 272 | } |
| 273 | |
| 274 | void DisableProviders(TRACEHANDLE sessionHandle) |
| 275 | { |
no test coverage detected