www.pudn.com > WDM_CharSample.rar > Test_CharSample.cpp
// Test_CharSample.cpp // // Generated by DriverWizard version DriverStudio 2.6.0 (Build 336) // // This console application demonstrates how to open a handle // to a device in your driver, and communicate with the driver // using Read, Write, and DeviceIoControl calls, as appropriate. // // This test program attempts to open the device using the // GUID defined in "..\CharSampleDeviceinterface.h" #include#include #include #include "..\CharSampleioctl.h" #include "..\CharSampleDeviceinterface.h" // Has class GUID definition // This function is found in module OpenByIntf.cpp HANDLE OpenByInterface(GUID* pClassGuid, DWORD instance, PDWORD pError); // Handle to device opened in driver. // HANDLE hDevice = INVALID_HANDLE_VALUE; // Class GUID used to open device // GUID ClassGuid = CharSampleDevice_CLASS_GUID; int __cdecl main(int argc, char *argv[]) { DWORD Error; printf("Test application Test_CharSample starting...\n"); hDevice = OpenByInterface( &ClassGuid, 0, &Error); if (hDevice == INVALID_HANDLE_VALUE) { printf("ERROR opening device: (%0x) returned from CreateFile\n", GetLastError()); exit(1); } else { printf("Device found, handle open.\n"); } CHAR bufInput[1]; // Input to device CHAR bufOutput[2]; // Output from device ULONG nOutput; // Count written to bufOutput printf("ÇëÊäÈëÊý×Ö(0-9)\n"); l0: bufInput[0]=_getch(); if ((bufInput[0]<'0') || (bufInput[0]>'9')) goto l0; _putch(bufInput[0]); // Call device IO Control interface (CHARSAMPLE_IOCTL_800) in driver if (!DeviceIoControl(hDevice, CHARSAMPLE_IOCTL_800, bufInput, 1, bufOutput, 2, &nOutput, NULL) ) { printf("ERROR: DeviceIoControl returns %0x.", GetLastError()); exit(1); } printf(":"); _putch(bufOutput[0]); _putch(bufOutput[1]); printf("\n"); return 0; }