This section describes a number of user-mode utility functions you will find useful for implementing various tasks. These utility functions are multi-platform, implemented on all operating systems supported by WinDriver.
Retrieves the status string that corresponds to a status code.
const char *Stat2Str(DWORD dwStatus);
| Name | Type | Input/Output |
|---|---|---|
| dwStatus | DWORD | Input |
| Name | Description |
|---|---|
| • dwStatus | A numeric status code |
Returns the verbal status description (string) that corresponds to the specified numeric status code.
See
Retrieves the type of the operating system.
OS_TYPE get_os_type(void);
Returns the type of the operating system.
If the operating system type is not detected, returns
OS_CAN_NOT_DETECT.
Creates a thread.
DWORD ThreadStart(
HANDLE *phThread,
HANDLER_FUNC pFunc,
void *pData);
| Name | Type | Input/Output |
|---|---|---|
| phThread | HANDLE* | Output |
| pFunc |
typedef void (*HANDLER_FUNC)( void *pData); | Input |
| pData | VOID* | Input |
| Name | Description |
|---|---|
| phThread | Returns the handle to the created thread |
| pFunc |
Starting address of the code that the new thread is to execute. (The
handler's prototype — HANDLER_FUNC — is defined in
utils.h).
|
| pData | Pointer to the data to be passed to the new thread |
Returns WD_STATUS_SUCCESS (0) on success, or an appropriate
error code otherwise
Waits for a thread to exit.
void ThreadWait(HANDLE hThread);
| Name | Type | Input/Output |
|---|---|---|
| hThread | HANDLE | Input |
| Name | Description |
|---|---|
| hThread | The handle to the thread whose completion is awaited |
None
Creates an event object.
DWORD OsEventCreate(HANDLE *phOsEvent);
| Name | Type | Input/Output |
|---|---|---|
| phOsEvent | HANDLE* | Output |
| Name | Description |
|---|---|
| phOsEvent | The pointer to a variable that receives a handle to the newly created event object |
Returns WD_STATUS_SUCCESS (0) on success, or an appropriate
error code otherwise
Closes a handle to an event object.
void OsEventClose(HANDLE hOsEvent);
| Name | Type | Input/Output |
|---|---|---|
| hOsEvent | HANDLE | Input |
| Name | Description |
|---|---|
| hOsEvent | The handle to the event object to be closed |
None
Waits until a specified event object is in the signaled state or the time-out interval elapses.
DWORD OsEventWait(
HANDLE hOsEvent,
DWORD dwSecTimeout);
| Name | Type | Input/Output |
|---|---|---|
| hOsEvent | HANDLE | Input |
| dwSecTimeout | DWORD | Input |
| Name | Description |
|---|---|
| hOsEvent | The handle to the event object |
| dwSecTimeout |
Time-out interval of the event, in seconds. For an infinite wait, set the timeout to INFINITE.
|
Returns WD_STATUS_SUCCESS (0) on success, or an appropriate
error code otherwise
Sets the specified event object to the signaled state.
DWORD OsEventSignal(HANDLE hOsEvent);
| Name | Type | Input/Output |
|---|---|---|
| hOsEvent | HANDLE | Input |
| Name | Description |
|---|---|
| hOsEvent | The handle to the event object |
Returns WD_STATUS_SUCCESS (0) on success, or an appropriate
error code otherwise
Resets the specified event object to the non-signaled state.
DWORD OsEventReset(HANDLE hOsEvent);
| Name | Type | Input/Output |
|---|---|---|
| hOsEvent | HANDLE | Input |
| Name | Description |
|---|---|
| hOsEvent | The handle to the event object |
Returns WD_STATUS_SUCCESS (0) on success, or an appropriate
error code otherwise
Creates a mutex object.
DWORD OsMutexCreate(HANDLE *phOsMutex);
| Name | Type | Input/Output |
|---|---|---|
| phOsMutex | HANDLE* | Output |
| Name | Description |
|---|---|
| phOsMutex | The pointer to a variable that receives a handle to the newly created mutex object |
Returns WD_STATUS_SUCCESS (0) on success, or an appropriate
error code otherwise
Closes a handle to a mutex object.
void OsMutexClose(HANDLE hOsMutex);
| Name | Type | Input/Output |
|---|---|---|
| hOsMutex | HANDLE | Input |
| Name | Description |
|---|---|
| hOsMutex | The handle to the mutex object to be closed |
None
Locks the specified mutex object.
DWORD OsMutexLock(HANDLE hOsMutex);
| Name | Type | Input/Output |
|---|---|---|
| hOsMutex | HANDLE | Input |
| Name | Description |
|---|---|
| hOsMutex | The handle to the mutex object to be locked |
Returns WD_STATUS_SUCCESS (0) on success, or an appropriate
error code otherwise
Releases (unlocks) a locked mutex object.
DWORD OsMutexUnlock(HANDLE hOsMutex);
| Name | Type | Input/Output |
|---|---|---|
| hOsMutex | HANDLE | Input |
| Name | Description |
|---|---|
| hOsMutex | The handle to the mutex object to be unlocked |
Returns WD_STATUS_SUCCESS (0) on success, or an appropriate
error code otherwise
Sends debug messages to the Debug Monitor.
void PrintDbgMessage(
DWORD dwLevel,
DWORD dwSection,
const char *format
[, argument]...);
| Name | Type | Input/Output |
|---|---|---|
| dwLevel | DWORD | Input |
| dwSection | DWORD | Input |
| format | const char* | Input |
| argument | Input |
| Name | Description |
|---|---|
| dwLevel |
Assigns the level in the Debug Monitor, in which the data will be declared.
If zero, D_ERROR will be declared.For more details please refer to DEBUG_LEVEL in
windrvr.h.
|
| dwSection |
Assigns the section in the Debug Monitor, in which the data will be
declared. If zero, S_MISC will be declared.For more details please refer to DEBUG_SECTION in windrvr.h. |
| format | Format-control string |
| argument | Optional arguments, limited to 256 bytes |
None
Opens a log file.
DWORD WD_LogStart(
const char *sFileName,
const char *sMode);
| Name | Type | Input/Output |
|---|---|---|
| sFileName | const char* | Input |
| sMode | const char* | Input |
| Name | Description |
|---|---|
| sFileName | Name of log file to be opened |
| sMode |
Type of access permitted. For example, NULL or w opens an empty file for writing, and if the given file exists, its contents are destroyed; a opens a file for writing at the end of the file (i.e., append). |
Returns WD_STATUS_SUCCESS (0) on success, or an appropriate
error code otherwise
Once a log file is opened, all API calls are logged in this file.
You may add your own printouts to the log file by calling
WD_LogAdd()
Adds user printouts into log file.
VOID DLLCALLCONV WD_LogAdd(
const char *sFormat
[, argument ]...);
| Name | Type | Input/Output |
|---|---|---|
| sFormat | const char* | Input |
| argument | Input |
| Name | Description |
|---|---|
| sFormat | Format-control string |
| argument | Optional format arguments |
Returns WD_STATUS_SUCCESS (0) on success, or an appropriate
error code otherwise