jiangyonghua
驱动牛犊
驱动牛犊
  • 注册日期2003-05-06
  • 最后登录2003-06-25
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1608回复:7

设备标示符GUID不一样?

楼主#
更多 发布于:2003-06-06 16:52
  我用DriverWorks生成了一个USB设备驱动,硬件是D12 smart USB开发板,我发现驱动的*.inf
文件中的GUID
和测试程序中头文件中定义的GUID不一样?
我有点胡涂了?
我在测试程序里也找不到识别GUID的API函数?
那位还能向我解释一下,硬件,驱动,系统,三者是如何识别的一个
过程?
谢谢! :o :o
windyguy
驱动牛犊
驱动牛犊
  • 注册日期2003-05-07
  • 最后登录2004-05-28
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-06-06 18:58
.inf中的是ClassGuid,不是你设备的Guid,当然不同。

去msdn 看看,或者找书……
kxgchina
驱动小牛
驱动小牛
  • 注册日期2002-04-01
  • 最后登录2005-05-05
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-06-06 20:35
你就说得清楚些吧,楼上的,有时候看书看的不太明白的,并不是所有的提问的人,都是不看书的人,呵呵
jason.gao
驱动小牛
驱动小牛
  • 注册日期2002-05-08
  • 最后登录2003-11-12
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2003-06-06 22:34
难得进来一趟,我说两句,呵呵。

INF中也可能有很多GUID(对某些设备的),所以楼主应该说清楚一点。但ClassGUID是每个INF中都有的,大致是与安装有关吧(具体起怎样的作用,我也不太明白,毕竟INF中的安装指示都是标准的,好象有时候可以扩展安装程序吧,比如那个co-class setup什么的)

头文件中也可能有很多GUID,又不知道楼主说的哪个。好象定义USB设备的Interface时会用到GUID吧。如果是这个,那两者是完全不相关的。(而且,你的头文件中是绝对不可能有安装程序中的ClassGUID的,所以总之是不相关,哈)

因为对MS的体系,凡是需要作唯一标识时都会用GUID,实在太多了,呵呵。

对后一个问题,说说从设备插上到driver装好的过程吧,不知道是否切题。

USB设备插上后,USB总线驱动检测到设备(及其VID,PID),报告给I/O管理器,从而启运安装程序,按一定的策略检索INF(XP居然会从网上搜索),或者向用户要求,主要是按 Hardware Id (即USB\\VID_XXXX&PID_XXXX)查找匹配的INF文件。然后按INF指示拷备文件等,最后装载driver,开始DriverEntry。

说这么多,尽我所知瞎说,主要希望有人回答我的问题,呵呵 :)


[编辑 -  6/6/03 by  jason.gao]
我打字很快。
jiangyonghua
驱动牛犊
驱动牛犊
  • 注册日期2003-05-06
  • 最后登录2003-06-25
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2003-06-07 17:10
;; Jy5.inf

;; *********  PLEASE READ ***********
;; The wizard cannot create exact INF files for all buses and device types.
;; You may have to make changes to this file in order to get your device to
;; install. In particular, hardware IDs and logical configurations require
;; intervention.
;;
;; The Win2K DDK documentation contains an excellent INF reference.

;--------- Version Section ---------------------------------------------------

[Version]
Signature=\"$Windows 95$\"
Provider=%ProviderName%

; If device fits one of the standard classes, use the name and GUID here,
; otherwise create your own device class and GUID as this example shows.

Class=NewDeviceClass
ClassGUID={ff646f80-8def-11d2-9449-00105a075f6b}

;--------- SourceDiskNames and SourceDiskFiles Section -----------------------

; These sections identify source disks and files for installation.  They are
; shown here as an example, but commented out.

;[SourceDisksNames]
;1 = \"Install Disk\",Disk1,,

;[SourceDisksFiles]
;Jy5.sys = 1,,

;--------- ClassInstall/ClassInstall32 Section -------------------------------

; Not necessary if using a standard class

; 9X Style
[ClassInstall]
Addreg=Class_AddReg

; NT Style
[ClassInstall32]
Addreg=Class_AddReg

[Class_AddReg]
HKR,,,,%DeviceClassName%
HKR,,Icon,,\"-18\"

;--------- DestinationDirs Section -------------------------------------------

[DestinationDirs]
Jy5_Files_Driver = 10,System32\\Drivers

;--------- Manufacturer and Models Sections ----------------------------------

[Manufacturer]
%MfgName%=Mfg0

[Mfg0]
%DeviceDesc%=Jy5_DDI, USB\\VID_0471&PID_0666

;---------- DDInstall Sections -----------------------------------------------
; --------- Windows 9X -----------------

; Experimentation has shown that DDInstall root names greater than 19 characters
; cause problems in Windows 98

[Jy5_DDI]
CopyFiles=Jy5_Files_Driver
AddReg=Jy5_9X_AddReg

