You are on page 1of 28

unit Unit1;

interface
uses
Windows, Classes, Variants, Winapi.Messages, Vcl.Graphics, System.SysUtils,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, ActiveX, OleServer, Vcl.StdCtrls,
Vcl.ExtCtrls, System.Win.ComObj;

const
CLASS_PortableDeviceValues: TGUID = '{0c15d503-d017-47ce-9016-7b3f978721cc}'
;
CLASS_PortableDevicePropVariantCollection: TGUID = '{08a99e2f-6d6d-4b80-af5a
-baf2bcbe4cb9}';
CLSID_PortableDeviceKeyCollection: TGUID = '{de2d022d-2480-43be-97f0-d1fa2cf
98f4f}';
// TypeLibrary Major and minor versions
PortableDeviceApiLibMajorVersion = 1;
PortableDeviceApiLibMinorVersion = 0;
LIBID_PortableDeviceApiLib: TGUID = '{1F001332-1A57-4934-BE31-AFFC99F4EE0A}';
IID_IPortableDevice: TGUID = '{625E2DF8-6392-4CF0-9AD1-3CFA5F17775C}';
CLASS_PortableDevice: TGUID = '{728A21C5-3D9E-48D7-9810-864848F0F404}';
IID_IPortableDeviceValues: TGUID = '{6848F6F2-3155-4F86-B6F5-263EEEAB3143}';
IID_ISequentialStream: TGUID = '{0C733A30-2A1C-11CE-ADE5-00AA0044773D}';
IID_IStream: TGUID = '{0000000C-0000-0000-C000-000000000046}';
IID_IStorage: TGUID = '{0000000B-0000-0000-C000-000000000046}';
IID_IEnumSTATSTG: TGUID = '{0000000D-0000-0000-C000-000000000046}';
IID_IRecordInfo: TGUID = '{0000002F-0000-0000-C000-000000000046}';
IID_ITypeInfo: TGUID = '{00020401-0000-0000-C000-000000000046}';
IID_ITypeComp: TGUID = '{00020403-0000-0000-C000-000000000046}';
IID_ITypeLib: TGUID = '{00020402-0000-0000-C000-000000000046}';
IID_IPortableDevicePropVariantCollection: TGUID = '{89B2E422-4F1B-4316-BCEF-A4
4AFEA83EB3}';
IID_IPortableDeviceKeyCollection: TGUID = '{DADA2357-E0AD-492E-98DB-DD61C53BA3
53}';
IID_IPortableDeviceValuesCollection: TGUID = '{6E3F2D79-4E07-48C4-8208-D8C2E5A
F4A99}';
IID_IPropertyStore: TGUID = '{886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99}';
IID_IPortableDeviceContent: TGUID = '{6A96ED84-7C73-4480-9938-BF5AF477D426}';
IID_IEnumPortableDeviceObjectIDs: TGUID = '{10ECE955-CF41-4728-BFA0-41EEDF1BBF
19}';
IID_IPortableDeviceProperties: TGUID = '{7F6D695C-03DF-4439-A809-59266BEEE3A6}
';
IID_IPortableDeviceResources: TGUID = '{FD8878AC-D841-4D17-891C-E6829CDB6934}'
;
IID_IPortableDeviceCapabilities: TGUID = '{2C8C6DBF-E3DC-4061-BECC-8542E810D12
6}';
IID_IPortableDeviceEventCallback: TGUID = '{A8792A31-F385-493C-A893-40F64EB45F
6E}';
IID_IPortableDeviceManager: TGUID = '{A1567595-4C2F-4574-A6FA-ECEF917B9A40}';
CLASS_PortableDeviceManager: TGUID = '{0AF10CEC-2ECD-4B92-9581-34F6AE0637F3}';
IID_IPortableDeviceService: TGUID = '{D3BD3A44-D7B5-40A9-98B7-2FA4D01DEC08}';
CLASS_PortableDeviceService: TGUID = '{EF5DB4C2-9312-422C-9152-411CD9C4DD84}';
IID_IPortableDeviceServiceCapabilities: TGUID = '{24DBD89D-413E-43E0-BD5B-197F

3C56C886}';
IID_IPortableDeviceContent2: TGUID = '{9B4ADD96-F6BF-4034-8708-ECA72BF10554}';
IID_IPortableDeviceServiceMethods: TGUID = '{E20333C9-FD34-412D-A381-CC6F2D820
DF7}';
IID_IPortableDeviceServiceMethodCallback: TGUID = '{C424233C-AFCE-4828-A756-7E
D7A2350083}';
IID_IPortableDeviceDispatchFactory: TGUID = '{5E1EAFC3-E3D7-4132-96FA-759C0F9D
1E0F}';
CLASS_PortableDeviceDispatchFactory: TGUID = '{43232233-8338-4658-AE01-0B4AE83
0B6B0}';
CLASS_PortableDeviceFTM: TGUID = '{F7C0039A-4762-488A-B4B3-760EF9A1BA9B}';
CLASS_PortableDeviceServiceFTM: TGUID = '{1649B154-C794-497A-9B03-F3F0121302F3
}';
WPD_DEVICE_OBJECT_ID = 'DEVICE';
WPD_CLIENT_NAME_FMTID : TGuid = '{204D9F0C-2292-4080-9F42-40664E70F859}';
WPD_CLIENT_NAME_PID = 2;
WPD_CLIENT_MAJOR_VERSION_FMTID : TGuid = '{204D9F0C-2292-4080-9F42-40664E70F
859}';
WPD_CLIENT_MAJOR_VERSION_PID = 3;
WPD_CLIENT_MINOR_VERSION_FMTID : TGuid = '{204D9F0C-2292-4080-9F42-40664E70F
859}';
WPD_CLIENT_MINOR_VERSION_PID = 4;
WPD_CLIENT_REVISION_FMTID : TGuid = '{204D9F0C-2292-4080-9F42-40664E70F859}'
;
WPD_CLIENT_REVISION_PID = 5;
WPD_CLIENT_DESIRED_ACCESS_FMTID : TGuid = '{204D9F0C-2292-4080-9F42-40664E70
F859}';
WPD_CLIENT_DESIRED_ACCESS_PID = 9;
WPD_DEVICE_SYNC_PARTNER_FMTID: TGUID = '{26D4979A-E643-4626-9E2B-736DC0C92FD
C}';
WPD_DEVICE_SYNC_PARTNER_PID = 2;
WPD_DEVICE_FIRMWARE_VERSION_FMTID: TGUID = '{26D4979A-E643-4626-9E2B-736DC0C
92FDC}';
WPD_DEVICE_FIRMWARE_VERSION_PID = 3;
WPD_DEVICE_POWER_LEVEL_FMTID: TGUID = '{26D4979A-E643-4626-9E2B-736DC0C92FDC
}';
WPD_DEVICE_POWER_LEVEL_PID = 4;
WPD_DEVICE_POWER_SOURCE_FMTID: TGUID = '{26D4979A-E643-4626-9E2B-736DC0C92FD
C}';
WPD_DEVICE_POWER_SOURCE_PID = 5;
WPD_DEVICE_PROTOCOL_FMTID: TGUID = '{26D4979A-E643-4626-9E2B-736DC0C92FDC}';
WPD_DEVICE_PROTOCOL_PID = 6;
WPD_DEVICE_MANUFACTURER_FMTID: TGUID = '{26D4979A-E643-4626-9E2B-736DC0C92FD
C}';
WPD_DEVICE_MANUFACTURER_PID = 7;
WPD_DEVICE_MODEL_FMTID: TGUID = '{26D4979A-E643-4626-9E2B-736DC0C92FDC}';

