BEGIN
\ \
\ \ \END
3 TEXTINCLUDE DISCARDABLE BEGIN \ \END
#endif // APSTUDIO_INVOKED
#endif // Chinese (P.R.C.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
///////////////////////////////////////////////////////////////////////////// //
// Generated from the TEXTINCLUDE 3 resource. //
///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED Exe
TestPciSample.cpp
// Test_PCISample.cpp : Defines the entry point for the console application.
//
#include \
#include
#include \
PCHAR
GetDevicePath(
IN LPGUID InterfaceGuid );
void doRead(void); void doWrite(void);
HANDLE hDevice = INVALID_HANDLE_VALUE;
int main(int argc, char* argv[]) { PCHAR DevicePath; printf(\
DevicePath = GetDevicePath((LPGUID)&PCISample_DEVINTERFACE_GUID);
hDevice = CreateFile(DevicePath,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0,
NULL );
if (hDevice == INVALID_HANDLE_VALUE) { printf(\ return 0; } printf(\
doWrite(); doRead();
if (hDevice != INVALID_HANDLE_VALUE) { CloseHandle(hDevice); } return 0; }
PCHAR
GetDevicePath(
IN LPGUID InterfaceGuid ) {
HDEVINFO HardwareDeviceInfo;
SP_DEVICE_INTERFACE_DATA DeviceInterfaceData;
PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData = NULL; ULONG Length, RequiredLength = 0; BOOL bResult;
HardwareDeviceInfo = SetupDiGetClassDevs( InterfaceGuid, NULL, NULL,
(DIGCF_PRESENT | DIGCF_DEVICEINTERFACE));
if (HardwareDeviceInfo == INVALID_HANDLE_VALUE) { printf(\ exit(1); }
DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
bResult = SetupDiEnumDeviceInterfaces(HardwareDeviceInfo, 0,
InterfaceGuid, 0,
&DeviceInterfaceData);
if (bResult == FALSE) {
printf(\
SetupDiDestroyDeviceInfoList(HardwareDeviceInfo);
exit(1); }
SetupDiGetDeviceInterfaceDetail( HardwareDeviceInfo, &DeviceInterfaceData, NULL, 0,
&RequiredLength, NULL );
DeviceInterfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA) LocalAlloc(LMEM_FIXED, RequiredLength);
if (DeviceInterfaceDetailData == NULL) {
SetupDiDestroyDeviceInfoList(HardwareDeviceInfo); printf(\ exit(1); }
DeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
Length = RequiredLength;
bResult = SetupDiGetDeviceInterfaceDetail( HardwareDeviceInfo, &DeviceInterfaceData, DeviceInterfaceDetailData, Length,
&RequiredLength, NULL);
if (bResult == FALSE) {
printf(\
SetupDiDestroyDeviceInfoList(HardwareDeviceInfo); LocalFree(DeviceInterfaceDetailData); exit(1); }
return DeviceInterfaceDetailData->DevicePath; }
void doRead(void) { char buf[32],*f; ULONG nRead; int i,j; // Read data from driver printf(\ ReadFile(hDevice, buf, 32, &nRead, NULL); printf(\ // Print what was read f=buf; for (i=0;i<2;i++) { for (j=0;j<16;j++) {
fprintf(stderr, \ };
fprintf(stderr, \ }; }
void doWrite(void) { char buf[32],*f; ULONG nWritten; int i,j; for (i=0; i<32; i++) { buf[i] = i; } // Write data to driver printf(\ WriteFile(hDevice, buf, 32, &nWritten, NULL); printf(\ // Print what was written f=buf; for (i=0;i<2;i++) { for (j=0;j<16;j++) {