用adbWinApi 检测系统中是否存在 ADB接口



检测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. 写你的代码吧

参考 https://github.com/Wysie/development_apps_spareparts/blob/master/host/windows/usb/adb_winapi_test/adb_winapi_test.cpp

核心函数:

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接口,但是打开失败


不知为何,没有调试。

至少可以检测了。






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路边闲人2

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值