请问你的SetupDiGetDeviceInterfaceDetail函数是怎么用的啊,里面的参数怎么写啊

 我来答
stushl
推荐于2016-02-06 · TA获得超过329个赞
知道小有建树答主
回答量:730
采纳率:50%
帮助的人:337万
展开全部
你木有MSDN吗
BOOL SetupDiGetDeviceInterfaceDetail(
HDEVINFO DeviceInfoSet,
PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData,
DWORD DeviceInterfaceDetailDataSize,
PDWORD RequiredSize,
PSP_DEVINFO_DATA DeviceInfoData
);

我原来写的函数,选修课做的实验
m_infor=_T("");
// TODO: Add your control notification handler code here
GUID guidHID;
HidD_GetHidGuid(&guidHID);
CString strShow;
strShow.Format("%08x-%04x-%04x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\r\n",
guidHID.Data1,guidHID.Data2,guidHID.Data3,guidHID.Data4[0],
guidHID.Data4[1],guidHID.Data4[2],guidHID.Data4[3],guidHID.Data4[4],
guidHID.Data4[5],guidHID.Data4[6],guidHID.Data4[7]);
m_infor+= _T("1.HID类的GUID标识为:\r\n ")+strShow+_T("\r\n");
m_infor+=_T("2.获得全部HID信息……\r\n ");

HDEVINFO hDevInfo;
hDevInfo=SetupDiGetClassDevs(&guidHID,NULL,NULL,DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (hDevInfo == INVALID_HANDLE_VALUE) // 查询全部HID信息失败
{
m_infor+=_T("查询失败 - SetupDiGetClassDevs()");
return ;
}
m_infor=m_infor+_T("获得成功!\r\n")+_T("\r\n")+_T("3.获得特定HID识别信息……\r\n ");

SP_INTERFACE_DEVICE_DATA ifdata;
ifdata.cbSize = sizeof(ifdata);
DWORD devindex;
for (devindex = 0;SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &guidHID,devindex, &ifdata); ++devindex)
{
CString num;
num.Format(_T("第(%d)个设备:\r\n "),devindex+1);
m_infor+=num;
DWORD needed;
SetupDiGetDeviceInterfaceDetail(hDevInfo, &ifdata, NULL, 0,&needed, NULL);

PSP_INTERFACE_DEVICE_DETAIL_DATA detail = (PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc(needed);
detail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
SP_DEVINFO_DATA did = {sizeof(SP_DEVINFO_DATA)};
SetupDiGetDeviceInterfaceDetail(hDevInfo, &ifdata, detail,needed, NULL, &did);
CString devPath(detail->DevicePath);
m_infor+=_T("设备路径:")+devPath+_T("\r\n ");
///////////////////////////////////////////////////////
TCHAR fname[256];
if (!SetupDiGetDeviceRegistryProperty(hDevInfo, &did,SPDRP_FRIENDLYNAME, NULL, (PBYTE) fname, sizeof(fname), NULL)
&& !SetupDiGetDeviceRegistryProperty(hDevInfo, &did, SPDRP_DEVICEDESC,NULL, (PBYTE) fname, sizeof(fname), NULL))
_tcsncpy(fname, detail->DevicePath, 256);

fname[255] = 0;

m_infor+=_T(" 设备类型:");
m_infor+=fname;
m_infor+=_T("\r\n ");
//CDeviceListEntry e(detail->DevicePath, fname);
free((PVOID) detail);
////////////////////////////////////////////////////////

HANDLE hand1 = CreateFile(devPath, GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);
if (hand1 == INVALID_HANDLE_VALUE)
{
m_infor+=_T(" CreateFile() - 打开失败!\r\n ");
continue;
}
else
{
m_infor+=_T(" CreateFile() - 打开成功!\r\n ");

}

HIDD_ATTRIBUTES attr = {sizeof(HIDD_ATTRIBUTES)};
BOOLEAN okay = HidD_GetAttributes(hand1, &attr);

if (okay)
{
CString tem;
tem.Format("ProductID:%x ,VendorID:%X ,VersionNumber: %x",attr.ProductID,attr.VendorID,attr.VersionNumber);
m_infor+=_T(" ")+tem+_T("\r\n ");
if (attr.ProductID==0x100 && attr.VendorID==0x930A)
{
hand=hand1;
m_receive.EnableWindow();
m_send.EnableWindow();
m_close.EnableWindow();
}

}
///////////////////////////////////////////////////////获得设备能力
m_infor+=_T(" 获得设备能力……\r\n ");
PHIDP_PREPARSED_DATA PreparsedData;

if(HidD_GetPreparsedData(hand1,&PreparsedData))
{
m_infor+=_T(" HidD_GetPreparsedData() - 调用成功! \r\n ");
}

Cap=new HIDP_CAPS;
HidP_GetCaps(PreparsedData,Cap);
m_infor+=_T(" HidP_GetCaps() - 调用成功! \r\n");
CString tmp;
tmp.Format("\
Usage:%d \r\n\
UsagePage:%d \r\n\
InputReportByteLength:%d \r\n\
OutputReportByteLength:%d \r\n\
FeatureReportByteLength:%d \r\n\
NumberLinkCollectionNodes:%d \r\n\
NumberInputButtonCaps:%d \r\n\
NumberInputValueCaps:%d \r\n\
NumberInputDataIndices:%d \r\n\
NumberOutputButtonCaps:%d \r\n\
NumberOutputValueCaps:%d \r\n\
NumberOutputDataIndices:%d \r\n\
NumberFeatureButtonCaps:%d \r\n\
NumberFeatureValueCaps:%d \r\n\
NumberFeatureDataIndices:%d \r\n",
Cap->Usage,
Cap->UsagePage,
Cap->InputReportByteLength,
Cap->OutputReportByteLength,
Cap->FeatureReportByteLength,
Cap->NumberLinkCollectionNodes,
Cap->NumberInputButtonCaps,
Cap->NumberInputValueCaps,
Cap->NumberInputDataIndices,
Cap->NumberOutputButtonCaps,
Cap->NumberOutputValueCaps,
Cap->NumberOutputDataIndices,
Cap->NumberFeatureButtonCaps,
Cap->NumberFeatureValueCaps,
Cap->NumberFeatureDataIndices);
m_infor+=tmp;

/////////////////////////////////////////////////////////

}

SetupDiDestroyDeviceInfoList(hDevInfo);
UpdateData(FALSE);
更多追问追答
追问
为什么我写的CString str=pDetail->DevicePath; 结果str=“ " 然后pDetail有值
追答
赋值应该没问题,自己调试一下,看执行这句之前和之后str值有变化吗
来自:求助得到的回答
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式