-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwpdh.h
More file actions
114 lines (94 loc) · 2.35 KB
/
Copy pathwpdh.h
File metadata and controls
114 lines (94 loc) · 2.35 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef _INC_WPDH_
#define _INC_WPDH_
#include <windows.h>
#ifdef __cplusplus
#include <wbase.h>
#ifndef EXTERN_C
#define EXTERN_C extern "C"
#endif
/**
Base class for all kernel object wrapping classes.
Uses CloseHandle() on the embedded handle when object is destroyed.
*/
class WPDHQuery : public WObjectHandle
{
public:
explicit WPDHQuery(PDH_HLOG hDataSource,
DWORD_PTR dwUserData = 0)
{
PDH_STATUS status = PdhOpenQueryH(hDataSource, dwUserData, &hObject);
if (status != NO_ERROR)
{
SetLastError(status);
hObject = NULL;
}
}
explicit WPDHQuery(LPCWSTR szDataSource = NULL,
DWORD_PTR dwUserData = 0)
{
PDH_STATUS status = PdhOpenQueryW(szDataSource, dwUserData, &hObject);
if (status != NO_ERROR)
{
SetLastError(status);
hObject = NULL;
}
}
explicit WPDHQuery(LPCSTR szDataSource,
DWORD_PTR dwUserData = 0)
{
PDH_STATUS status = PdhOpenQueryA(szDataSource, dwUserData, &hObject);
if (status != NO_ERROR)
{
SetLastError(status);
hObject = NULL;
}
}
/// Init with existing handle.
explicit WPDHQuery(PDH_HQUERY handle)
: WObjectHandle(handle)
{
}
/// Init with handle from other object.
explicit WPDHQuery(const WPDHQuery& obj)
: WObjectHandle(obj.Handle())
{
}
/// Closes existing object and init with handle from other object.
WPDHQuery& operator=(const WPDHQuery& obj)
{
SetHandle(obj.Handle());
return *this;
}
/// Closes existing object and init with supplied handle.
WPDHQuery& operator=(PDH_HQUERY handle)
{
SetHandle(handle);
return *this;
}
/// Closes existing object and init with supplied handle.
void SetHandle(PDH_HQUERY handle)
{
Close();
hObject = handle;
}
/// Closes the handle.
~WPDHQuery()
{
Close();
}
/// Closes the embedded handle if it is valid.
bool Close()
{
if (!IsValidHandle(hObject))
return false;
if (PdhCloseQuery(hObject) == NO_ERROR)
{
hObject = INVALID_HANDLE_VALUE;
return true;
}
else
return false;
}
};
#endif // __cplusplus
#endif // _INC_WIO_