在Delphi中确定WPD设备类型 [英] Determine WPD device type in Delphi

查看:90
本文介绍了在Delphi中确定WPD设备类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定我的WPD设备在Delphi中是什么类型.

I'm trying to determine what type my WPD device is in Delphi.

在我的应用程序中,我需要知道设备是手机还是相机,或者是什么.

In my application I need to know if the device is a Phone or Camera or what ever it is.

根据此MSDN文章 WPD设备类型是WPD设备属性,可以通过读取设备的属性来读取.

According to this MSDN article the WPD Device Type is a WPD Device Property which can be read by reading the properties of the device.

然后根据此MSDNarticle 的属性和属性定义为PROPERTYKEY结构,该结构分为两部分:类别GUID和该类别的唯一ID.

Then according to this MSDN article properties and attributes are defined as PROPERTYKEY structures with two parts: a category GUID, and a unique ID for that category.

我找到了 WPD_DEVICE_TYPE 的GUID和Uinique ID, WPD_DEVICE_TYPE_FMTID:TGuid ='{26D4979A-E643-4626-9E2B-736DC0C92FDC}'; WPD_DEVICE_TYPE_PID = 15;

I've found GUID and Uinique ID for WPD_DEVICE_TYPE which are WPD_DEVICE_TYPE_FMTID : TGuid = '{26D4979A-E643-4626-9E2B-736DC0C92FDC}'; WPD_DEVICE_TYPE_PID = 15;

我的问题是我遇到了困扰,希望弄清楚如何检索信息.

My problem is that I'm having isses figuring out how to retrieve the information.

我期望 IPortableDevice 将具有 .Property 过程,就像 IPortableDeviceContent 一样,

I was expecting that IPortableDevice would have a .Property procedure just like IPortableDeviceContent, but it doesn't.

但是, IPortableDeviceManager 确实有一个名为 GetDeviceProperty 的过程.

However, IPortableDeviceManager does have a procedure called GetDeviceProperty.

我有示例代码,可以获取WPD设备的友好名称(从PortableDeviceApiLib_TLB.pas单元获得).

I have sample code which can get the friendly name of a WPD device (from the unit PortableDeviceApiLib_TLB.pas).

代码:

function GetDeviceFriendlyName(sDeviceId: WideString): WideString;
  var iDevNameLen: LongWord;
      iRes: Integer;
      s: WideString;
begin
  //get length of friendly name:
  iDevNameLen := 0;
  s := '';

  iRes := My_IPortableDeviceManager.GetDeviceFriendlyName(PWideChar(sDeviceId),  Word(nil^),  iDevNameLen);

  if iRes = S_OK then
    if iDevNameLen>0 then
    begin
      SetLength(s, iDevNameLen);
      ZeroMemory(PWideChar(s), iDevNameLen);
      iRes := My_IPortableDevice.GetDeviceFriendlyName(PWideChar(sDeviceId),  PWord(PWideChar(s))^,  iDevNameLen);
      s := Trim(s);
    end;

  result := s;
end;

我用于获取设备属性的测试代码如下(基本上相同...几乎...):

My test code for getting a property of a device looks as following (basically the same... almost...):

function GetDeviceProperty(ADeviceID, APropertyName: WideString): WideString;
  var iDevPropLen: LongWord;
      iRes: Integer;
      s: WideString;
      t: cardinal;
begin
  //get length of property name:
  iDevPropLen := 0;
  s := '';

  iRes := My_IPortableDeviceManager.GetDeviceProperty(PWideChar(ADeviceID), PWideChar(APropertyName), Byte(nil^), iDevPropLen, t);
  showmessage(inttostr(ires)+#13#10+inttostr(iDevPropLen)+#13#10+inttostr(t));
  //just trying to get some useful information…
end;

根据此MSDN文章, pData 应该设置为NULL,而pcbData设置为零,以获取pcbData的大小.

According to this MSDN article, pDatashould be set to NULL and pcbData set to zero in order to get the size of pcbData.

我在做什么.

有人可以帮我解释一下我需要做些什么才能使它正确吗?

Could someone help explaining what I need to do in order to get it right?

I found this code which seems to be in python, that gets the device type.

我正在尝试将其移植到delphi.

I'm trying to port it to delphi.

推荐答案

好,所以最终我弄清楚了如何读取设备的设备类型.

Ok, so eventually I figured out how to read the device type of a device.

需要做的是读取设备属性.

What needed to be done was to read the device properties.

可以读取一些非常有趣的信息,例如设备的电池电量.

Some very interesting information could be read, such as the battery level of the device, if available.

我使用了在此处找到的来源作为WPD编程的参考.

I used the source found here as a reference to WPD programming.

代码已通过外部硬盘驱动器,SD存储卡读取器,USB记忆棒,Apple iPhone和Samsung Galaxy手机进行了测试.

Code tested with external harddrives, SD memory card reader, USB sticks, Apple iPhone, and Samsung Galaxy phone.

可在此处使用代码!!!

只需将代码复制并粘贴到新的VCL项目中,添加一个名为DeviceList的列表框,一个名为LogMemo的备注,一个名为Panel1的面板以及一个位于Panel1内部的名为Button1的按钮.然后双击列表框",然后双击按钮,最后双击主窗体,一切应该都会完美地运行.

Just copy and paste the code in to a new VCL project, add a listbox called DeviceList, a memo called LogMemo, a panel called Panel1, and a button inside Panel1 called Button1. Then doubleclick on the Listbox, and doubleclick on the button, and finally doubleclick on the main form, and everything should run flawlsessly.

在Delphi XE7中编程.

Programmed in Delphi XE7.

这篇关于在Delphi中确定WPD设备类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