openbyintf.cpp

来自「Windows 2000/XP WDM設備驅動程式開發 使用 Numega 公」· C++ 代码 · 共 58 行

CPP
58
字号
#include "stdafx.h"
#include "Test_PnPEvent.h"
#include "Test_PnPEventDlg.h"

// 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 <devintf.h>	// DriverWorks

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

// OpenByInterface
//
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();
	else 
	{
		CString msg;
		CTest_PnPEventDlg* pDlg=(CTest_PnPEventDlg*)AfxGetMainWnd();
		msg.Format("Device %s arrived", (LPCTSTR) DevInterface.DevicePath());
		pDlg->m_Events.AddString(msg);
	}

	return hDev;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?