[Jy5_9X_AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,Jy5.sys
HKR, \"Parameters\", \"BreakOnEntry\", 0x00010001, 0

; --------- Windows NT -----------------

[Jy5_DDI.NT]
CopyFiles=Jy5_Files_Driver
AddReg=Jy5_NT_AddReg

[Jy5_DDI.NT.Services]
Addservice = Jy5, 0x00000002, Jy5_AddService

[Jy5_AddService]
DisplayName    = %SvcDesc%
ServiceType    = 1                  ; SERVICE_KERNEL_DRIVER
StartType      = 3                  ; SERVICE_DEMAND_START
ErrorControl   = 1                  ; SERVICE_ERROR_NORMAL
ServiceBinary  = %10%\\System32\\Drivers\\Jy5.sys

[Jy5_NT_AddReg]
HKLM, \"System\\CurrentControlSet\\Services\\Jy5\\Parameters\",\\
\"BreakOnEntry\", 0x00010001, 0


; --------- Files (common) -------------

[Jy5_Files_Driver]
Jy5.sys

;--------- Strings Section ---------------------------------------------------

[Strings]
ProviderName=\"Your Company Name here\"
MfgName=\"Name of HW Manufacturer here\"
DeviceDesc=\"Description of Device here\"
DeviceClassName=\"Description of Device class here\"
SvcDesc=\"Description of NT service here\"

以上是安装文件 有ClassGUID。
// interface.h - device interface classes for Jy5

// This GUID identifies the device interface class used by the Jy5Device device

// TODO: If your driver supports a standard interface, use the GUID that identifies
// the interface class, rather than using the one defined below

#define Jy5Device_CLASS_GUID \\
 { 0x48aaa061, 0x2ef, 0x11d7, { 0x92, 0x66, 0x52, 0x54, 0xab, 0x19, 0x3f, 0x33 } }
以上是测试程序中interface.h 头文件定义的
这两个文件都是有Driverworks自动生成的,在DS的某一步要输入
VID,PID。是不是interface.h 头文件中的Jy5Device_CLASS_GUID
就是根据VID,PID生成的?用来实现应用程序与设备驱动的交互。
怎么解释*INf中的GUID的作用?

另外,应用程序要与设备驱动交互,大概要有以下一个过程
HANDLE USB_Createfile( GUID* pGuid, DWORD InterfaceIndex)
{
   // Get handle to relevant device information set
   HDEVINFO info = SetupDiGetClassDevs(pGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
   if(info==INVALID_HANDLE_VALUE)
   {
      return NULL;
   }

   // Get interface data for the requested MemberIndex
   SP_INTERFACE_DEVICE_DATA ifdata;
   ifdata.cbSize = sizeof(ifdata);
   if(!SetupDiEnumDeviceInterfaces(info, NULL, pGuid, InterfaceIndex, &ifdata))
   {
      SetupDiDestroyDeviceInfoList(info);
      return NULL;
   }

   // Get size of symbolic link name
   DWORD ReqLen;
   SetupDiGetDeviceInterfaceDetail(info, &ifdata, NULL, 0, &ReqLen, NULL);
   PSP_INTERFACE_DEVICE_DETAIL_DATA ifDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)(new char[ReqLen]);
   if( ifDetail==NULL)
   {
      SetupDiDestroyDeviceInfoList(info);
      return NULL;
   }

   // Get symbolic link name
   ifDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
   if( !SetupDiGetDeviceInterfaceDetail(info, &ifdata, ifDetail, ReqLen, NULL, NULL))
   {
      SetupDiDestroyDeviceInfoList(info);
      delete ifDetail;
      return NULL;
   }

   // Open file
   HANDLE pDevicefile = CreateFile( ifDetail->DevicePath,
      GENERIC_READ | GENERIC_WRITE,
      FILE_SHARE_READ | FILE_SHARE_WRITE,
      NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
   if( pDevicefile==INVALID_HANDLE_VALUE) pDevicefile = NULL;

   delete ifDetail;
   SetupDiDestroyDeviceInfoList(info);
   return pDevicefile;
}

可是ds生成的测试程序中关于这方面的内容若下
// 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 <windows.h>
#include <winioctl.h>
#include <devintf.h> // DriverWorks

// 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;
}

其中DevInterface,DevClass这几个函数又是社么意思?是不是另外
有库封装好了!
谢谢各位指教
 :D
jason.gao
驱动小牛
驱动小牛
  • 注册日期2002-05-08
  • 最后登录2003-11-12
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2003-06-09 08:52
感觉和我前面说的差不多,不知道你具体碰到了什么问题?

关于 device interface 你可以看 MSDN 中 Device Management 的文档啊(即 SetupDiXxx )
 :)
我打字很快。
jiangyonghua
驱动牛犊
驱动牛犊
  • 注册日期2003-05-06
  • 最后登录2003-06-25
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2003-06-09 10:17
 非常感谢
jason.gao :)
jason.gao
驱动小牛
驱动小牛
  • 注册日期2002-05-08
  • 最后登录2003-11-12
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2003-06-10 09:45
感谢为什么不给分,我的分都给别人了,所以,你的分应该给我
 :(:D :D
我打字很快。
游客

返回顶部