检测ADB接口,一般的实现是对系统中所有的USB设备进行遍历,再检测每个设备的配置信息,提取接口信息,看接口是否是
class_FF
subclass_42
Prot_01
如果不使用adbWinApi ,则需要使用系统驱动控制函数,对USB设备进行控制非常麻烦。
adbWinApi对一些操作进行了封装,如果只是做adb接口的检测,这个工作就非常简单了。
1. 拿到adbWinApi的 lib 和.h 文件
见:http://www.pudn.com/downloads611/sourcecode/comm/android/detail2491867.html
这位大哥已经搞的非常好了,连ddk都不需要。 生成adbWinApi.dll 和 lib
如果出错就在 解决方案的属性中去年 adbWinApi对于adb的依赖,我们只要这个就好了。
2. 写你的代码吧
核心函数:
bool TestEnumInterfaces() {
// Enumerate interfaces
ADBAPIHANDLE enum_handle =
AdbEnumInterfaces(kAdbInterfaceId, true, true, true);
if (NULL == enum_handle) {
printf("\nEnum interfaces failure:");
printf("\nUnable to enumerate ADB interfaces: %u", GetLastError());
return false;
}
// Unite interface info structure and buffer big enough to contain the
// largest structure.
union {
AdbInterfaceInfo interface_info;
char buf[4096];
};
unsigned long buf_size = sizeof(buf);
// Enumerate (and count) interfaces, printing information for each found
// interface.
interface_count = 0;
while (AdbNextInterface(enum_handle, &interface_info, &buf_size)) {
interface_count++;
printf("\nFound interface %ws:", interface_info.device_name);
if (interface_info.flags & SPINT_ACTIVE)
printf(" ACTIVE");
if (interface_info.flags & SPINT_DEFAULT)
printf(" DEFAULT");
if (interface_info.flags & SPINT_REMOVED)
printf(" REMOVED");
buf_size = sizeof(buf);;
};
AdbCloseHandle(enum_handle);
return true;
}
我已经把这个目录下载下来,进行了一点点修改,上传至
http://download.csdn.net/detail/v6543210/7650269
编译需要安装DDk,打开DDK的编译窗口,输入 build -cbeEIFZ 即可
或者 nmake 也行
在我机子上执行能够 检测到一个adb接口,但是打开失败
不知为何,没有调试。
至少可以检测了。