Delphi で使用している WPD デバイスのタイプを特定しようとしています。
私のアプリケーションでは、デバイスが電話かカメラか、またはそれが何であるかを知る必要があります。
この MSDN の記事によると、WPD デバイス タイプは WPD デバイス プロパティであり、デバイスのプロパティを読み取ることで読み取ることができます。
次に、この MSDN 記事によると、プロパティと属性は、カテゴリ GUID とそのカテゴリの一意の ID の 2 つの部分を持つ PROPERTYKEY 構造として定義されます。
GUID と Uinique ID を見つけましたWPD_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
、pcbData のサイズを取得するには、NULL に設定し、pcbData をゼロに設定する必要があります。
私がやっている。
誰かがそれを正しくするために私が何をする必要があるかを説明するのを手伝ってもらえますか?
編集: デバイスタイプを取得するpython にあると思われるこのコードを見つけました。
私はそれをデルフィに移植しようとしています。