DriverStudio

/*****************************************************************************

* 功能: 通过GUID打开设备,获得设备句柄

* 参数: 

*****************************************************************************/

HANDLE lOpenByInterface(

  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=0;

 

 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;

}

//WDF驱动

HANDLE CxDriverInterface::SetupDevInterfaces(DWORD dev_interface_index, int board_type)

{

 HANDLE hd_invalid = INVALID_HANDLE_VALUE;

 DWORD required_buf_size;

 GUID *pGuid = (LPGUID)&GUID_DEVINTERFACE_ATHENA;

if ( board_type == Athena_EVK )

 {

  pGuid = (LPGUID)&GUID_DEVINTERFACE_ATHENA;

 }

 else if( (board_type == Atlas_Plus_EVK) || (board_type == Atlas_EVK) )

 {

  pGuid = (LPGUID)&GUID_DEVINTERFACE_ATLAS;

 }

//Get handle to our device information set that contains requested device information elements

 HDEVINFO devInfoSetHandle = SetupDiGetClassDevs(pGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);

 if ( devInfoSetHandle == INVALID_HANDLE_VALUE )

 {

  TRACE("SetupDiGetClassDevs failed to find device GUID in system! \n");

  return hd_invalid;

 }

SP_INTERFACE_DEVICE_DATA devInterfaceInfo;

 devInterfaceInfo.cbSize = sizeof(devInterfaceInfo);

// Try to enumerate the device interfaces that are contained in device information set just retrieved

 if( !SetupDiEnumDeviceInterfaces( devInfoSetHandle, NULL, pGuid, dev_interface_index, &devInterfaceInfo ) )

 {

  TRACE("SetupDiEnumDeviceInterfaces failed to enumerate device GUID! \n");

  SetupDiDestroyDeviceInfoList(devInfoSetHandle);

  return hd_invalid;

 }

// Get the required buffer size and allocate proper sized buffer

 SetupDiGetDeviceInterfaceDetail( devInfoSetHandle, &devInterfaceInfo, NULL, 0, &required_buf_size, NULL );

 PSP_INTERFACE_DEVICE_DETAIL_DATA devInterfaceDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc (required_buf_size);

if( devInterfaceDetail == NULL )

 {

  TRACE("SetupDiGetDeviceInterfaceDetail failed! \n");

  SetupDiDestroyDeviceInfoList( devInfoSetHandle );

  return hd_invalid;

 }

// Get details for the device interface

 devInterfaceDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);

 if( !SetupDiGetDeviceInterfaceDetail( devInfoSetHandle, &devInterfaceInfo, devInterfaceDetail, required_buf_size, NULL, NULL) )

 {

  TRACE("SetupDiGetDeviceInterfaceDetail failed to set SP_INTERFACE_DEVICE_DETAIL_DATA! \n");

  SetupDiDestroyDeviceInfoList( devInfoSetHandle );

  delete devInterfaceDetail;

  return hd_invalid;

 }

 //前面这部分在Driverworks中用两个类来完成

 // Get device handle

 LPCWSTR dev_path = devInterfaceDetail->DevicePath;

 HANDLE dev_hd = CreateFile( devInterfaceDetail->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

if( dev_hd == INVALID_HANDLE_VALUE )

 {

  TRACE("Failed to create device handleB!");

  exit(1);

 }

delete devInterfaceDetail;

if ( devInfoSetHandle )

  SetupDiDestroyDeviceInfoList( devInfoSetHandle );

return dev_hd;

}

