请教window2000,vc6下的USB通信编程问题?

tangfarong 2003-10-19 04:09:11
1.原理作简单的描述。
2.实现的前提,及实现的过程(请详细)。
...全文
71 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
theone 2003-11-25
  • 打赏
  • 举报
回复
可能没有指定DDK的目录
你也可以直接把HID.LIB添加到project中
sunheart 2003-11-24
  • 打赏
  • 举报
回复
错:
unresolved external symbol "unsigned char __stdcall HidD_GetAttributes(void *,struct _HIDD_ATTRIBUTES *)" (?HidD_GetAttributes@@YGEPAXPAU_HIDD_ATTRIBUTES@@@Z)
USBPortDlg.obj : error LNK2001: unresolved external symbol "void __stdcall HidD_GetHidGuid(struct _GUID *)" (?HidD_GetHidGuid@@YGXPAU_GUID@@@Z)
sunheart 2003-11-24
  • 打赏
  • 举报
回复
在用HidD_GetHidGuid()函数时为什么老报编译错误,说外部符号错误。我已经指定了hid.lib setupapi.lib了
Gladstone 2003-11-19
  • 打赏
  • 举报
回复
BOO DetectDogIsExist()
{
HIDD_ATTRIBUTES Attributes;
SP_DEVICE_INTERFACE_DATA devInfoData;
LONG Result;
int MemberIndex = 0;
PSP_DEVICE_INTERFACE_DETAIL_DATA detailData;
bool LastDevice = FALSE;
bool MyDeviceDetected;
PWORD ManufcturerStringBuffer;
ManufcturerStringBuffer= new WORD[26];

//得到HID类的GUID
HidD_GetHidGuid(&HidGuid);

//返回包含一个特定类的所有设备的设备信息组
hDevInfo=SetupDiGetClassDevs \
(&HidGuid, \
NULL, \
NULL, \
DIGCF_PRESENT|DIGCF_INTERFACEDEVICE);

devInfoData.cbSize = sizeof(devInfoData);
do
{
MyDeviceDetected=FALSE;

//返回关于设备信息组中一个设备的信息
Result=SetupDiEnumDeviceInterfaces \
(hDevInfo, \
0, \
&HidGuid, \
MemberIndex, \
&devInfoData);

if (Result != 0)
{
//返回一个设备路径名(得到Length)
Result = SetupDiGetDeviceInterfaceDetail \
(hDevInfo, \
&devInfoData, \
NULL, \
0, \
&Length, \
NULL);

detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(Length);

detailData -> cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);

//返回一个设备路径名(得到detailData)
Result = SetupDiGetDeviceInterfaceDetail \
(hDevInfo, \
&devInfoData, \
detailData, \
Length, \
&Required, \
NULL);

//打开一个设备
DeviceHandle=CreateFile \
(detailData->DevicePath, \
GENERIC_READ|GENERIC_WRITE, \
FILE_SHARE_READ|FILE_SHARE_WRITE, \
NULL, \
OPEN_EXISTING, \
0, \
NULL);

//返回销售商ID,产品ID和版本
Result = HidD_GetAttributes \
(DeviceHandle, \
&Attributes);

// DisplayLastError("HidD_GetAttributes: ");

//Is it the desired device?
MyDeviceDetected = FALSE;


if (Attributes.VendorID == VendorID)
{
if (Attributes.ProductID == ProductID)
{
//Both the Product and Vendor IDs match.
//MyDeviceDetected = TRUE;
//Get the device's capablities.
GetDeviceCapabilities();
ReadHandle=CreateFile \
(detailData->DevicePath, \
GENERIC_READ|GENERIC_WRITE, \
FILE_SHARE_READ|FILE_SHARE_WRITE, \
NULL, \
OPEN_EXISTING, \
0, \
NULL);

BOOL test=HidD_GetManufacturerString(ReadHandle,ManufcturerStringBuffer, 26);

if(CompareStr(ManufcturerStringBuffer)==true)
{
InitBuffer();
MyDeviceDetected=true;
}
else
{
CloseHandle(DeviceHandle);
MyDeviceDetected = false;
}

} //if (Attributes.ProductID == ProductID)
else
//The Product ID doesn't match.
CloseHandle(DeviceHandle);
} //if (Attributes.VendorID == VendorID)
else
//The Vendor ID doesn't match.
CloseHandle(DeviceHandle);

//Free the memory used by the detailData structure (no longer needed).
free(detailData);
} //if (Result != 0)
else
//SetupDiEnumDeviceInterfaces returned 0, so there are no more devices to check.
LastDevice=TRUE;

//If we haven't found the device yet, and haven't tried every available device,
//try the next one.
MemberIndex = MemberIndex + 1;

} //do
while ((LastDevice == FALSE) && (MyDeviceDetected == FALSE));

SetupDiDestroyDeviceInfoList(hDevInfo);
// DisplayData("SetupDiDestroyDeviceInfoList");
if(ManufcturerStringBuffer)
{
delete[]ManufcturerStringBuffer;
}
return MyDeviceDetected;
}
yifeng_ch 2003-11-17
  • 打赏
  • 举报
回复
关注。
Riverqh 2003-10-31
  • 打赏
  • 举报
回复
老古那个硬件开发网好像有这方面的资料。
AthlonxpX86 2003-10-26
  • 打赏
  • 举报
回复
有驱动程序的情况下,原理如下
用SetupAPI枚举USB设备和端口,得到需要设备名称,然后用CreateFile打开驱动程序,用readfile writefile就可以实现USB通讯了,另外驱动程序中可能会带一些设备控制码,这个要去问写驱动程序的人了
MoreBug 2003-10-25
  • 打赏
  • 举报
回复
去www.driverdevelop.com找找,祝你好运!
thisisyjs 2003-10-20
  • 打赏
  • 举报
回复
我也想知道。
建议到驱动开发网看看。
qwedcxza 2003-10-20
  • 打赏
  • 举报
回复
这种东西也来问,要写一本书了
买书看吧

2,640

社区成员

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

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