WPD_DEVICE_MODEL_PID = 8;
WPD_DEVICE_SERIAL_NUMBER_FMTID: TGUID = '{26D4979A-E643-4626-9E2B-736DC0C92F
DC}';
WPD_DEVICE_SERIAL_NUMBER_PID = 9;
WPD_DEVICE_SUPPORTS_NON_CONSUMABLE_FMTID: TGUID = '{26D4979A-E643-4626-9E2B736DC0C92FDC}';
WPD_DEVICE_SUPPORTS_NON_CONSUMABLE_PID = 10;
WPD_DEVICE_DATETIME_FMTID: TGUID = '{26D4979A-E643-4626-9E2B-736DC0C92FDC}';
WPD_DEVICE_DATETIME_PID = 11;
WPD_DEVICE_FRIENDLY_NAME_FMTID: TGUID = '{26D4979A-E643-4626-9E2B-736DC0C92F
DC}';
WPD_DEVICE_FRIENDLY_NAME_PID = 12;
WPD_DEVICE_SUPPORTED_DRM_SCHEMES_FMTID: TGUID = '{26D4979A-E643-4626-9E2B-73
6DC0C92FDC}';
WPD_DEVICE_SUPPORTED_DRM_SCHEMES_PID = 13;
WPD_DEVICE_SUPPORTED_FORMATS_ARE_ORDERED_FMTID: TGUID = '{26D4979A-E643-4626
-9E2B-736DC0C92FDC}';
WPD_DEVICE_SUPPORTED_FORMATS_ARE_ORDERED_PID = 14;
WPD_DEVICE_TYPE_FMTID: TGUID = '{26D4979A-E643-4626-9E2B-736DC0C92FDC}';
WPD_DEVICE_TYPE_PID = 15;
WPD_DEVICE_NETWORK_IDENTIFIER_FMTID: TGUID = '{26D4979A-E643-4626-9E2B-736DC
0C92FDC}';
WPD_DEVICE_NETWORK_IDENTIFIER_PID = 16;
WPD_DEVICE_FUNCTIONAL_UNIQUE_ID_FMTID: TGUID = '{463DD662-7FC4-4291-911C-7F4
C9CCA9799}';
WPD_DEVICE_FUNCTIONAL_UNIQUE_ID_PID = 2;
WPD_DEVICE_MODEL_UNIQUE_ID_FMTID: TGUID = '{463DD662-7FC4-4291-911C-7F4C9CCA
9799}';
WPD_DEVICE_MODEL_UNIQUE_ID_PID = 3;
WPD_DEVICE_TRANSPORT_FMTID: TGUID = '{463DD662-7FC4-4291-911C-7F4C9CCA9799}'
;
WPD_DEVICE_TRANSPORT_PID = 4;
WPD_DEVICE_USE_DEVICE_STAGE_FMTID: TGUID = '{463DD662-7FC4-4291-911C-7F4C9CC
A9799}';
WPD_DEVICE_USE_DEVICE_STAGE_PID = 5;
type
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
IPortableDevice = interface;
IPortableDeviceValues = interface;
// ISequentialStream = interface;
// IStream = interface;
// IStorage = interface;
// IEnumSTATSTG = interface;
// IRecordInfo = interface;

// ITypeInfo = interface;
// ITypeComp = interface;
// ITypeLib = interface;
IPortableDevicePropVariantCollection = interface;
IPortableDeviceKeyCollection = interface;
IPortableDeviceValuesCollection = interface;
IPropertyStore = interface;
IPortableDeviceContent = interface;
IEnumPortableDeviceObjectIDs = interface;
IPortableDeviceProperties = interface;
IPortableDeviceResources = interface;
IPortableDeviceCapabilities = interface;
IPortableDeviceEventCallback = interface;
// IPortableDeviceManager = interface;
// IPortableDeviceService = interface;
// IPortableDeviceServiceCapabilities = interface;
// IPortableDeviceContent2 = interface;
// IPortableDeviceServiceMethods = interface;
// IPortableDeviceServiceMethodCallback = interface;
// IPortableDeviceDispatchFactory = interface;
wirePSAFEARRAY = ^PUserType5;
PUserType5 = ^_wireSAFEARRAY; {*}
PUserType2 = ^tag_inner_PROPVARIANT; {*}
PUserType6 = ^_FLAGGED_WORD_BLOB; {*}
PUserType7 = ^_wireVARIANT; {*}
PUserType14 = ^_wireBRECORD; {*}
PPUserType1 = ^PUserType5; {*}
PByte1 = ^Byte; {*}
tagBSTRBLOB = packed record
cbSize: LongWord;
pData: ^Byte;
end;
tagCABSTRBLOB = packed record
cElems: LongWord;
pElems: ^tagBSTRBLOB;
end;
tagCALPSTR = packed record
cElems: LongWord;
pElems: ^PChar;
end;
tagCALPWSTR = packed record
cElems: LongWord;
pElems: ^PWideChar;
end;
tagCAC = packed record
cElems: LongWord;
pElems: ^Shortint;
end;
tagCAUB = packed record
cElems: LongWord;
pElems: ^Byte;
end;

tagVersionedStream = packed record


guidVersion: TGUID;
pStream: IStream;
end;
_ULARGE_INTEGER = packed record
QuadPart: Largeuint;
end;
__MIDL___MIDL_itf_PortableDeviceApi_0001_0000_0001 = record
case Integer of
0: (cVal: Shortint);
1: (bVal: Byte);
2: (iVal: Smallint);
3: (uiVal: Word);
4: (lVal: Integer);
5: (ulVal: LongWord);
6: (intVal: SYSINT);
7: (uintVal: SYSUINT);
8: (hVal: _LARGE_INTEGER);
9: (uhVal: _ULARGE_INTEGER);
10: (fltVal: Single);
11: (dblVal: Double);
12: (boolVal: WordBool);
13: (bool: WordBool);
14: (scode: SCODE);
15: (cyVal: Currency);
16: (date: TDateTime);
17: (filetime: _FILETIME);
18: (puuid: ^TGUID);
19: (pClipData: ^tagCLIPDATA);
20: (bstrVal: {!!WideString}Pointer);
21: (bstrblobVal: tagBSTRBLOB);
22: (blob: tagBLOB);
23: (pszVal: PChar);
24: (pwszVal: PWideChar);
25: (punkVal: {!!IUnknown}Pointer);
26: (pdispVal: {!!IDispatch}Pointer);
27: (pStream: {!!IStream}Pointer);
28: (pStorage: {!!IStorage}Pointer);
29: (pVersionedStream: ^tagVersionedStream);
30: (parray: wirePSAFEARRAY);
31: (cac: tagCAC);
32: (caub: tagCAUB);
33: (cai: tagCAI);
34: (caui: tagCAUI);
35: (cal: tagCAL);
36: (caul: tagCAUL);
37: (cah: tagCAH);
38: (cauh: tagCAUH);
39: (caflt: tagCAFLT);
40: (cadbl: tagCADBL);
41: (cabool: tagCABOOL);
42: (cascode: tagCASCODE);
43: (cacy: tagCACY);
44: (cadate: tagCADATE);
45: (cafiletime: tagCAFILETIME);
46: (cauuid: tagCACLSID);
47: (caclipdata: tagCACLIPDATA);

48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:

(cabstr: tagCABSTR);
(cabstrblob: tagCABSTRBLOB);
(calpstr: tagCALPSTR);
(calpwstr: tagCALPWSTR);
(capropvar: tagCAPROPVARIANT);
(pcVal: ^Shortint);
(pbVal: ^Byte);
(piVal: ^Smallint);
(puiVal: ^Word);
(plVal: ^Integer);
(pulVal: ^LongWord);
(pintVal: ^SYSINT);
(puintVal: ^SYSUINT);
(pfltVal: ^Single);
(pdblVal: ^Double);
(pboolVal: ^WordBool);
(pdecVal: ^TDecimal);
(pscode: ^SCODE);
(pcyVal: ^Currency);
(pdate: ^TDateTime);
(pbstrVal: ^WideString);
(ppunkVal: {!!^IUnknown}Pointer);
(ppdispVal: {!!^IDispatch}Pointer);
(pparray: ^wirePSAFEARRAY);
(pvarVal: PUserType2);

end;

tag_inner_PROPVARIANT = packed record


vt: Word;
wReserved1: Byte;
wReserved2: Byte;
wReserved3: LongWord;
__MIDL____MIDL_itf_PortableDeviceApi_0001_00000001: __MIDL___MIDL_itf_Portab
leDeviceApi_0001_0000_0001;
end;
_tagpropertykey = packed record
fmtid: TGUID;
pid: LongWord;
end;
_wireSAFEARR_BSTR = packed record
Size: LongWord;
aBstr: ^PUserType6;
end;
_wireSAFEARR_UNKNOWN = packed record
Size: LongWord;
apUnknown: ^IUnknown;
end;
_wireSAFEARR_DISPATCH = packed record
Size: LongWord;
apDispatch: ^IDispatch;
end;
_FLAGGED_WORD_BLOB = packed record