DriverStudio 和 WDF驱动 通过GUID获取设备句柄的差别的更多相关文章

  1. WDF驱动中KMDF与UMDF区别

    抄的 早期的Windows 95/98的设备驱动是VxD(Virtual Device Driver),其中x表示某一类设备.从Windows 2000开始,开发驱动程序必以WDM(Windows D ...

  2. WDF驱动的编译、调试、安装

    编译和调试使用WDK编译,源代码应包括wdf.h,ntddk.h以及KMDF_VERSION=1,编译使用/GS.KMDF包括以下库:1). WdfDriverEntry.lib(编译时绑定):驱动入 ...

  3. win7 vs2012+wdk8.0 搭建wdf驱动开发环境

    开发环境搭建:系统:win7 x64工具:vs2012 + WDK8.0插件:wdfcoinstaller.msi(1)先安装vs2012,再安装wdk8.0,这样在打开vs2012时可以创建wind ...

  4. vs2012+wdk8.0 搭建wdf驱动开发环境

    开发环境搭建: 系统:win7 x64 工具:vs2012 + WDK8.0 插件:wdfcoinstaller.msi (1)先安装vs2012,再安装wdk8.0,这样在打开vs2012时可以创建 ...

  5. 基于WDF的PCI/PCIe接口卡Windows驱动程序(4)- 驱动程序代码(源文件)

    原文出处:http://www.cnblogs.com/jacklu/p/4687325.html 本篇文章将对PCIe驱动程序的源文件代码作详细解释与说明.整个WDF驱动程序工程共包含4个头文件(已 ...

  6. 基于WDF的PCI/PCIe接口卡Windows驱动程序(2)-开发者需要了解的WDF中的一些重要的概念

    原文出处:http://www.cnblogs.com/jacklu/p/4646601.html 本科毕业设计是这方面的工作,所以想开几篇博客来介绍使用WDF开发PCI/PCIe接口卡的驱动程序方法 ...

  7. 用Setup系列函数完成驱动卸载安装[驱动安装卸载程序]

    // InstallWDFDriver.cpp : Defines the entry point for the console application. // #include "std ...

  8. windows设备驱动安装接口(自己仿写)

    /***************************************** Author:foo_hack This is File named:Setup.h The Funtion Im ...

  9. RT-Thread 设备驱动ADC浅析与改进

    OS版本:RT-Thread 4.0.0 芯片:STM32F407 下面时官方ADC提供的参考访问接口 访问 ADC 设备 应用程序通过 RT-Thread 提供的 ADC 设备管理接口来访问 ADC ...

随机推荐

  1. DDMS和程序打包过程

    1. Android版本对应api级别 2.3~~~~~10 3.0~~~~~11 4.0~~~~~14 4.1.2~~~16 2.3和4.1.2是最稳定的 2.Android手机常见分辨率 320* ...

  2. [DeeplearningAI笔记]改善深层神经网络1.4_1.8深度学习实用层面_正则化Regularization与改善过拟合

    觉得有用的话,欢迎一起讨论相互学习~Follow Me 1.4 正则化(regularization) 如果你的神经网络出现了过拟合(训练集与验证集得到的结果方差较大),最先想到的方法就是正则化(re ...

  3. ABP官方文档翻译 5.1 Web API控制器

    ASP.NET Web API控制器 介绍 AbpApiController基类 本地化 其他 过滤器 审计日志 授权 反伪造过滤器 工作单元 结果包装和异常处理 结果缓存 校验 模型绑定器 介绍 A ...

  4. Jquery DataTable控制显示列,导出EXCEL

    1.初始化 var table = $('#table').DataTable({ "data": data[0].DATA, "columns": data[ ...

  5. Springboot security cas整合方案-原理篇

    前言:网络中关于Spring security整合cas的方案有很多例,对于Springboot security整合cas方案则比较少,且有些仿制下来运行也有些错误,所以博主在此篇详细的分析cas原 ...

  6. CheckStyle

    在Eclipse当中安装CheckStyle插件非常方便,和安装FindBugs除了URL有区别之外,其他的几乎完全一样.我们可以参照以下几个步骤进行(注意一下,eclipse版本不一样,可能安装插件 ...

  7. bzoj 3509: [CodeChef] COUNTARI] [分块 生成函数]

    3509: [CodeChef] COUNTARI 题意:统计满足\(i<j<k, 2*a[j] = a[i] + a[k]\)的个数 \(2*a[j]\)不太好处理,暴力fft不如直接暴 ...

  8. Git点滴记录

    合并多个commit记录 假设我们当前有三个commit信息,现在要将commit hash为 23f92c 和 409978 合并 //git rebase -i HEAD~3 那么我们可以使用 r ...

  9. Function与Object的关系

    这里先简单介绍一下我研究这个问题的初衷.起初我只是想研究一下原型链的基本思想.构造函数拥有prototype属性,指向它的prototype,而该构造函数的实例化对象则拥有一个[[prototype] ...

  10. golang GET 出现 x509: certificate signed by unknown authority

    我们编写一个Go程序来尝试与这个HTTPS server建立连接并通信. //gohttps/4-https/client1.gopackage main import (    "fmt& ...