赞
踩
- //此函数用来判断网口是否连接正常,需要首先在cpp当中添加头文件
-
- #include <sensapi.h>
- ...
-
- BYTE checkNetworks()
- {
- DWORD dwCode;
- if(!IsNetworkAlive(&dwCode))
- return 0;
- return 1;
- }
-
-
- //此函数用来检查特定的USB句柄设备是否完好,也是首先需要添加头文件
-
- #include <winioctl.h>
- #include <setupapi.h>
- #include <initguid.h>
- ...
-
- DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE,
- 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED);
- #define GUID_CLASS_USB_DEVICE GUID_DEVINTERFACE_USB_DEVICE
-
- BOOL GetMyUsbDeviceLabel(const char *sHandle)//输入设备句柄ID字符串,判断是否正常
- {
- LPGUID lpGuid = (LPGUID)&GUID_CLASS_USB_DEVICE;
- int INTERFACE_DETAIL_SIZE = 1024;
- int nCount = 0;
- HDEVINFO info = SetupDiGetClassDevsA(lpGuid, NULL, NULL, DIGCF_PRESENT|DIGCF_INTERFACEDEVICE);
-
- //enumerate device information
- DWORD required_size = 0;
- int i;
- SP_DEVINFO_DATA DeviceInfoData = { sizeof(DeviceInfoData) };
-
- unsigned long DataT;
- BOOL flag = FALSE;
- //DWORD buffersize = 1024;
- unsigned long req_bufsize = 0;
-
- for (i=0;SetupDiEnumDeviceInfo(info,i,&DeviceInfoData);i++)
- {
- char locid[1024];
- if (!SetupDiGetDeviceRegistryPropertyA(info, &DeviceInfoData, SPDRP_HARDWAREID, &DataT, (LPBYTE)locid, 1024, &req_bufsize))
- continue;
- if(strstr(locid,sHandle) != NULL)
- {
- flag = TRUE;
- break;
- }
- }
-
- SetupDiDestroyDeviceInfoList(info);
- return flag;
- }
以上用两个windows下面的QT creator引用第三方类库,举例说明问题。
如果只是添加的引用头文件以后,是不行的,这样写QT Creator编译是无法通过的,提示找不到对应的函数体实现。如:
undefined reference to '_imp_SetupDiGetClassDevs'....类似这种带有_imp前缀的错误提示之类的。
需要打开项目的CMakeLists.txt
手动添加关于第三方类库的两行代码:
- target_link_libraries(myProjectname PRIVATE Sensapi)
- target_link_libraries(myProjectname PRIVATE Setupapi)
再次编译,不再出现错误
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。