fFlags: LongWord;
clSize: LongWord;
asData: ^Word;
end;
_wireSAFEARR_VARIANT = packed record
Size: LongWord;
aVariant: ^PUserType7;
end;
_wireBRECORD = packed record
fFlags: LongWord;
clSize: LongWord;
pRecInfo: IRecordInfo;
pRecord: ^Byte;
end;
_wireSAFEARR_BRECORD = packed record
Size: LongWord;
aRecord: ^PUserType14;
end;
_wireSAFEARR_HAVEIID = packed record
Size: LongWord;
apUnknown: ^IUnknown;
iid: TGUID;
end;
_BYTE_SIZEDARR = packed record
clSize: LongWord;
pData: ^Byte;
end;
_SHORT_SIZEDARR = packed record
clSize: LongWord;
pData: ^Word;
end;
_LONG_SIZEDARR = packed record
clSize: LongWord;
pData: ^LongWord;
end;
_HYPER_SIZEDARR = packed record
clSize: LongWord;
pData: ^Int64;
end;
__MIDL_IOleAutomationTypes_0001 = record
case Integer of
0: (BstrStr: _wireSAFEARR_BSTR);
1: (UnknownStr: _wireSAFEARR_UNKNOWN);
2: (DispatchStr: _wireSAFEARR_DISPATCH);
3: (VariantStr: _wireSAFEARR_VARIANT);
4: (RecordStr: _wireSAFEARR_BRECORD);
5: (HaveIidStr: _wireSAFEARR_HAVEIID);
6: (ByteStr: _BYTE_SIZEDARR);
7: (WordStr: _SHORT_SIZEDARR);
8: (LongStr: _LONG_SIZEDARR);

9: (HyperStr: _HYPER_SIZEDARR);
end;
_wireSAFEARRAY_UNION = packed record
sfType: LongWord;
u: __MIDL_IOleAutomationTypes_0001;
end;
_wireSAFEARRAY = packed record
cDims: Word;
fFeatures: Word;
cbElements: LongWord;
cLocks: LongWord;
uArrayStructs: _wireSAFEARRAY_UNION;
rgsabound: ^tagSAFEARRAYBOUND;
end;
__MIDL_IOleAutomationTypes_0004 = record
case Integer of
0: (llVal: Int64);
1: (lVal: Integer);
2: (bVal: Byte);
3: (iVal: Smallint);
4: (fltVal: Single);
5: (dblVal: Double);
6: (boolVal: WordBool);
7: (scode: SCODE);
8: (cyVal: Currency);
9: (date: TDateTime);
10: (bstrVal: ^_FLAGGED_WORD_BLOB);
11: (punkVal: {!!IUnknown}Pointer);
12: (pdispVal: {!!IDispatch}Pointer);
13: (parray: ^PUserType5);
14: (brecVal: ^_wireBRECORD);
15: (pbVal: ^Byte);
16: (piVal: ^Smallint);
17: (plVal: ^Integer);
18: (pllVal: ^Int64);
19: (pfltVal: ^Single);
20: (pdblVal: ^Double);
21: (pboolVal: ^WordBool);
22: (pscode: ^SCODE);
23: (pcyVal: ^Currency);
24: (pdate: ^TDateTime);
25: (pbstrVal: ^PUserType6);
26: (ppunkVal: {!!^IUnknown}Pointer);
27: (ppdispVal: {!!^IDispatch}Pointer);
28: (pparray: ^PPUserType1);
29: (pvarVal: ^PUserType7);
30: (cVal: Shortint);
31: (uiVal: Word);
32: (ulVal: LongWord);
33: (ullVal: Largeuint);
34: (intVal: SYSINT);
35: (uintVal: SYSUINT);
36: (decVal: TDecimal);
37: (pdecVal: ^TDecimal);
38: (pcVal: ^Shortint);
39: (puiVal: ^Word);
40: (pulVal: ^LongWord);

41: (pullVal: ^Largeuint);


42: (pintVal: ^SYSINT);
43: (puintVal: ^SYSUINT);
end;
_wireVARIANT = packed record
clSize: LongWord;
rpcReserved: LongWord;
vt: Word;
wReserved1: Word;
wReserved2: Word;
wReserved3: Word;
DUMMYUNIONNAME: __MIDL_IOleAutomationTypes_0004;
end;
// *********************************************************************//
// Interface: IPortableDeviceKeyCollection
// Flags:
(0)
// GUID:
{DADA2357-E0AD-492E-98DB-DD61C53BA353}
// *********************************************************************//
IPortableDeviceKeyCollection = interface(IUnknown)
['{DADA2357-E0AD-492E-98DB-DD61C53BA353}']
function GetCount(var pcElems: LongWord): HResult; stdcall;
function GetAt(dwIndex: LongWord; var pKey: _tagpropertykey): HResult; stdca
ll;
function Add(var key: _tagpropertykey): HResult; stdcall;
function Clear: HResult; stdcall;
function RemoveAt(dwIndex: LongWord): HResult; stdcall;
end;
// *********************************************************************//
Interface: IPortableDevicePropVariantCollection
Flags:
(0)
GUID:
{89B2E422-4F1B-4316-BCEF-A44AFEA83EB3}
*********************************************************************//
IPortableDevicePropVariantCollection = interface(IUnknown)
['{89B2E422-4F1B-4316-BCEF-A44AFEA83EB3}']
function GetCount(var pcElems: LongWord): HResult; stdcall;
function GetAt(dwIndex: LongWord; var pValue: tag_inner_PROPVARIANT): HResul
t; stdcall;
function Add(var pValue: tag_inner_PROPVARIANT): HResult; stdcall;
function GetType(out pvt: Word): HResult; stdcall;
function ChangeType(vt: Word): HResult; stdcall;
function Clear: HResult; stdcall;
function RemoveAt(dwIndex: LongWord): HResult; stdcall;
end;
//
//
//
//

// *********************************************************************//
Interface: IPortableDeviceValuesCollection
Flags:
(0)
GUID:
{6E3F2D79-4E07-48C4-8208-D8C2E5AF4A99}
*********************************************************************//
IPortableDeviceValuesCollection = interface(IUnknown)
['{6E3F2D79-4E07-48C4-8208-D8C2E5AF4A99}']
function GetCount(var pcElems: LongWord): HResult; stdcall;
function GetAt(dwIndex: LongWord; out ppValues: IPortableDeviceValues): HRes
ult; stdcall;
function Add(const pValues: IPortableDeviceValues): HResult; stdcall;
function Clear: HResult; stdcall;
function RemoveAt(dwIndex: LongWord): HResult; stdcall;
//
//
//
//

end;
// *********************************************************************//
Interface: IPropertyStore
Flags:
(0)
GUID:
{886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99}
*********************************************************************//
IPropertyStore = interface(IUnknown)
['{886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99}']
function GetCount(out cProps: LongWord): HResult; stdcall;
function GetAt(iProp: LongWord; out pKey: _tagpropertykey): HResult; stdcall

//
//
//
//

;
function GetValue(var key: _tagpropertykey; out pv: tag_inner_PROPVARIANT):
HResult; stdcall;
function SetValue(var key: _tagpropertykey; var propvar: tag_inner_PROPVARIA
NT): HResult; stdcall;
function Commit: HResult; stdcall;
end;
//
//
//
//
//

*********************************************************************//
Interface: IPortableDeviceValues
Flags:
(0)
GUID:
{6848F6F2-3155-4F86-B6F5-263EEEAB3143}
*********************************************************************//
IPortableDeviceValues = interface(IUnknown)
['{6848F6F2-3155-4F86-B6F5-263EEEAB3143}']
function GetCount(var pcelt: LongWord): HResult; stdcall;
function GetAt(index: LongWord; var pKey: _tagpropertykey; var pValue: tag_i
nner_PROPVARIANT): HResult; stdcall;
function SetValue(var key: _tagpropertykey; var pValue: tag_inner_PROPVARIAN
T): HResult; stdcall;
function GetValue(var key: _tagpropertykey; out pValue: tag_inner_PROPVARIAN
T): HResult; stdcall;
function SetStringValue(var key: _tagpropertykey; Value: PWideChar): HResult
; stdcall;
function GetStringValue(var key: _tagpropertykey; out pValue: PWideChar): HR
esult; stdcall;
function SetUnsignedIntegerValue(var key: _tagpropertykey; Value: LongWord):
HResult; stdcall;
function GetUnsignedIntegerValue(var key: _tagpropertykey; out pValue: LongW
ord): HResult; stdcall;
function SetSignedIntegerValue(var key: _tagpropertykey; Value: Integer): HR
esult; stdcall;
function GetSignedIntegerValue(var key: _tagpropertykey; out pValue: Integer
): HResult; stdcall;
function SetUnsignedLargeIntegerValue(var key: _tagpropertykey; Value: Large
uint): HResult; stdcall;
function GetUnsignedLargeIntegerValue(var key: _tagpropertykey; out pValue:
Largeuint): HResult; stdcall;
function SetSignedLargeIntegerValue(var key: _tagpropertykey; Value: Int64):
HResult; stdcall;
function GetSignedLargeIntegerValue(var key: _tagpropertykey; out pValue: In
t64): HResult; stdcall;
function SetFloatValue(var key: _tagpropertykey; Value: Single): HResult; st
dcall;
function GetFloatValue(var key: _tagpropertykey; out pValue: Single): HResul
t; stdcall;
function SetErrorValue(var key: _tagpropertykey; Value: HResult): HResult; s
tdcall;

