我正在尝试确定我的 WPD 设备在 Delphi 中的类型。
在我的应用程序中,我需要知道该设备是手机还是相机或者什么。
根据这篇 MSDN 文章 https://msdn.microsoft.com/en-us/library/windows/hardware/ff597865%28v=vs.85%29.aspxWPD 设备类型是 WPD 设备属性,可以通过读取设备的属性来读取。
然后根据这篇 MSDN 文章 https://msdn.microsoft.com/en-us/library/windows/hardware/ff597900(v=vs.85).aspx属性和特性被定义为 PROPERTYKEY 结构,由两部分组成:类别 GUID 和该类别的唯一 ID。
我找到了 GUID 和唯一 IDWPD_DEVICE_TYPE
哪个是WPD_DEVICE_TYPE_FMTID : TGuid = '{26D4979A-E643-4626-9E2B-736DC0C92FDC}';
WPD_DEVICE_TYPE_PID = 15;
我的问题是我正在考虑如何检索信息。
我正期待着IPortableDevice
会有一个.Property
程序就像IPortableDeviceContent
,但事实并非如此。
然而,IPortableDeviceManager
确实有一个称为GetDeviceProperty
.
我有示例代码,可以获取 WPD 设备的友好名称(来自 PortableDeviceApiLib_TLB.pas 单元)。
Code:
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;
我用于获取设备属性的测试代码如下所示(基本上相同......几乎......):
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 文章, https://msdn.microsoft.com/en-us/library/windows/desktop/dd388692(v=vs.85).aspx pData
应设置为 NULL 并将 pcbData 设置为零才能获取 pcbData 的大小。
我正在做的事。
有人可以帮助解释我需要做什么才能做到正确吗?
EDIT:
我发现这段代码似乎是在 python 中 http://fossies.org/linux/misc/calibre-2.21.0.tar.gz/calibre-2.21.0/src/calibre/devices/mtp/windows/device_enumeration.cpp,获取设备类型。
我正在尝试将其移植到delphi。