The following is a typical calling sequence for the WinDriver API.
![]() | |
|
HANDLE WD_Open(void);
INVALID_HANDLE_VALUE.
WD_License [B.6.9] for an
example of how to register your WinDriver license.
HANDLE hWD;
hWD = WD_Open();
if (hWD == INVALID_HANDLE_VALUE)
{
printf("Cannot open WinDriver device\n");
}
DWORD WD_Version(
HANDLE hWD,
WD_VERSION *pVer);
| Name | Type | Input/Output |
|---|---|---|
| hWD | HANDLE | Input |
| pVer | WD_VERSION* | |
| • dwVer | DWORD | Output |
| • cVer | CHAR[128] | Output |
| Name | Description |
|---|---|
| hWD | Handle to WinDriver's kernel-mode driver as
received from WD_Open [B.6.2] |
| pVer | Pointer to a WinDriver version information structure: |
| • dwVer | The version number |
| • cVer |
Version information string. The version string's size is limited to 128 characters (including the NULL terminator character). |
WD_STATUS_SUCCESS(0) on success, or
an appropriate error code otherwise [B.8].
WD_VERSION ver;
BZERO(ver);
WD_Version(hWD, &ver);
printf("%s\n", ver.cVer);
if (ver.dwVer < WD_VER)
{
printf("Error - incorrect WinDriver version\n");
}
void WD_Close(HANDLE hWD);
| Name | Type | Input/Output |
|---|---|---|
| hWD | HANDLE | Input |
| Name | Description |
|---|---|
| hWD | Handle to WinDriver's kernel-mode driver as
received from WD_Open [B.6.2] |
WD_Close(hWD);
DWORD WD_Debug(
HANDLE hWD,
WD_DEBUG *pDebug);
| Name | Type | Input/Output |
|---|---|---|
| hWD | HANDLE | Input |
| pDebug | WD_DEBUG* | Input |
| • dwCmd | DWORD | Input |
| • dwLevel | DWORD | Input |
| • dwSection | DWORD | Input |
| • dwLevelMessageBox | DWORD | Input |
| • dwBufferSize | DWORD | Input |
| Name | Description |
|---|---|
| hWD | Handle to WinDriver's kernel-mode driver as
received from WD_Open [B.6.2] |
| pDebug | Pointer to a debug information structure: |
| • dwCmd |
Debug command: Set filter, Clear buffer, etc. For more details please refer to DEBUG_COMMAND in
windrvr.h.
|
| • dwLevel |
Used for dwCmd=DEBUG_SET_FILTER. Sets the debugging level to
collect: Error, Warning, Info, Trace. For more details please refer to DEBUG_LEVEL in
windrvr.h.
|
| • dwSection |
Used for dwCmd=DEBUG_SET_FILTER. Sets the sections to
collect: I/O, Memory, Interrupt, etc. Use S_ALL for all.
For more details please refer to DEBUG_SECTION in
windrvr.h.
|
| • dwLevelMessageBox |
Used for dwCmd=DEBUG_SET_FILTER. Sets the debugging level to
print in a message box. For more details please refer to DEBUG_LEVEL in
windrvr.h.
|
| • dwBufferSize |
Used for dwCmd=DEBUG_SET_BUFFER. The size of buffer in the
kernel.
|
WD_STATUS_SUCCESS(0) on success, or
an appropriate error code otherwise [B.8].
WD_DEBUG dbg; BZERO(dbg); dbg.dwCmd = DEBUG_SET_FILTER; dbg.dwLevel = D_ERROR; dbg.dwSection = S_ALL; dbg.dwLevelMessageBox = D_ERROR; WD_Debug(hWD, &dbg);
DWORD WD_DebugAdd(
HANDLE hWD,
WD_DEBUG_ADD *pData);
| Name | Type | Input/Output |
|---|---|---|
| hWD | HANDLE | Input |
| pData | WD_DEBUG_ADD* | |
| • dwLevel | DWORD | Input |
| • dwSection | DWORD | Input |
| • pcBuffer | CHAR[256] | Input |
| Name | Description |
|---|---|
| hWD | Handle to WinDriver's kernel-mode driver as
received from WD_Open [B.6.2] |
| pData | Pointer to an additional debug information structure: |
| • dwLevel |
Assigns the level in the Debug Monitor, in which the data will be
declared. If dwLevel is 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 dwSection is zero, S_MISC section will be
declared. For more details please refer to DEBUG_SECTION in
windrvr.h.
|
| • pcBuffer | The string to copy into the message log. |
WD_STATUS_SUCCESS(0) on success, or
an appropriate error code otherwise [B.8].
WD_DEBUG_ADD add;
BZERO(add);
add.dwLevel = D_WARN;
add.dwSection = S_MISC;
sprintf(add.pcBuffer, "This message will be displayed in "
"the Debug Monitor\n");
WD_DebugAdd(hWD, &add);
DWORD WD_DebugDump(
HANDLE hWD,
WD_DEBUG_DUMP *pDebugDump);
| Name | Type | Input/Output |
|---|---|---|
| hWD | HANDLE | Input |
| pDebug | WD_DEBUG_DUMP* | Input |
| • pcBuffer | PCHAR | Input/Output |
| • dwSize | DWORD | Input |
| Name | Description |
|---|---|
| hWD | Handle to WinDriver's kernel-mode driver as
received from WD_Open [B.6.2] |
| pDebugDump | Pointer to a debug dump information structure: |
| • pcBuffer | Buffer to receive debug messages |
| dwSize | Size of buffer in bytes |
WD_STATUS_SUCCESS(0) on success, or
an appropriate error code otherwise [B.8].
char buffer[1024]; WD_DEBUG_DUMP dump; dump.pcBuffer=buffer; dump.dwSize = sizeof(buffer); WD_DebugDump(hWD, &dump);
DWORD WD_Sleep(
HANDLE hWD,
WD_SLEEP *pSleep);
| Name | Type | Input/Output |
|---|---|---|
| hWD | HANDLE | Input |
| pSleep | WD_SLEEP* | |
| • dwMicroSeconds | DWORD | Input |
| • dwOptions | DWORD | Input |
| Name | Description |
|---|---|
| hWD | Handle to WinDriver's kernel-mode driver as
received from WD_Open [B.6.2] |
| pSleep | Pointer to a sleep information structure: |
| • dwMicroSeconds | Sleep time in microseconds–1/1,000,000 of a second. |
| • dwOptions |
A bit-mask, which can be set to either of the following: • Zero (0) – Busy sleep (default)OR: • SLEEP_NON_BUSY – Delay execution
without consuming CPU resources. (Not relevant for under 17,000 micro
seconds. Less accurate than busy sleep).
|
WD_STATUS_SUCCESS(0) on success, or
an appropriate error code otherwise [B.8].
WD_Sleep slp; BZERO(slp); slp.dwMicroSeconds = 200; WD_Sleep(hWD, &slp);
• Transfers the license string to the WinDriver kernel module and returns information regarding the license type of the specified license string.
NOTE:
When using the WDU USB APIs [B.2]
your WinDriver license registration is done via the call to
WDU_Init [B.4.1], so you do not need
to call WD_License directly from your code.
DWORD WD_License(
HANDLE hWD,
WD_LICENSE *pLicense);
| Name | Type | Input/Output |
|---|---|---|
| hWD | HANDLE | Input |
| pLicense | WD_LICENSE* | |
| • cLicense | CHAR[] | Input |
| • dwLicense | DWORD | Output |
| • dwLicense2 | DWORD | Output |
| Name | Description |
|---|---|
| hWD | Handle to WinDriver's kernel-mode driver as
received from WD_Open [B.6.2] |
| pLicense | Pointer to a WinDriver license information structure: |
| • cLicense |
A buffer to contain the license string that is to be transferred to the
WinDriver kernel module. If an\ empty string is transferred, then WinDriver
kernel module returns the current license type to the parameter
dwLicense.
|
| • dwLicense |
Returns the license type of the specified license string
(cLicnese). The return value is a bit-mask of license flags,
defined as an enum in windrvr.h. Zero
signifies an invalid license string. Additional flags for determining the
license type are returned in dwLicense2, if needed.
|
| • dwLicense2 |
Returns additional flags for determining the license type, if
dwLicense cannot hold all the relevant information
(otherwise – zero)
|
WD_STATUS_SUCCESS(0) on success, or
an appropriate error code otherwise [B.8].
WD_Open [B.6.2], in order to register the license from the code.
DWORD RegisterWinDriver()
{
HANDLE hWD;
WD_LICENSE lic;
DWORD dwStatus = WD_INVALID_HANDLE;
hWD = WD_Open();
if (hWD!=INVALID_HANDLE_VALUE)
{
BZERO(lic);
/* Replace the following string with your license string: */
strcpy(lic.cLicense, "12345abcde12345.CompanyName");
dwStatus = WD_License(hWD, &lic);
WD_Close(hWD);
}
return dwStatus;
}