function GetErrorValue(var key: _tagpropertykey; out pValue: HResult): HResu


lt; stdcall;
function SetKeyValue(var key: _tagpropertykey; var Value: _tagpropertykey):
HResult; stdcall;
function GetKeyValue(var key: _tagpropertykey; out pValue: _tagpropertykey):
HResult; stdcall;
function SetBoolValue(var key: _tagpropertykey; Value: Integer): HResult; st
dcall;
function GetBoolValue(var key: _tagpropertykey; out pValue: Integer): HResul
t; stdcall;
function SetIUnknownValue(var key: _tagpropertykey; const pValue: IUnknown):
HResult; stdcall;
function GetIUnknownValue(var key: _tagpropertykey; out ppValue: IUnknown):
HResult; stdcall;
function SetGuidValue(var key: _tagpropertykey; var Value: TGUID): HResult;
stdcall;
function GetGuidValue(var key: _tagpropertykey; out pValue: TGUID): HResult;
stdcall;
function SetBufferValue(var key: _tagpropertykey; var pValue: Byte; cbValue:
LongWord): HResult; stdcall;
function GetBufferValue(var key: _tagpropertykey; out ppValue: PByte1; out p
cbValue: LongWord): HResult; stdcall;
function SetIPortableDeviceValuesValue(var key: _tagpropertykey;
const pValue: IPortableDeviceValues):
HResult; stdcall;
function GetIPortableDeviceValuesValue(var key: _tagpropertykey;
out ppValue: IPortableDeviceValues):
HResult; stdcall;
function SetIPortableDevicePropVariantCollectionValue(var key: _tagpropertyk
ey;
const pValue: IPortabl
eDevicePropVariantCollection): HResult; stdcall;
function GetIPortableDevicePropVariantCollectionValue(var key: _tagpropertyk
ey;
out ppValue: IPortable
DevicePropVariantCollection): HResult; stdcall;
function SetIPortableDeviceKeyCollectionValue(var key: _tagpropertykey;
const pValue: IPortableDeviceK
eyCollection): HResult; stdcall;
function GetIPortableDeviceKeyCollectionValue(var key: _tagpropertykey;
out ppValue: IPortableDeviceKe
yCollection): HResult; stdcall;
function SetIPortableDeviceValuesCollectionValue(var key: _tagpropertykey;
const pValue: IPortableDevi
ceValuesCollection): HResult; stdcall;
function GetIPortableDeviceValuesCollectionValue(var key: _tagpropertykey;
out ppValue: IPortableDevic
eValuesCollection): HResult; stdcall;
function RemoveValue(var key: _tagpropertykey): HResult; stdcall;
function CopyValuesFromPropertyStore(const pStore: IPropertyStore): HResult;
stdcall;
function CopyValuesToPropertyStore(const pStore: IPropertyStore): HResult; s
tdcall;
function Clear: HResult; stdcall;
end;
// *********************************************************************//
// Interface: IEnumPortableDeviceObjectIDs
// Flags:
(0)

// GUID:
{10ECE955-CF41-4728-BFA0-41EEDF1BBF19}
// *********************************************************************//
IEnumPortableDeviceObjectIDs = interface(IUnknown)
['{10ECE955-CF41-4728-BFA0-41EEDF1BBF19}']
function Next(cObjects: LongWord; out pObjIDs: PWideChar; var pcFetched: Lon
gWord): HResult; stdcall;
function Skip(cObjects: LongWord): HResult; stdcall;
function Reset: HResult; stdcall;
function Clone(out ppenum: IEnumPortableDeviceObjectIDs): HResult; stdcall;
function Cancel: HResult; stdcall;
end;
// *********************************************************************//
Interface: IPortableDeviceProperties
Flags:
(0)
GUID:
{7F6D695C-03DF-4439-A809-59266BEEE3A6}
*********************************************************************//
IPortableDeviceProperties = interface(IUnknown)
['{7F6D695C-03DF-4439-A809-59266BEEE3A6}']
function GetSupportedProperties(pszObjectID: PWideChar; out ppKeys: IPortabl
eDeviceKeyCollection): HResult; stdcall;
function GetPropertyAttributes(pszObjectID: PWideChar; var key: _tagproperty
key;
out ppAttributes: IPortableDeviceValues): HRe
sult; stdcall;
function GetValues(pszObjectID: PWideChar; const pKeys: IPortableDeviceKeyCo
llection;
out ppValues: IPortableDeviceValues): HResult; stdcall;
function SetValues(pszObjectID: PWideChar; const pValues: IPortableDeviceVal
ues;
out ppResults: IPortableDeviceValues): HResult; stdcall;
function Delete(pszObjectID: PWideChar; const pKeys: IPortableDeviceKeyColle
ction): HResult; stdcall;
function Cancel: HResult; stdcall;
end;
//
//
//
//

//
//
//
//
//

*********************************************************************//
Interface: IPortableDeviceResources
Flags:
(0)
GUID:
{FD8878AC-D841-4D17-891C-E6829CDB6934}
*********************************************************************//
IPortableDeviceResources = interface(IUnknown)
['{FD8878AC-D841-4D17-891C-E6829CDB6934}']
function GetSupportedResources(pszObjectID: PWideChar; out ppKeys: IPortable
DeviceKeyCollection): HResult; stdcall;
function GetResourceAttributes(pszObjectID: PWideChar; var key: _tagproperty
key;
out ppResourceAttributes: IPortableDeviceValu
es): HResult; stdcall;
function GetStream(pszObjectID: PWideChar; var key: _tagpropertykey; dwMode:
LongWord;
var pdwOptimalBufferSize: LongWord; out ppStream: IStream
): HResult; stdcall;
function Delete(pszObjectID: PWideChar; const pKeys: IPortableDeviceKeyColle
ction): HResult; stdcall;
function Cancel: HResult; stdcall;
function CreateResource(const pResourceAttributes: IPortableDeviceValues; ou
t ppData: IStream;
var pdwOptimalWriteBufferSize: LongWord; var ppszCoo
kie: PWideChar): HResult; stdcall;

end;
//
//
//
//
//

*********************************************************************//
Interface: IPortableDeviceContent
Flags:
(0)
GUID:
{6A96ED84-7C73-4480-9938-BF5AF477D426}
*********************************************************************//
IPortableDeviceContent = interface(IUnknown)
['{6A96ED84-7C73-4480-9938-BF5AF477D426}']
function EnumObjects(dwFlags: LongWord; pszParentObjectID: PWideChar;
const pFilter: IPortableDeviceValues;
out ppenum: IEnumPortableDeviceObjectIDs): HResult; std
call;
function Properties(out ppProperties: IPortableDeviceProperties): HResult; s
tdcall;
function Transfer(out ppResources: IPortableDeviceResources): HResult; stdca
ll;
function CreateObjectWithPropertiesOnly(const pValues: IPortableDeviceValues
;
var ppszObjectID: PWideChar): HResul
t; stdcall;
function CreateObjectWithPropertiesAndData(const pValues: IPortableDeviceVal
ues;
out ppData: IStream;
var pdwOptimalWriteBufferSize: Lo
ngWord;
var ppszCookie: PWideChar): HResu
lt; stdcall;
function Delete(dwOptions: LongWord; const pObjectIDs: IPortableDevicePropVa
riantCollection;
var ppResults: IPortableDevicePropVariantCollection): HResul
t; stdcall;
function GetObjectIDsFromPersistentUniqueIDs(const pPersistentUniqueIDs: IPo
rtableDevicePropVariantCollection;
out ppObjectIDs: IPortableDevic
ePropVariantCollection): HResult; stdcall;
function Cancel: HResult; stdcall;
function Move(const pObjectIDs: IPortableDevicePropVariantCollection;
pszDestinationFolderObjectID: PWideChar;
var ppResults: IPortableDevicePropVariantCollection): HResult;
stdcall;
function Copy(const pObjectIDs: IPortableDevicePropVariantCollection;
pszDestinationFolderObjectID: PWideChar;
var ppResults: IPortableDevicePropVariantCollection): HResult;
stdcall;
end;
//
//
//
//
//

