SetupDiGetDeviceInterfaceDetail error 求助

zora2Irene 2015-04-10 10:09:54
我在使用
SetupDiGetDeviceInterfaceDetail(
dev_info, /* DeviceInfoSet */
&dev_interface_data, /* DeviceInterfaceData */
NULL, /* DeviceInterfaceDetailData */
0, /* DeviceInterfaceDetailDataSize */
&len, /* RequiredSize */
NULL /* DeviceInfoData */);
在win7 32上正常,但是在win7 64上老是提示getlasterror 183 不知道是什么原因,在线坐等求助。。。。。不胜感激
...全文
545 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
fly4free 2015-04-15
  • 打赏
  • 举报
回复
你是编译成64位的程序了?
wyx100 2015-04-10
  • 打赏
  • 举报
回复
zora2Irene 2015-04-10
  • 打赏
  • 举报
回复
不知道为什么,我的应用在win7 32位上都是正常的,在win7 64就出现了这个错误,我在网上找了很久也看了msdn都没有提到这个函数出现这个错误
worldy 2015-04-10
  • 打赏
  • 举报
回复
183 Cannot create a file when that file already exists. ERROR_ALREADY_EXISTS
zora2Irene 2015-04-10
  • 打赏
  • 举报
回复
谢谢大家的回答,问题已经解决,前面我调用函数时,赋值unsigned long len=0;msdn中参数所属位置为DWORD型,虽然DWORD和定义就是unsigned long这个,但是好像还是有区别,在win7 32 上正确,win7 64出错,修改后正常
利用USB接口进行通信的数据源码MemberIndex = 0 Do 'The cbSize element of the MyDeviceInterfaceData structure must be set to 'the structure's size in bytes. The size is 28 bytes. MyDeviceInterfaceData.cbSize = LenB(MyDeviceInterfaceData) Result = SetupDiEnumDeviceInterfaces _ (DeviceInfoSet, _ 0, _ HidGuid, _ MemberIndex, _ MyDeviceInterfaceData) Call DisplayResultOfAPICall("SetupDiEnumDeviceInterfaces") If Result = 0 Then LastDevice = True 'If a device exists, display the information returned. If Result <> 0 Then lstResults.AddItem " DeviceInfoSet for device #" & CStr(MemberIndex) & ": " lstResults.AddItem " cbSize = " & CStr(MyDeviceInterfaceData.cbSize) lstResults.AddItem _ " InterfaceClassGuid.Data1 = " & Hex$(MyDeviceInterfaceData.InterfaceClassGuid.Data1) lstResults.AddItem _ " InterfaceClassGuid.Data2 = " & Hex$(MyDeviceInterfaceData.InterfaceClassGuid.Data2) lstResults.AddItem _ " InterfaceClassGuid.Data3 = " & Hex$(MyDeviceInterfaceData.InterfaceClassGuid.Data3) lstResults.AddItem _ " Flags = " & Hex$(MyDeviceInterfaceData.Flags) '****************************************************************************** 'SetupDiGetDeviceInterfaceDetail 'Returns: an SP_DEVICE_INTERFACE_DETAIL_DATA structure 'containing information about a device. 'To retrieve the information, call this function twice. 'The first time returns the size of the structure in Needed. 'The second time returns a pointer to the data in DeviceInfoSet. 'Requires: 'A DeviceInfoSet returned by SetupDiGetClassDevs and 'an SP_DEVICE_INTERFACE_DATA structure returned by SetupDiEnumDeviceInterfaces. '******************************************************************************* MyDeviceInfoData.cbSize = Len(MyDeviceInfoData) Result = SetupDiGetDeviceInterfaceDetail _ (DeviceInfoSet, _ MyDeviceInterfaceData, _ 0, _ 0, _ Needed, _ 0) DetailData = Needed Call DisplayResultOfAPICall("SetupDiGetDeviceInterfaceDetail") lstResults.AddItem " (OK to say too small)" lstResults.AddItem " Required buffer size for the data: " & Needed 'Store the structure's size. MyDeviceInterfaceDetailData.cbSize = _ Len(MyDeviceInterfaceDetailData) 'Use a byte array to allocate memory for 'the MyDeviceInterfaceDetailData structure ReDim DetailDataBuffer(Needed) 'Store cbSize in the first four bytes of the array. Call RtlMoveMemory _ (DetailDataBuffer(0), _ MyDeviceInterfaceDetailData, _ 4) 'Call SetupDiGetDeviceInterfaceDetail again. 'This time, pass the address of the first element of DetailDataBuffer 'and the returned required buffer size in DetailData. Result = SetupDiGetDeviceInterfaceDetail _ (DeviceInfoSet, _ MyDeviceInterfaceData, _ VarPtr(DetailDataBuffer(0)), _ DetailData, _ Needed, _ 0) Call DisplayResultOfAPICall(" Result of second call: ") lstResults.AddItem " MyDeviceInterfaceDetailData.cbSize: " & _ CStr(MyDeviceInterfaceDetailData.cbSize) 'Convert the byte array to a string. DevicePathName = CStr(DetailDataBuffer()) 'Convert to Unicode. DevicePathName = StrConv(DevicePathName, vbUnicode) 'Strip cbSize (4 bytes) from the beginning. DevicePathName = Right$(DevicePathName, Len(DevicePathName) - 4) lstResults.AddItem " Device pathname: " lstResults.AddItem " " & DevicePathName '****************************************************************************** 'CreateFile 'Returns: a handle that enables reading and writing to the device. 'Requires: 'The DevicePathName returned by SetupDiGetDeviceInterfaceDetail. '****************************************************************************** HidDevice = CreateFile _ (DevicePathName, _ GENERIC_READ Or GENERIC_WRITE, _ (FILE_SHARE_READ Or FILE_SHARE_WRITE), _ 0, _ OPEN_EXISTING, _ 0, _ 0) Call DisplayResultOfAPICall("CreateFile") lstResults.AddItem " Returned handle: " & Hex$(HidDevice) & "h" 'Now we can find out if it's the device we're looking for. '****************************************************************************** 'HidD_GetAttributes 'Requests information from the device. 'Requires: The handle returned by CreateFile. 'Returns: an HIDD_ATTRIBUTES structure containing 'the Vendor ID, Product ID, and Product Version Number. 'Use this information to determine if the detected device 'is the one we're looking for. '****************************************************************************** 'Set the Size property to the number of bytes in the structure. DeviceAttributes.Size = LenB(DeviceAttributes) Result = HidD_GetAttributes _ (HidDevice, _ DeviceAttributes) Call DisplayResultOfAPICall("HidD_GetAttributes") If Result <> 0 Then lstResults.AddItem " HIDD_ATTRIBUTES structure filled without error." Else lstResults.AddItem " Error in filling HIDD_ATTRIBUTES structure." End If lstResults.AddItem " Structure size: " & DeviceAttributes.Size lstResults.AddItem " Vendor ID: " & Hex$(DeviceAttributes.VendorID) lstResults.AddItem " Product ID: " & Hex$(DeviceAttributes.ProductID)

2,640

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