我正在尝试确定我的 WPD 设备在 Delphi 中的类型。
在我的应用程序中,我需要知道设备是电话还是相机,或者它是什么。
根据这篇 MSDN 文章,WPD 设备类型是一个 WPD 设备属性,可以通过读取设备的属性来读取。
然后根据这篇 MSDN 文章,属性和属性被定义为 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 单元)。
代码:
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 文章, pData
应该设置为 NULL 并将 pcbData 设置为零,以便获得 pcbData 的大小。
我正在做的。
有人可以帮助解释我需要做什么才能做到正确吗?
编辑: 我发现这段代码似乎在 python中,它获取设备类型。
我正在尝试将其移植到delphi。