*********************************************************************//
Interface: IPortableDeviceCapabilities
Flags:
(0)
GUID:
{2C8C6DBF-E3DC-4061-BECC-8542E810D126}
*********************************************************************//
IPortableDeviceCapabilities = interface(IUnknown)
['{2C8C6DBF-E3DC-4061-BECC-8542E810D126}']
function GetSupportedCommands(out ppCommands: IPortableDeviceKeyCollection):
HResult; stdcall;
function GetCommandOptions(var Command: _tagpropertykey; out ppOptions: IPor
tableDeviceValues): HResult; stdcall;
function GetFunctionalCategories(out ppCategories: IPortableDevicePropVarian

tCollection): HResult; stdcall;


function GetFunctionalObjects(var Category: TGUID;
out ppObjectIDs: IPortableDevicePropVariantCol
lection): HResult; stdcall;
function GetSupportedContentTypes(var Category: TGUID;
out ppContentTypes: IPortableDevicePropVar
iantCollection): HResult; stdcall;
function GetSupportedFormats(var ContentType: TGUID;
out ppFormats: IPortableDevicePropVariantCollec
tion): HResult; stdcall;
function GetSupportedFormatProperties(var Format: TGUID;
out ppKeys: IPortableDeviceKeyCollecti
on): HResult; stdcall;
function GetFixedPropertyAttributes(var Format: TGUID; var key: _tagproperty
key;
out ppAttributes: IPortableDeviceValues)
: HResult; stdcall;
function Cancel: HResult; stdcall;
function GetSupportedEvents(out ppEvents: IPortableDevicePropVariantCollecti
on): HResult; stdcall;
function GetEventOptions(var Event: TGUID; out ppOptions: IPortableDeviceVal
ues): HResult; stdcall;
end;
//
//
//
//
//

*********************************************************************//
Interface: IPortableDeviceEventCallback
Flags:
(0)
GUID:
{A8792A31-F385-493C-A893-40F64EB45F6E}
*********************************************************************//
IPortableDeviceEventCallback = interface(IUnknown)
['{A8792A31-F385-493C-A893-40F64EB45F6E}']
function OnEvent(const pEventParameters: IPortableDeviceValues): HResult; st
dcall;
end;
//
//
//
//
//

*********************************************************************//
Interface: IPortableDevice
Flags:
(0)
GUID:
{625E2DF8-6392-4CF0-9AD1-3CFA5F17775C}
*********************************************************************//
IPortableDevice = interface(IUnknown)
['{625E2DF8-6392-4CF0-9AD1-3CFA5F17775C}']
function Open(pszPnPDeviceID: PWideChar; const pClientInfo: IPortableDeviceV
alues): HResult; stdcall;
function SendCommand(dwFlags: LongWord; const pParameters: IPortableDeviceVa
lues;
out ppResults: IPortableDeviceValues): HResult; stdcall
;
function Content(out ppContent: IPortableDeviceContent): HResult; stdcall;
function Capabilities(out ppCapabilities: IPortableDeviceCapabilities): HRes
ult; stdcall;
function Cancel: HResult; stdcall;
function Close: HResult; stdcall;
function Advise(dwFlags: LongWord; const pCallback: IPortableDeviceEventCall
back;
const pParameters: IPortableDeviceValues; out ppszCookie: PW
ideChar): HResult; stdcall;
function Unadvise(pszCookie: PWideChar): HResult; stdcall;
function GetPnPDeviceID(out ppszPnPDeviceID: PWideChar): HResult; stdcall;

end;
//
//
//
//
//

*********************************************************************//
Interface: IPortableDeviceManager
Flags:
(0)
GUID:
{A1567595-4C2F-4574-A6FA-ECEF917B9A40}
*********************************************************************//
IPortableDeviceManager = interface(IUnknown)
['{A1567595-4C2F-4574-A6FA-ECEF917B9A40}']
function GetDevices(var pPnPDeviceIDs: PWideChar; var pcPnPDeviceIDs: LongWo
rd): HResult; stdcall;
function RefreshDeviceList: HResult; stdcall;
function GetDeviceFriendlyName(pszPnPDeviceID: PWideChar; var pDeviceFriendl
yName: Word;
var pcchDeviceFriendlyName: LongWord): HResul
t; stdcall;
function GetDeviceDescription(pszPnPDeviceID: PWideChar; var pDeviceDescript
ion: Word;
var pcchDeviceDescription: LongWord): HResult;
stdcall;
function GetDeviceManufacturer(pszPnPDeviceID: PWideChar; var pDeviceManufac
turer: Word;
var pcchDeviceManufacturer: LongWord): HResul
t; stdcall;
function GetDeviceProperty(pszPnPDeviceID: PWideChar; pszDevicePropertyName:
PWideChar;
var pData: Byte; var pcbData: LongWord; var pdwTy
pe: LongWord): HResult; stdcall;
function GetPrivateDevices(var pPnPDeviceIDs: PWideChar; var pcPnPDeviceIDs:
LongWord): HResult; stdcall;
end;
//
//
//
//
//

*********************************************************************//
Interface: IPortableDeviceDispatchFactory
Flags:
(0)
GUID:
{5E1EAFC3-E3D7-4132-96FA-759C0F9D1E0F}
*********************************************************************//
IPortableDeviceDispatchFactory = interface(IUnknown)
['{5E1EAFC3-E3D7-4132-96FA-759C0F9D1E0F}']
function GetDeviceDispatch(pszPnPDeviceID: PWideChar; out ppDeviceDispatch:
IDispatch): HResult; stdcall;
end;
// *********************************************************************//
The Class CoPortableDevice provides a Create and CreateRemote method to
create instances of the default interface IPortableDevice exposed by
the CoClass PortableDevice. The functions are intended to be used by
clients wishing to automate the CoClass objects exposed by the
server of this typelibrary.
*********************************************************************//
CoPortableDevice = class
class function Create: IPortableDevice;
class function CreateRemote(const MachineName: string): IPortableDevice;
end;

//
//
//
//
//
//

// *********************************************************************//
// OLE Server Proxy class declaration
// Server Object
: TPortableDeviceManager

// Help String
: PortableDeviceManager Class
// Default Interface: IPortableDeviceManager
// Def. Intf. DISP? : No
// Event Interface:
// TypeFlags
: (2) CanCreate
// *********************************************************************//
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
TPortableDeviceManagerProperties= class;
{$ENDIF}
TPortableDeviceManager = class(TOleServer)
private
FIntf: IPortableDeviceManager;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps: TPortableDeviceManagerProperties;
function GetServerProperties: TPortableDeviceManagerProperties;
{$ENDIF}
function GetDefaultInterface: IPortableDeviceManager;
protected
procedure InitServerData; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Connect; override;
procedure ConnectTo(svrIntf: IPortableDeviceManager);
procedure Disconnect; override;
function GetDevices(var pPnPDeviceIDs: PWideChar; var pcPnPDeviceIDs: LongWo
rd): HResult;
function RefreshDeviceList: HResult;
function GetDeviceFriendlyName(pszPnPDeviceID: PWideChar; var pDeviceFriendl
yName: Word;
var pcchDeviceFriendlyName: LongWord): HResul
t;
function GetDeviceDescription(pszPnPDeviceID: PWideChar; var pDeviceDescript
ion: Word;
var pcchDeviceDescription: LongWord): HResult;
function GetDeviceManufacturer(pszPnPDeviceID: PWideChar; var pDeviceManufac
turer: Word;
var pcchDeviceManufacturer: LongWord): HResul
t;
function GetDeviceProperty(pszPnPDeviceID: PWideChar; pszDevicePropertyName:
PWideChar;
var pData: Byte; var pcbData: LongWord; var pdwTy
pe: LongWord): HResult;
function GetPrivateDevices(var pPnPDeviceIDs: PWideChar; var pcPnPDeviceIDs:
LongWord): HResult;
property DefaultInterface: IPortableDeviceManager read GetDefaultInterface;
published
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
property Server: TPortableDeviceManagerProperties read GetServerProperties;
{$ENDIF}
end;
TForm1 = class(TForm)
LogMemo: TMemo;
DeviceList: TListBox;
Panel1: TPanel;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure DeviceListClick(Sender: TObject);
private

