-
Notifications
You must be signed in to change notification settings - Fork 0
/
winapi_utils.h
179 lines (139 loc) · 6.87 KB
/
winapi_utils.h
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/**********************************************************************************
** ENVIROMENT VARIABILE
**********************************************************************************/
#ifndef WIN_API_UTILS_H_
#define WIN_API_UTILS_H_
/**********************************************************************************
** GLOBAL INCLUDES
**********************************************************************************/
/**********************************************************************************
** DEFINES
**********************************************************************************/
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
//Maximum users allowed
#define WINAPI_UTILS_SEM_MAX_USERS 10
/**********************************************************************************
** MACROS
**********************************************************************************/
//handle have a special invalid value (0xf..f). NULL is 0x0..0)
#define IS_BAD_HANDLE( handle ) \
((handle == NULL) || (handle == INVALID_HANDLE_VALUE))
/**********************************************************************************
** TYPEDEF
**********************************************************************************/
/**********************************************************************************
** PROTOTYPE: STRUCTURE
**********************************************************************************/
/**********************************************************************************
** PROTOTYPE: GLOBAL VARIABILE
**********************************************************************************/
/**********************************************************************************
** PROTOTYPE: CLASS
**********************************************************************************/
using namespace std;
/****************************************************************************
** Class
**
*****************************************************************************
** PARAMETER:
** RETURN:
** DESCRIPTION:
****************************************************************************/
class Winapi_utils
{
//Visible to all
public:
///--------------------------------------------------------------------------
/// CONSTRUCTORS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// DESTRUCTORS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// SETTERS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// GETTERS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// TESTERS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// PUBLIC METHODS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// PUBLIC STATIC METHODS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// MISCELLEANOUS UTILITY FUNCTION
///--------------------------------------------------------------------------
//Get a random float
static float rand_float( float min, float max );
///--------------------------------------------------------------------------
/// HANDLE
///--------------------------------------------------------------------------
//Close an handle. FALSE -> OK
static bool close_handle( HANDLE htmp );
///--------------------------------------------------------------------------
/// Performance Counter
///--------------------------------------------------------------------------
// System Call that get the performance counter value
// QueryPerformanceCounter( &time_stamp );
// System call that get the frequency of the system
// QueryPerformanceFrequency( &freq );
//
//Calculate the difference in tick between two timestamps
static LARGE_INTEGER deltat( LARGE_INTEGER scnt, LARGE_INTEGER ecnt );
//Calculate the difference in tick between two timestamps
static float deltat( LARGE_INTEGER scnt, LARGE_INTEGER ecnt, LARGE_INTEGER freq );
//Calculate elapsed time
static float time_calc( LARGE_INTEGER scnt, LARGE_INTEGER ecnt );
///--------------------------------------------------------------------------
/// QueueTimer
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// Semaphores
///--------------------------------------------------------------------------
//Create a semaphore
static HANDLE born_sem( int max_users );
//Reserve a semaphore. return == FALSE: OK
static bool lock_sem( HANDLE hsem, int timeout );
//Release a semaphore. return == FALSE: OK
static bool unlock_sem( HANDLE hsem );
///--------------------------------------------------------------------------
/// Threads
///--------------------------------------------------------------------------
//Suspend a thread. Simple wrapper that prints errors
static bool pause_thread( HANDLE hthread );
//Resume a thread. return == FALSE: OK
static bool resume_thread( HANDLE hthread );
///--------------------------------------------------------------------------
/// PUBLIC VARS
///--------------------------------------------------------------------------
//Visible to derived classes
protected:
///--------------------------------------------------------------------------
/// PROTECTED VARS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// PROTECTED METHODS
///--------------------------------------------------------------------------
//Visible only inside the class
private:
///--------------------------------------------------------------------------
/// PRIVATE VARS
///--------------------------------------------------------------------------
///--------------------------------------------------------------------------
/// PRIVATE METHODS
///--------------------------------------------------------------------------
//Here so that i can easly copy the code.
bool dummy( void );
};
#else
#error "multiple inclusion of H"
#endif