OpenByIntf.cpp
上传用户:lyfy_2008
上传日期:2014-07-13
资源大小:3016k
文件大小:1k
- // OpenByIntf.cpp - open device by device interface
- // Copyright (c) 1998 Compuware Corporation
- #define NOCRYPT // prevent attempt to include missing files
- #define _INC_EXCPT // prevent excpt.h from being included
- //#include <stdlib.h>
- #include"stdafx.h"
- #include <windows.h>
- #include <winioctl.h>
- #include <devintf.h> // DriverWorks
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG-NEW
- #endif
- // OpenByInterface
- //
- // Opens the nth device found with the given interface class
- HANDLE OpenByInterface(
- GUID* pClassGuid, // points to the GUID that identifies the interface class
- DWORD instance, // specifies which instance of the enumerated devices to open
- PDWORD pError // address of variable to receive error status
- )
- {
- HANDLE hDev;
- CDeviceInterfaceClass DevClass(pClassGuid, pError);
- if (*pError != ERROR_SUCCESS)
- return INVALID_HANDLE_VALUE;
- CDeviceInterface DevInterface(&DevClass, instance, pError);
- if (*pError != ERROR_SUCCESS)
- return INVALID_HANDLE_VALUE;
- hDev = CreateFile(
- DevInterface.DevicePath(),
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL,
- NULL
- );
- if (hDev == INVALID_HANDLE_VALUE)
- *pError = GetLastError();
- return hDev;
- }