procedure RefreshDeviceList;
function ConnectToDevice(sDev: WideString; var PortableDev: IPortableDevice)
: Boolean;
procedure GetDeviceInformation(PortableDev: IPortableDevice);
public
procedure Log(AStr: string);
procedure LogContinue(AStr: string);
procedure LogContinueNotifyOK;
procedure LogContinueNotifyERROR;
procedure LogContinueNotifyYES;
procedure LogContinueNotifyNO;
end;
function GetDeviceFriendlyName(DeviceManager: TPortableDeviceManager; sDeviceId:
WideString): WideString;
function GetDeviceManufacturer(DeviceManager: TPortableDeviceManager; sDeviceId:
WideString): WideString;
var
Form1: TForm1;
fPDM: TPortableDeviceManager;
DeviceIDs: array of PWideChar;
implementation
{$R *.dfm}
class function CoPortableDevice.Create: IPortableDevice;
begin
Result := CreateComObject(CLASS_PortableDevice) as IPortableDevice;
end;
class function CoPortableDevice.CreateRemote(const MachineName: string): IPortab
leDevice;
begin
Result := CreateRemoteComObject(MachineName, CLASS_PortableDevice) as IPortabl
eDevice;
end;
procedure TPortableDeviceManager.InitServerData;
const
CServerData: TServerData = (
ClassID: '{0AF10CEC-2ECD-4B92-9581-34F6AE0637F3}';
IntfIID: '{A1567595-4C2F-4574-A6FA-ECEF917B9A40}';
EventIID: '';
LicenseKey: nil;
Version: 500);
begin
ServerData := @CServerData;
end;
procedure TPortableDeviceManager.Connect;
var
punk: IUnknown;
begin
if FIntf = nil then
begin
punk := GetServer;
Fintf:= punk as IPortableDeviceManager;

