www.pudn.com > PCI9054.rar > Test_PCI9054.cpp
// Test_PCI9054.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 "..\PCI9054Deviceinterface.h" #include#include #include "..\PCI9054Deviceinterface.h" // Has class GUID definition // This function is found in module OpenByIntf.cpp HANDLE OpenByInterface(GUID* pClassGuid, DWORD instance, PDWORD pError); // Prototypes void CloseIfOpen(void); void doRead(void); void doWrite(char i); // Handle to device opened in driver. // HANDLE hDevice = INVALID_HANDLE_VALUE; // Class GUID used to open device // GUID ClassGuid = PCI9054Device_CLASS_GUID; //////////////////////////////////////////////////////////////////////// // Exit // // Print a message and exit // void Exit(int res) { printf("Exiting...\n\n"); CloseIfOpen(); exit(res); } //////////////////////////////////////////////////////////////////////// // Main entry point // // int __cdecl main(int argc, char *argv[]) { int val; DWORD Error; printf("Test application Test_PCI9054 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"); } // Parse the command line val=32; doWrite(val); doRead(); return 0; } void CloseIfOpen(void) { if (hDevice != INVALID_HANDLE_VALUE) { // Close the handle to the driver if (!CloseHandle(hDevice)) { printf("ERROR: CloseHandle returns %0x.\n", GetLastError()); } hDevice = INVALID_HANDLE_VALUE; } } void doWrite(char n) { char *buf; ULONG nWritten; int i; buf = (char *) malloc(n); if (buf == NULL) { printf("Failed to allocate buffer for write"); Exit(1); } for (i=0; i