end;
end;
procedure TPortableDeviceManager.ConnectTo(svrIntf: IPortableDeviceManager);
begin
Disconnect;
FIntf := svrIntf;
end;
procedure TPortableDeviceManager.DisConnect;
begin
if Fintf <> nil then
begin
FIntf := nil;
end;
end;
function TPortableDeviceManager.GetDefaultInterface: IPortableDeviceManager;
begin
if FIntf = nil then
Connect;
Assert(FIntf <> nil, 'DefaultInterface is NULL. Component is not connected to
Server. You must call "Connect" or "ConnectTo" before this operation');
Result := FIntf;
end;
constructor TPortableDeviceManager.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps := TPortableDeviceManagerProperties.Create(Self);
{$ENDIF}
end;
destructor TPortableDeviceManager.Destroy;
begin
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
FProps.Free;
{$ENDIF}
inherited Destroy;
end;
{$IFDEF LIVE_SERVER_AT_DESIGN_TIME}
function TPortableDeviceManager.GetServerProperties: TPortableDeviceManagerPrope
rties;
begin
Result := FProps;
end;
{$ENDIF}
function TPortableDeviceManager.GetDevices(var pPnPDeviceIDs: PWideChar;
var pcPnPDeviceIDs: LongWord): HResul
t;
begin
Result := DefaultInterface.GetDevices(pPnPDeviceIDs, pcPnPDeviceIDs);
end;
function TPortableDeviceManager.RefreshDeviceList: HResult;
begin
Result := DefaultInterface.RefreshDeviceList;

end;
function TPortableDeviceManager.GetDeviceFriendlyName(pszPnPDeviceID: PWideChar;
var pDeviceFriendlyName: W
ord;
var pcchDeviceFriendlyName
: LongWord): HResult;
begin
Result := DefaultInterface.GetDeviceFriendlyName(pszPnPDeviceID, pDeviceFriend
lyName,
pcchDeviceFriendlyName);
end;
function TPortableDeviceManager.GetDeviceDescription(pszPnPDeviceID: PWideChar;
var pDeviceDescription: Wor
d;
var pcchDeviceDescription:
LongWord): HResult;
begin
Result := DefaultInterface.GetDeviceDescription(pszPnPDeviceID, pDeviceDescrip
tion,
pcchDeviceDescription);
end;
function TPortableDeviceManager.GetDeviceManufacturer(pszPnPDeviceID: PWideChar;
var pDeviceManufacturer: W
ord;
var pcchDeviceManufacturer
: LongWord): HResult;
begin
Result := DefaultInterface.GetDeviceManufacturer(pszPnPDeviceID, pDeviceManufa
cturer,
pcchDeviceManufacturer);
end;
function TPortableDeviceManager.GetDeviceProperty(pszPnPDeviceID: PWideChar;
pszDevicePropertyName: PWideCh
ar;
var pData: Byte; var pcbData:
LongWord;
var pdwType: LongWord): HResul
t;
begin
Result := DefaultInterface.GetDeviceProperty(pszPnPDeviceID, pszDeviceProperty
Name, pData,
pcbData, pdwType);
end;
function TPortableDeviceManager.GetPrivateDevices(var pPnPDeviceIDs: PWideChar;
var pcPnPDeviceIDs: LongWord):
HResult;
begin
Result := DefaultInterface.GetPrivateDevices(pPnPDeviceIDs, pcPnPDeviceIDs);
end;
//class function CoPortableDeviceService.Create: IPortableDeviceService;
//begin
// Result := CreateComObject(CLASS_PortableDeviceService) as IPortableDeviceSer
vice;
//end;

function GetDeviceFriendlyName(DeviceManager: TPortableDeviceManager; sDeviceId:


WideString): WideString;
var iDevNameLen: LongWord;
iRes: Integer;
s: WideString;
begin
//get length of friendly name:
iDevNameLen := 0;
s := '';
iRes := DeviceManager.GetDeviceFriendlyName(PWideChar(sDeviceId), Word(nil^),
iDevNameLen);
if iRes = S_OK then
if iDevNameLen>0 then
begin
SetLength(s, iDevNameLen);
ZeroMemory(PWideChar(s), iDevNameLen);
DeviceManager.GetDeviceFriendlyName(PWideChar(sDeviceId), PWord(PWideChar(
s))^, iDevNameLen);
s := Trim(s);
end;
result := s;
end;
function GetDeviceManufacturer(DeviceManager: TPortableDeviceManager; sDeviceId:
WideString): WideString;
var iDevManufacturerLen: LongWord;
iRes: Integer;
s: WideString;
begin
//get length of manufacturer name:
iDevManufacturerLen := 0;
s := '';
iRes := DeviceManager.GetDeviceManufacturer(PWideChar(sDeviceId), Word(nil^),
iDevManufacturerLen);
if iRes = S_OK then
if iDevManufacturerLen>0 then
begin
SetLength(s, iDevManufacturerLen);
ZeroMemory(PWideChar(s), iDevManufacturerLen);
DeviceManager.GetDeviceFriendlyName(PWideChar(sDeviceId), PWord(PWideChar(
s))^, iDevManufacturerLen);
s := Trim(s);
end;
result := s;
end;
//Sample code START
procedure TForm1.Log(AStr: string);
begin
LogMemo.Lines.insert(0, AStr);
end;

procedure TForm1.LogContinue(AStr: string);


begin
if assigned(LogMemo) then LogMemo.Lines.Strings[0] := LogMemo.Lines.Strings[0]
+ AStr;
end;
procedure TForm1.LogContinueNotifyOK;
begin
LogMemo.Lines.Strings[0] := LogMemo.Lines.Strings[0] + ' OK!!';
end;
procedure TForm1.LogContinueNotifyERROR;
begin
LogMemo.Lines.Strings[0] := LogMemo.Lines.Strings[0] + ' ERROR!';
end;
procedure TForm1.LogContinueNotifyYES;
begin
LogContinue(' YES!');
end;
procedure TForm1.LogContinueNotifyNO;
begin
LogMemo.Lines.Strings[0] := LogMemo.Lines.Strings[0] + ' NO!';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
fPDM := TPortableDeviceManager.Create(nil);
RefreshDeviceList;
end;
procedure TForm1.RefreshDeviceList;
var iDevCount: LongWord;
i, iRes: Integer;
DevFriendlyName: WideString;
PortableDevice: IPortableDevice;
begin
if fPDM.RefreshDeviceList = S_OK then
begin
// Determine how many WPD devices are connected
iDevCount := 1;
if fPDM.GetDevices(PWideChar(nil^), iDevCount) = S_OK then
if iDevCount > 0 then
begin
// Retrieve the device id for each connected device
SetLength(DeviceIDs, iDevCount);
iRes := fPDM.GetDevices(DeviceIDs[0], iDevCount);
DeviceList.items.clear;
if iRes = S_OK then
for i := 0 to iDevCount - 1 do //enumerate the devices:
DeviceList.Items.Add(GetDeviceFriendlyName(fPDM, DeviceIDs[i]));
end;
end;

end;
function TForm1.ConnectToDevice(sDev: WideString; var PortableDev: IPortableDevi
ce): Boolean;
var
PortableDeviceValues: IPortableDeviceValues;
hr: HResult;
dev_val: _tagpropertykey;
//bReadonly: Boolean;
begin
Result := False;
PortableDev := CoPortableDevice.Create;
try
//create device values:
PortableDeviceValues := CreateComObject(CLASS_PortableDeviceValues) as IPort
ableDeviceValues;
if VarIsClear(PortableDeviceValues) then Exit;
//bReadonly := False;
//set some info
//Aid Vllasaliu: probably just to let the device know who is connected to it
dev_val.fmtid := WPD_CLIENT_NAME_FMTID;
dev_val.pid := WPD_CLIENT_NAME_PID;
PortableDeviceValues.SetStringValue(dev_val, PWideChar('MyClient')); //Clien
t name
dev_val.fmtid := WPD_CLIENT_MAJOR_VERSION_FMTID;
dev_val.pid := WPD_CLIENT_MAJOR_VERSION_PID;
PortableDeviceValues.SetUnsignedIntegerValue(dev_val, 1); //Major version
dev_val.fmtid := WPD_CLIENT_MINOR_VERSION_FMTID;
dev_val.pid := WPD_CLIENT_MINOR_VERSION_PID;
PortableDeviceValues.SetUnsignedIntegerValue(dev_val, 0); //Minor version
dev_val.fmtid := WPD_CLIENT_REVISION_FMTID;
dev_val.pid := WPD_CLIENT_REVISION_PID;
PortableDeviceValues.SetUnsignedIntegerValue(dev_val, 0); //Revision
//open device
hr := PortableDev.Open(PWideChar(sDev), PortableDeviceValues);
if hr = E_ACCESSDENIED then
begin
// Attempt to open for read-only access
dev_val.fmtid := WPD_CLIENT_DESIRED_ACCESS_FMTID;
dev_val.pid := WPD_CLIENT_DESIRED_ACCESS_PID;
PortableDeviceValues.SetUnsignedIntegerValue(dev_val, GENERIC_READ);
hr := PortableDev.Open(PWideChar(sDev), PortableDeviceValues);
//bReadonly := (hr = S_OK);
end;
//opened ok
if hr = S_OK then
begin
Result := True;
LogMemo.Clear;
GetDeviceInformation(PortableDev);
end;

finally
PortableDeviceValues := nil;
end;
end;
procedure TForm1.GetDeviceInformation(PortableDev: IPortableDevice);
function PByte1ArrayToStr(ASrc: PByte1; AArrayCount: cardinal): string;
var i: integer;
begin
for i := 0 to AArrayCount-1 do
result := result + ASrc^.ToHexString;
end;
var
h: HRESULT;
content: IPortableDeviceContent;
properties: IPortableDeviceProperties;
propKeys: IPortableDeviceKeyCollection;
prop_val: IPortableDeviceValues;
propKeys_val: _tagpropertykey;
pwc : PWideChar
ui
: UINT
ui64 : UInt64
c
: cardinal
bool : integer
b
: byte
ba
: PByte1
bac : cardinal
begin
Log('Reading device

;
;
;
;
;
;
;
;
information.');

try
Log('PortableDev.Content(content)...');
h := PortableDev.Content(content);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
propKeys := CreateComObject(CLSID_PortableDeviceKeyCollection) as IPortableD
eviceKeyCollection;
if VarIsClear(propKeys) = false then
begin
Log('Adding WPD_DEVICE_SYNC_PARTNER key...');
propKeys_val.fmtid := WPD_DEVICE_SYNC_PARTNER_FMTID;
propKeys_val.pid
:= WPD_DEVICE_SYNC_PARTNER_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_FIRMWARE_VERSIONs key...');
propKeys_val.fmtid := WPD_DEVICE_FIRMWARE_VERSION_FMTID;
propKeys_val.pid
:= WPD_DEVICE_FIRMWARE_VERSION_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_POWER_LEVEL key...');
propKeys_val.fmtid := WPD_DEVICE_POWER_LEVEL_FMTID;
propKeys_val.pid
:= WPD_DEVICE_POWER_LEVEL_PID;

h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_POWER_LEVEL key...');
propKeys_val.fmtid := WPD_DEVICE_POWER_SOURCE_FMTID;
propKeys_val.pid
:= WPD_DEVICE_POWER_SOURCE_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_POWER_LEVEL key...');
propKeys_val.fmtid := WPD_DEVICE_PROTOCOL_FMTID;
propKeys_val.pid
:= WPD_DEVICE_PROTOCOL_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_MANUFACTURER key...');
propKeys_val.fmtid := WPD_DEVICE_MANUFACTURER_FMTID;
propKeys_val.pid
:= WPD_DEVICE_MANUFACTURER_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_MODEL key...');
propKeys_val.fmtid := WPD_DEVICE_MODEL_FMTID;
propKeys_val.pid
:= WPD_DEVICE_MODEL_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_SERIAL_NUMBER key...');
propKeys_val.fmtid := WPD_DEVICE_SERIAL_NUMBER_FMTID;
propKeys_val.pid
:= WPD_DEVICE_SERIAL_NUMBER_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_SUPPORTS_NON_CONSUMABLE key...');
propKeys_val.fmtid := WPD_DEVICE_SUPPORTS_NON_CONSUMABLE_FMTID;
propKeys_val.pid
:= WPD_DEVICE_SUPPORTS_NON_CONSUMABLE_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_DATETIME key...');
propKeys_val.fmtid := WPD_DEVICE_DATETIME_FMTID;
propKeys_val.pid
:= WPD_DEVICE_DATETIME_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_FRIENDLY_NAME key...');
propKeys_val.fmtid := WPD_DEVICE_FRIENDLY_NAME_FMTID;
propKeys_val.pid
:= WPD_DEVICE_FRIENDLY_NAME_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_SUPPORTED_DRM_SCHEMES key...');
propKeys_val.fmtid := WPD_DEVICE_SUPPORTED_DRM_SCHEMES_FMTID;
propKeys_val.pid
:= WPD_DEVICE_SUPPORTED_DRM_SCHEMES_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_SUPPORTED_FORMATS_ARE_ORDERED key...');
propKeys_val.fmtid := WPD_DEVICE_SUPPORTED_FORMATS_ARE_ORDERED_FMTID;
propKeys_val.pid
:= WPD_DEVICE_SUPPORTED_FORMATS_ARE_ORDERED_PID;

h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_TYPE key...');
propKeys_val.fmtid := WPD_DEVICE_TYPE_FMTID;
propKeys_val.pid
:= WPD_DEVICE_TYPE_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_NETWORK_IDENTIFIER key...');
propKeys_val.fmtid := WPD_DEVICE_NETWORK_IDENTIFIER_FMTID;
propKeys_val.pid
:= WPD_DEVICE_NETWORK_IDENTIFIER_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_FUNCTIONAL_UNIQUE_ID key...');
propKeys_val.fmtid := WPD_DEVICE_FUNCTIONAL_UNIQUE_ID_FMTID;
propKeys_val.pid
:= WPD_DEVICE_FUNCTIONAL_UNIQUE_ID_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_MODEL_UNIQUE_ID key...');
propKeys_val.fmtid := WPD_DEVICE_MODEL_UNIQUE_ID_FMTID;
propKeys_val.pid
:= WPD_DEVICE_MODEL_UNIQUE_ID_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_TRANSPORT key...');
propKeys_val.fmtid := WPD_DEVICE_TRANSPORT_FMTID;
propKeys_val.pid
:= WPD_DEVICE_TRANSPORT_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Adding WPD_DEVICE_USE_DEVICE_STAGE key...');
propKeys_val.fmtid := WPD_DEVICE_USE_DEVICE_STAGE_FMTID;
propKeys_val.pid
:= WPD_DEVICE_USE_DEVICE_STAGE_PID;
h := propKeys.Add(propKeys_val);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('content.Properties(properties)');
h := content.Properties(properties);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;

//
//
//
//
//
//
//
//

Log('Getting values...');
h := properties.GetValues(WPD_DEVICE_OBJECT_ID, propKeys, prop_val);
if not h = S_OK then
begin
LogContinueNotifyERROR;
end
else
if h = S_OK then
begin
LogContinueNotifyOK;
Log('Var "prop_val" is populated?');
if VarIsClear(prop_val) then
begin
LogContinueNotifyNO;
LogContinue('Var "prop_val" needs to be populated!!!');
end
else

if not VarIsClear(prop_val) then


begin
LogContinueNotifyYES;
Log('Reading WPD_DEVICE_SYNC_PARTNER value...');
propKeys_val.fmtid := WPD_DEVICE_SYNC_PARTNER_FMTID;
propKeys_val.pid
:= WPD_DEVICE_SYNC_PARTNER_PID;
h := prop_val.GetStringValue(propKeys_val, pwc);
if h = S_OK then LogContinue(pwidechar(pwc)) else LogContinueNotifyERR
OR;
Log('Reading WPD_DEVICE_FIRMWARE_VERSION value...');
propKeys_val.fmtid := WPD_DEVICE_FIRMWARE_VERSION_FMTID;
propKeys_val.pid
:= WPD_DEVICE_FIRMWARE_VERSION_PID;
h := prop_val.GetStringValue(propKeys_val, pwc);
if h = S_OK then LogContinue(pwidechar(pwc)) else LogContinueNotifyERR
OR;
Log('Reading WPD_DEVICE_POWER_LEVEL value...');
propKeys_val.fmtid := WPD_DEVICE_POWER_LEVEL_FMTID;
propKeys_val.pid
:= WPD_DEVICE_POWER_LEVEL_PID;
h := prop_val.GetUnsignedIntegerValue(propKeys_val, ui);
if h = S_OK then LogContinue(inttostr(ui)) else LogContinueNotifyERROR
;
Log('Reading WPD_DEVICE_POWER_SOURCE value...');
propKeys_val.fmtid := WPD_DEVICE_POWER_SOURCE_FMTID;
propKeys_val.pid
:= WPD_DEVICE_POWER_SOURCE_PID;
h := prop_val.GetUnsignedIntegerValue(propKeys_val, ui);
if h = S_OK then LogContinue(inttostr(ui)) else LogContinueNotifyERROR
;
Log('Reading WPD_DEVICE_PROTOCOL value...');
propKeys_val.fmtid := WPD_DEVICE_PROTOCOL_FMTID;
propKeys_val.pid
:= WPD_DEVICE_PROTOCOL_PID;
h := prop_val.GetStringValue(propKeys_val, pwc);
if h = S_OK then LogContinue(pwidechar(pwc)) else LogContinueNotifyERR
OR;
Log('Reading WPD_DEVICE_MANUFACTURER value...');
propKeys_val.fmtid := WPD_DEVICE_MANUFACTURER_FMTID;
propKeys_val.pid
:= WPD_DEVICE_MANUFACTURER_PID;
h := prop_val.GetStringValue(propKeys_val, pwc);
if h = S_OK then LogContinue(pwidechar(pwc)) else LogContinueNotifyERR
OR;
Log('Reading WPD_DEVICE_MODEL value...');
propKeys_val.fmtid := WPD_DEVICE_MODEL_FMTID;
propKeys_val.pid
:= WPD_DEVICE_MODEL_PID;
h := prop_val.GetStringValue(propKeys_val, pwc);
if h = S_OK then LogContinue(pwidechar(pwc)) else LogContinueNotifyERR
OR;
Log('Reading WPD_DEVICE_SERIAL_NUMBER value...');
propKeys_val.fmtid := WPD_DEVICE_SERIAL_NUMBER_FMTID;
propKeys_val.pid
:= WPD_DEVICE_SERIAL_NUMBER_PID;
h := prop_val.GetStringValue(propKeys_val, pwc);
if h = S_OK then LogContinue(pwidechar(pwc)) else LogContinueNotifyERR
OR;

Log('Reading WPD_DEVICE_SUPPORTS_NON_CONSUMABLE value...');


propKeys_val.fmtid := WPD_DEVICE_SUPPORTS_NON_CONSUMABLE_FMTID;
propKeys_val.pid
:= WPD_DEVICE_SUPPORTS_NON_CONSUMABLE_PID;
h := prop_val.GetBoolValue(propKeys_val, bool);
if h = S_OK then LogContinue(inttostr(bool)) else LogContinueNotifyERR
OR;
Log('Reading WPD_DEVICE_DATETIME value...');
propKeys_val.fmtid := WPD_DEVICE_DATETIME_FMTID;
propKeys_val.pid
:= WPD_DEVICE_DATETIME_PID;
h := prop_val.GetUnsignedIntegerValue(propKeys_val, ui);
if h = S_OK then LogContinue(inttostr(ui)) else LogContinueNotifyERROR
;
Log('Reading WPD_DEVICE_FRIENDLY_NAME value...');
propKeys_val.fmtid := WPD_DEVICE_FRIENDLY_NAME_FMTID;
propKeys_val.pid
:= WPD_DEVICE_FRIENDLY_NAME_PID;
h := prop_val.GetStringValue(propKeys_val, pwc);
if h = S_OK then LogContinue(pwidechar(pwc)) else LogContinueNotifyERR
OR;

//

Log('Reading WPD_DEVICE_SUPPORTED_DRM_SCHEMES value...');


propKeys_val.fmtid := WPD_DEVICE_SUPPORTED_DRM_SCHEMES_FMTID;
propKeys_val.pid
:= WPD_DEVICE_SUPPORTED_DRM_SCHEMES_PID;
h := prop_val.GetIUnknownValue(propKeys_val, s);
if h = S_OK then LogContinueNotifyOK else LogContinueNotifyERROR;
Log('Reading WPD_DEVICE_SUPPORTED_FORMATS_ARE_ORDERED value...');
propKeys_val.fmtid := WPD_DEVICE_SUPPORTED_FORMATS_ARE_ORDERED_FMTID;
propKeys_val.pid
:= WPD_DEVICE_SUPPORTED_FORMATS_ARE_ORDERED_PID;
h := prop_val.GetBoolValue(propKeys_val, bool);
if h = S_OK then LogContinue(inttostr(bool)) else LogContinueNotifyERR

OR;
Log('Reading WPD_DEVICE_TYPE value...');
propKeys_val.fmtid := WPD_DEVICE_TYPE_FMTID;
propKeys_val.pid
:= WPD_DEVICE_TYPE_PID;
h := prop_val.GetUnsignedIntegerValue(propKeys_val, ui);
if h = S_OK then LogContinue(inttostr(ui)) else LogContinueNotifyERROR
;
Log('Reading WPD_DEVICE_NETWORK_IDENTIFIER value...');
propKeys_val.fmtid := WPD_DEVICE_NETWORK_IDENTIFIER_FMTID;
propKeys_val.pid
:= WPD_DEVICE_NETWORK_IDENTIFIER_PID;
h := prop_val.GetUnsignedLargeIntegerValue(propKeys_val, ui64);
if h = S_OK then LogContinue(inttostr(ui64)) else LogContinueNotifyERR
OR;
Log('Reading WPD_DEVICE_FUNCTIONAL_UNIQUE_ID value...');
propKeys_val.fmtid := WPD_DEVICE_FUNCTIONAL_UNIQUE_ID_FMTID;
propKeys_val.pid
:= WPD_DEVICE_FUNCTIONAL_UNIQUE_ID_PID;
h := prop_val.GetBufferValue(propKeys_val, ba, bac);
if h = S_OK then LogContinue(PByte1ArrayToStr(ba, bac)) else LogContin
ueNotifyERROR;
Log('Reading WPD_DEVICE_MODEL_UNIQUE_ID value...');
propKeys_val.fmtid := WPD_DEVICE_MODEL_UNIQUE_ID_FMTID;
propKeys_val.pid
:= WPD_DEVICE_MODEL_UNIQUE_ID_PID;
h := prop_val.GetBufferValue(propKeys_val, ba, bac);
if h = S_OK then LogContinue(PByte1ArrayToStr(ba, bac)) else LogContin

ueNotifyERROR;
Log('Reading WPD_DEVICE_TRANSPORT value...');
propKeys_val.fmtid := WPD_DEVICE_TRANSPORT_FMTID;
propKeys_val.pid
:= WPD_DEVICE_TRANSPORT_PID;
h := prop_val.GetUnsignedIntegerValue(propKeys_val, ui);
if h = S_OK then LogContinue(inttostr(ui)) else LogContinueNotifyERROR
;
Log('Reading WPD_DEVICE_USE_DEVICE_STAGE value...');
propKeys_val.fmtid := WPD_DEVICE_USE_DEVICE_STAGE_FMTID;
propKeys_val.pid
:= WPD_DEVICE_USE_DEVICE_STAGE_PID;
h := prop_val.GetBoolValue(propKeys_val, bool);
if h = S_OK then LogContinue(inttostr(bool)) else LogContinueNotifyERR
OR;
end;
end;
finally
end;
end;
procedure TForm1.DeviceListClick(Sender: TObject);
var PortableDev: IPortableDevice;
begin
ConnectToDevice(DeviceIDs[DeviceList.ItemIndex], PortableDev)
end;
end.

You might also like