
quelqu'un sait comment manipuler les fichiers avec ce protocole ?
merci.
Code : Tout sélectionner
2e4a4f914950b3bcd0f56a36ad27ba16db6b250c
Code : Tout sélectionner
Interface IPortableDeviceManager Extends IUnknown
; ['{A1567595-4C2F-4574-A6FA-ECEF917B9A40}']
GetDevices(pPnPDeviceIDs,
pcPnPDeviceIDs)
RefreshDeviceList()
GetDeviceFriendlyName(pszPnPDeviceID,
pDeviceFriendlyName,
pcchDeviceFriendlyName)
GetDeviceDescription(pszPnPDeviceID,
pDeviceDescription,
pcchDeviceDescription)
GetDeviceManufacturer(pszPnPDeviceID,
pDeviceManufacturer,
pcchDeviceManufacturer)
GetDeviceProperty(pszPnPDeviceID,
pszDevicePropertyName,
pData,
pcbData,
pdwType)
GetPrivateDevices(pPnPDeviceIDs,
pcPnPDeviceIDs)
EndInterface
Macro CoInitialize()
CoInitializeEx_(0, 0)
EndMacro
Macro CoUninitialize()
CoUninitialize_()
EndMacro
Macro FAILED(hr)
hr <> 0
EndMacro
Macro SUCCEEDED(hr)
hr = 0
EndMacro
Procedure EnumerateAllDevices() ;DWORD EnumerateAllDevices()
;{
pnpDeviceIDCount.l ;DWORD pnpDeviceIDCount = 0;
deviceManager.IPortableDeviceManager;ComPtr<IPortableDeviceManager> deviceManager;
; // CoCreate the IPortableDeviceManager Interface To enumerate
; // portable devices And To get information about them.
; //<SnippetDeviceEnum1>
; HRESULT hr = CoCreateInstance(CLSID_PortableDeviceManager,
; nullptr,
; CLSCTX_INPROC_SERVER,
; IID_PPV_ARGS(&deviceManager));
hr = CoCreateInstance_(?CLSID_PortableDeviceManager,
0,
#CLSCTX_INPROC_SERVER,
?IID_IPortableDeviceManager,@deviceManager);
If (FAILED(hr)) ; If (FAILED(hr))
; {
Debug "Failed to CoCreateInstance CLSID_PortableDeviceManager"; wprintf(L"! Failed To CoCreateInstance CLSID_PortableDeviceManager, hr = 0x%lx\n", hr);
End
EndIf; }
; //</SnippetDeviceEnum1>
;
; // 1) Pass nullptr As the PWSTR Array pointer To get the total number
; // of devices found on the system.
; //<SnippetDeviceEnum2>
If (SUCCEEDED(hr)); If (SUCCEEDED(hr))
; {
hr = deviceManager\GetDevices(0, @pnpDeviceIDCount); hr = deviceManager->GetDevices(nullptr, &pnpDeviceIDCount);
If (FAILED(hr)) ;If (FAILED(hr))
; {
Debug "Failed to get number of devices on the system" ;wprintf(L"! Failed To get number of devices on the system, hr = 0x%lx\n", hr);
End
EndIf ;}
EndIf ; }
;
; // Report the number of devices found. NOTE: we will report 0, If an error
; // occured.
Debug " Windows Portable Device(s) found on the system"; wprintf(L"\n%u Windows Portable Device(s) found on the system\n\n", pnpDeviceIDCount);
; //</SnippetDeviceEnum2>
; // 2) Allocate an Array To hold the PnPDeviceID strings returned from
Debug pnpDeviceIDCount ; // the IPortableDeviceManager::GetDevices method
; //<SnippetDeviceEnum3>
If (SUCCEEDED(hr) And (pnpDeviceIDCount > 0)) ; If (SUCCEEDED(hr) && (pnpDeviceIDCount > 0))
; End
; {
Dim pnpDeviceIDs.s(pnpDeviceIDCount) ;PWSTR* pnpDeviceIDs = new (std::nothrow) PWSTR[pnpDeviceIDCount];
; If (pnpDeviceIDs != nullptr)
; {
; ZeroMemory(pnpDeviceIDs, pnpDeviceIDCount * SizeOf(PWSTR));
retrievedDeviceIDCount = pnpDeviceIDCount ; DWORD retrievedDeviceIDCount = pnpDeviceIDCount;
hr = deviceManager\GetDevices(@pnpDeviceIDs(), @retrievedDeviceIDCount);
If (SUCCEEDED(hr))
; {
; _Analysis_assume_(retrievedDeviceIDCount <= pnpDeviceIDCount);
; // For each device found, display the devices friendly name,
; // manufacturer, And description strings.
S.s{124}
sl=124
For index = 0 To retrievedDeviceIDCount -1
Debug pnpDeviceIDs(index)
deviceManager\GetDeviceFriendlyName(@pnpDeviceIDs(index),@s,@sl)
Debug S
CoTaskMemFree_(@pnpDeviceIDs(index))
Next
EndIf
EndIf
deviceManager\Release()
; }
; Else
; {
; wprintf(L"! Failed to get the device list from the system, hr = 0x%lx\n", hr);
; }
; //</SnippetDeviceEnum3>
;
; // Free all returned PnPDeviceID strings by using CoTaskMemFree.
; // NOTE: CoTaskMemFree can handle nullptr pointers, so no nullptr
; // check is needed.
; For (DWORD index = 0; index < pnpDeviceIDCount; index ++)
; {
; CoTaskMemFree(pnpDeviceIDs[index]);
; pnpDeviceIDs[index] = nullptr;
; }
;
; // Delete the Array of PWSTR pointers
; delete [] pnpDeviceIDs;
; pnpDeviceIDs = nullptr;
; }
; Else
; {
; wprintf(L"! Failed to allocate memory for PWSTR array\n");
; }
; }
ProcedureReturn pnpDeviceIDCount;
EndProcedure
CoInitialize()
EnumerateAllDevices()
CoUninitialize()
DataSection
CLSID_PortableDeviceManager:
; "{0af10cec-2ecd-4b92-9581-34f6ae0637f3}"
Data.l $0af10cec
Data.w $2ecd,$4b92
Data.b $95,$81,$34,$f6,$ae,$06,$37,$f3
IID_IPortableDeviceManager:
; "{a1567595-4c2f-4574-a6fa-ecef917b9a40}"
Data.l $a1567595
Data.w $4c2f,$4574
Data.b $a6,$fa,$ec,$ef,$91,$7b,$9a,$40
EndDataSection
Code : Tout sélectionner
Interface IPortableDeviceManager Extends IUnknown
; ['{A1567595-4C2F-4574-A6FA-ECEF917B9A40}']
GetDevices(pPnPDeviceIDs,
pcPnPDeviceIDs)
RefreshDeviceList()
GetDeviceFriendlyName(pszPnPDeviceID,
pDeviceFriendlyName,
pcchDeviceFriendlyName)
GetDeviceDescription(pszPnPDeviceID,
pDeviceDescription,
pcchDeviceDescription)
GetDeviceManufacturer(pszPnPDeviceID,
pDeviceManufacturer,
pcchDeviceManufacturer)
GetDeviceProperty(pszPnPDeviceID,
pszDevicePropertyName,
pData,
pcbData,
pdwType)
GetPrivateDevices(pPnPDeviceIDs,
pcPnPDeviceIDs)
EndInterface
Interface IPortableDevice Extends IUnknown
;{625e2df8-6392-4cf0-9ad1-3cfa5f17775c}
Open(pszPnPDeviceID,
pClientInfo)
SendCommand(dwFlags.l,
pParameters,
ppResults)
Content(ppContent)
Capabilities(ppCapabilities)
Cancel()
Close()
Advise(dwFlags.l,
pCallback,
pParameters,
ppszCookie)
Unadvise(pszCookie)
GetPnPDeviceID(ppszPnPDeviceID)
EndInterface
Macro CoInitialize()
CoInitializeEx_(0, 0)
EndMacro
Macro CoUninitialize()
CoUninitialize_()
EndMacro
Macro FAILED(hr)
hr < 0
EndMacro
Macro SUCCEEDED(hr)
hr = 0
EndMacro
Procedure.l EnumerateAllDevices()
pnpDeviceIDCount.l
deviceManager.IPortableDeviceManager
hr = CoCreateInstance_(?CLSID_PortableDeviceManager,
0,
#CLSCTX_INPROC_SERVER,
?IID_IPortableDeviceManager,@deviceManager);
If (FAILED(hr))
Debug "Failed to CoCreateInstance CLSID_PortableDeviceManager"
ProcedureReturn -1
EndIf
hr = deviceManager\GetDevices(0, @pnpDeviceIDCount)
If (FAILED(hr))
Debug "Failed to get number of devices on the system"
deviceManager\Release()
ProcedureReturn -1
EndIf
Debug " Windows Portable Device(s) found on the system n=° (" +Str(pnpDeviceIDCount)+ ")"
If pnpDeviceIDCount > 0
; pnpDeviceIDs=AllocateMemory(SizeOf(integer)*pnpDeviceIDCount)
Dim pnpDeviceIDs.i(pnpDeviceIDCount) ;
retrievedDeviceIDCount = pnpDeviceIDCount
hr = deviceManager\GetDevices(@pnpDeviceIDs(0), @retrievedDeviceIDCount);
If (SUCCEEDED(hr))
S.s{124}
sl=124
For index = 0 To retrievedDeviceIDCount -1
Debug "ID: " + PeekS(pnpDeviceIDs(index))
deviceManager\GetDeviceFriendlyName(pnpDeviceIDs(index),@s,@sl)
Debug S
S="":sl=124
deviceManager\GetDeviceDescription(pnpDeviceIDs(index),@s,@sl)
Debug S
S="":sl=124
deviceManager\GetDeviceManufacturer(pnpDeviceIDs(index),@s,@sl)
Debug S
CoTaskMemFree_(pnpDeviceIDs(index))
Next
EndIf
EndIf
deviceManager\Release()
ProcedureReturn pnpDeviceIDCount
EndProcedure
CoInitialize()
Debug EnumerateAllDevices()
CoUninitialize()
DataSection
CLSID_PortableDeviceManager:
; "{0af10cec-2ecd-4b92-9581-34f6ae0637f3}"
Data.l $0af10cec
Data.w $2ecd,$4b92
Data.b $95,$81,$34,$f6,$ae,$06,$37,$f3
IID_IPortableDeviceManager:
; "{a1567595-4c2f-4574-a6fa-ecef917b9a40}"
Data.l $a1567595
Data.w $4c2f,$4574
Data.b $a6,$fa,$ec,$ef,$91,$7b,$9a,$40
CLSID_PortableDeviceFTM:
; "{f7c0039a-4762-488a-b4b3-760ef9a1ba9b}"
Data.l $f7c0039a
Data.w $4762,$488a
Data.b $b4,$b3,$76,$0e,$f9,$a1,$ba,$9b
IID_IPortableDevice:
; "{625e2df8-6392-4cf0-9ad1-3cfa5f17775c}"
Data.l $625e2df8
Data.w $6392,$4cf0
Data.b $9a,$d1,$3c,$fa,$5f,$17,$77,$5c
EndDataSection
C'est rigolo que les DD externes USB portables ne soient pas pris en compte comme portableWindows Portable Device(s) found on the system n=° (1)
ID: \\?\wpdbusenumroot#umb#2&37c186b&0&storage#volume#_??_usbstor#disk&ven_kingston&prod_datatraveler_g2&rev_1.00#001cc0ec3504f050a7da126d&0##{6ac27878-a6fa-4155-ba85-f98f491d4f33}
E:\
DataTraveler G2
Kingston
1
Code : Tout sélectionner
Interface IPortableDeviceManager Extends IUnknown
;'{A1567595-4C2F-4574-A6FA-ECEF917B9A40}'
GetDevices(pPnPDeviceIDs,
pcPnPDeviceIDs)
RefreshDeviceList()
GetDeviceFriendlyName(pszPnPDeviceID,
pDeviceFriendlyName,
pcchDeviceFriendlyName)
GetDeviceDescription(pszPnPDeviceID,
pDeviceDescription,
pcchDeviceDescription)
GetDeviceManufacturer(pszPnPDeviceID,
pDeviceManufacturer,
pcchDeviceManufacturer)
GetDeviceProperty(pszPnPDeviceID,
pszDevicePropertyName,
pData,
pcbData,
pdwType)
GetPrivateDevices(pPnPDeviceIDs,
pcPnPDeviceIDs)
EndInterface
Interface IPortableDevice Extends IUnknown
;{625e2df8-6392-4cf0-9ad1-3cfa5f17775c}
Open(pszPnPDeviceID,
pClientInfo)
SendCommand(dwFlags.l,
pParameters,
ppResults)
Content(ppContent)
Capabilities(ppCapabilities)
Cancel()
Close()
Advise(dwFlags.l,
pCallback,
pParameters,
ppszCookie)
Unadvise(pszCookie)
GetPnPDeviceID(ppszPnPDeviceID)
EndInterface
Interface IPortableDeviceValues Extends IUnknown
;"6848f6f2-3155-4f86-b6f5-263eeeab3143"
GetCount(pcelt)
GetAt(index.l,
pKey,
pValue)
SetValue(key,
pValue)
GetValue(key,
pValue)
SetStringValue(key,
LPCWSTRValue)
GetStringValue(key,
pLPWSTRValue)
SetUnsignedIntegerValue(key,
LongValue.l)
GetUnsignedIntegerValue(key,
pLongValue)
SetSignedIntegerValue(key,
LongValue.l)
GetSignedIntegerValue(key,
pLongValue)
SetUnsignedLargeIntegerValue(key,
QuadValue.q)
GetUnsignedLargeIntegerValue(key,
pQuadValue)
SetSignedLargeIntegerValue(key,
QuadValue.q)
GetSignedLargeIntegerValue(key,
pQuadValue)
SetFloatValue(key,
FLOATValue.f)
GetFloatValue(key,
pFLOATpValue)
SetErrorValue(key,
HRESULTLongValue.l)
GetErrorValue(key,
pHRESULTLongValue)
SetKeyValue(key,
REFPROPERTYKEYValue)
GetKeyValue(key,
pPROPERTYKEYValue)
SetBoolValue(key,
BOOLLongValue)
GetBoolValue(key,
pBOOLLongValue)
SetIUnknownValue(key,
pIUnknownValue)
GetIUnknownValue(key,
ppIUnknownValue)
SetGuidValue(key,
REFGUIDValue)
GetGuidValue(key,
pGUIDValue)
SetBufferValue(key,
pValue,
cbValue.l)
GetBufferValue(key,
ppValue,
pcbValue)
SetIPortableDeviceValuesValue(key,
pValue)
GetIPortableDeviceValuesValue(key,
ppValue)
SetIPortableDevicePropVariantCollectionValue(key,
pValue)
GetIPortableDevicePropVariantCollectionValue(key,
ppValue)
SetIPortableDeviceKeyCollectionValue(key,
pValue)
GetIPortableDeviceKeyCollectionValue(key,
ppValue)
SetIPortableDeviceValuesCollectionValue(key,
pValue)
GetIPortableDeviceValuesCollectionValue(key,
ppValue)
RemoveValue(key)
CopyValuesFromPropertyStore(pStore)
CopyValuesToPropertyStore(pStore)
Clear()
EndInterface
Macro CoInitialize()
CoInitializeEx_(0, 0)
EndMacro
Macro CoUninitialize()
CoUninitialize_()
EndMacro
Macro FAILED(hr)
hr < 0
EndMacro
Macro SUCCEEDED(hr)
hr = 0
EndMacro
Macro Guillemet
"
EndMacro
Macro DEFINE_PROPERTYKEY(Nm,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12)
Nm:
Data.l p1
Data.w p2,p3
Data.b p4,p5,p6,p7,p8,p9,p10,p11,p12
EndMacro
Global CLIENT_NAME.s="WPD Sample Application"
Global CLIENT_MAJOR_VER=1
Global CLIENT_MINOR_VER=0
Global CLIENT_REVISION=2
Procedure.l EnumerateAllDevices(List ListDevisId.s())
pnpDeviceIDCount.l
deviceManager.IPortableDeviceManager
hr = CoCreateInstance_(?CLSID_PortableDeviceManager,
0,
#CLSCTX_INPROC_SERVER,
?IID_IPortableDeviceManager,@deviceManager);
If (FAILED(hr))
Debug "Failed to CoCreateInstance CLSID_PortableDeviceManager"
ProcedureReturn -1
EndIf
hr = deviceManager\GetDevices(0, @pnpDeviceIDCount)
If (FAILED(hr))
Debug "Failed to get number of devices on the system"
deviceManager\Release()
ProcedureReturn -1
EndIf
Debug " Windows Portable Device(s) found on the system n=° (" +Str(pnpDeviceIDCount)+ ")"
If pnpDeviceIDCount > 0
; pnpDeviceIDs=AllocateMemory(SizeOf(integer)*pnpDeviceIDCount)
Dim pnpDeviceIDs.i(pnpDeviceIDCount) ;
retrievedDeviceIDCount = pnpDeviceIDCount
hr = deviceManager\GetDevices(@pnpDeviceIDs(0), @retrievedDeviceIDCount);
If (SUCCEEDED(hr))
S.s{124}
sl=124
For index = 0 To retrievedDeviceIDCount -1
AddElement(ListDevisId())
ListDevisId()=PeekS(pnpDeviceIDs(index))
Debug "ID: " + ListDevisId()
deviceManager\GetDeviceFriendlyName(pnpDeviceIDs(index),@s,@sl)
Debug S
S="":sl=124
deviceManager\GetDeviceDescription(pnpDeviceIDs(index),@s,@sl)
Debug S
S="":sl=124
deviceManager\GetDeviceManufacturer(pnpDeviceIDs(index),@s,@sl)
Debug S
CoTaskMemFree_(pnpDeviceIDs(index))
Next
EndIf
EndIf
deviceManager\Release()
ProcedureReturn pnpDeviceIDCount
EndProcedure
Procedure ChooseDevice()
clientInformation.IPortableDeviceValues
device.IPortableDevice
NewList ListDevisId.s()
If EnumerateAllDevices(ListDevisId()) > 0
FirstElement(ListDevisId())
hr = CoCreateInstance_(?CLSID_PortableDeviceValues,
0,
#CLSCTX_INPROC_SERVER,
?IID_IPortableDeviceValues, @clientInformation);
If (SUCCEEDED(hr))
hr = clientInformation\SetStringValue(?WPD_CLIENT_NAME, @CLIENT_NAME);
If (FAILED(hr))
Debug "! Failed to set WPD_CLIENT_NAME"
EndIf
hr = clientInformation\SetUnsignedIntegerValue(?WPD_CLIENT_MAJOR_VERSION, CLIENT_MAJOR_VER);
If (FAILED(hr))
Debug "! Failed to set WPD_CLIENT_MAJOR_VERSION"
EndIf
hr = clientInformation\SetUnsignedIntegerValue(?WPD_CLIENT_MINOR_VERSION, CLIENT_MINOR_VER);
If (FAILED(hr))
Debug "! Failed to set WPD_CLIENT_MINOR_VERSION"
EndIf
hr = clientInformation\SetUnsignedIntegerValue(?WPD_CLIENT_REVISION, CLIENT_REVISION);
If (FAILED(hr))
Debug "! Failed to set WPD_CLIENT_REVISION"
EndIf
hr = clientInformation\SetUnsignedIntegerValue(?WPD_CLIENT_SECURITY_QUALITY_OF_SERVICE, SECURITY_IMPERSONATION);
If (FAILED(hr))
Debug "! Failed to set WPD_CLIENT_SECURITY_QUALITY_OF_SERVICE"
EndIf
hr = CoCreateInstance_(?CLSID_PortableDeviceFTM,
0,
#CLSCTX_INPROC_SERVER,
?IID_IPortableDevice,@device)
If (SUCCEEDED(hr))
Did.s{124}= ListDevisId()
hr = device\Open(@Did,clientInformation)
; #define E_ACCESSDENIED ((HRESULT)0x80070005L)
If hr = $80070005
clientInformation\SetUnsignedIntegerValue(?WPD_CLIENT_DESIRED_ACCESS, #GENERIC_READ)
hr = device\Open(@Did,clientInformation)
EndIf
If (FAILED(hr))
Debug "! Failed to Open the device"
Else
;To be continued ;)
Debug "- The device successfully opened"
EndIf
device\Release();
Else
Debug "! Failed to CoCreateInstance CLSID_PortableDeviceFTM"
EndIf
clientInformation\Release()
Else
Debug "! Failed to CoCreateInstance CLSID_PortableDeviceValues"
EndIf
EndIf
EndProcedure
CoInitialize()
ChooseDevice()
CoUninitialize()
DataSection
CLSID_PortableDeviceManager:
; "{0af10cec-2ecd-4b92-9581-34f6ae0637f3}"
Data.l $0af10cec
Data.w $2ecd,$4b92
Data.b $95,$81,$34,$f6,$ae,$06,$37,$f3
IID_IPortableDeviceManager:
; "{a1567595-4c2f-4574-a6fa-ecef917b9a40}"
Data.l $a1567595
Data.w $4c2f,$4574
Data.b $a6,$fa,$ec,$ef,$91,$7b,$9a,$40
CLSID_PortableDeviceFTM:
; "{f7c0039a-4762-488a-b4b3-760ef9a1ba9b}"
Data.l $f7c0039a
Data.w $4762,$488a
Data.b $b4,$b3,$76,$0e,$f9,$a1,$ba,$9b
IID_IPortableDevice:
; "{625e2df8-6392-4cf0-9ad1-3cfa5f17775c}"
Data.l $625e2df8
Data.w $6392,$4cf0
Data.b $9a,$d1,$3c,$fa,$5f,$17,$77,$5c
CLSID_PortableDeviceValues:
;"0c15d503-d017-47ce-9016-7b3f978721cc"
Data.l $0c15d503
Data.w $d017,$47ce
Data.b $90,$16,$7b,$3f,$97,$87,$21,$cc
IID_IPortableDeviceValues:
;"6848f6f2-3155-4f86-b6f5-263eeeab3143"
Data.l $6848f6f2
Data.w $3155,$4f86
Data.b $b6,$f5,$26,$3e,$ee,$ab,$31,$43
DEFINE_PROPERTYKEY( WPD_CLIENT_NAME , $204D9F0C, $2292, $4080, $9F, $42, $40, $66, $4E, $70, $F8, $59 , 2 );
DEFINE_PROPERTYKEY( WPD_CLIENT_MAJOR_VERSION , $204D9F0C, $2292, $4080, $9F, $42, $40, $66, $4E, $70, $F8, $59 , 3 );
DEFINE_PROPERTYKEY( WPD_CLIENT_MINOR_VERSION , $204D9F0C, $2292, $4080, $9F, $42, $40, $66, $4E, $70, $F8, $59 , 4 );
DEFINE_PROPERTYKEY( WPD_CLIENT_REVISION , $204D9F0C, $2292, $4080, $9F, $42, $40, $66, $4E, $70, $F8, $59 , 5 );
DEFINE_PROPERTYKEY( WPD_CLIENT_SECURITY_QUALITY_OF_SERVICE , $204D9F0C, $2292, $4080, $9F, $42, $40, $66, $4E, $70, $F8, $59 , 8 );
DEFINE_PROPERTYKEY( WPD_CLIENT_DESIRED_ACCESS , $204D9F0C, $2292, $4080, $9F, $42, $40, $66, $4E, $70, $F8, $59 , 9 );
EndDataSection
Tu n'es pas habilité à être désoléCeltic88 a écrit :une petite mise à jour , dsl je trouve plu l'temps pour programmer
Code : Tout sélectionner
Interface IPortableDeviceManager Extends IUnknown
;'{A1567595-4C2F-4574-A6FA-ECEF917B9A40}'
GetDevices(pPnPDeviceIDs,
pcPnPDeviceIDs)
RefreshDeviceList()
GetDeviceFriendlyName(pszPnPDeviceID,
pDeviceFriendlyName,
pcchDeviceFriendlyName)
GetDeviceDescription(pszPnPDeviceID,
pDeviceDescription,
pcchDeviceDescription)
GetDeviceManufacturer(pszPnPDeviceID,
pDeviceManufacturer,
pcchDeviceManufacturer)
GetDeviceProperty(pszPnPDeviceID,
pszDevicePropertyName,
pData,
pcbData,
pdwType)
GetPrivateDevices(pPnPDeviceIDs,
pcPnPDeviceIDs)
EndInterface
Interface IPortableDevice Extends IUnknown
;{625e2df8-6392-4cf0-9ad1-3cfa5f17775c}
Open(pszPnPDeviceID,
pClientInfo)
SendCommand(dwFlags.l,
pParameters,
ppResults)
Content(ppContent)
Capabilities(ppCapabilities)
Cancel()
Close()
Advise(dwFlags.l,
pCallback,
pParameters,
ppszCookie)
Unadvise(pszCookie)
GetPnPDeviceID(ppszPnPDeviceID)
EndInterface
Interface IPortableDeviceValues Extends IUnknown
;"6848f6f2-3155-4f86-b6f5-263eeeab3143"
GetCount(pcelt)
GetAt(index.l,
pKey,
pValue)
SetValue(key,
pValue)
GetValue(key,
pValue)
SetStringValue(key,
LPCWSTRValue)
GetStringValue(key,
pLPWSTRValue)
SetUnsignedIntegerValue(key,
LongValue.l)
GetUnsignedIntegerValue(key,
pLongValue)
SetSignedIntegerValue(key,
LongValue.l)
GetSignedIntegerValue(key,
pLongValue)
SetUnsignedLargeIntegerValue(key,
QuadValue.q)
GetUnsignedLargeIntegerValue(key,
pQuadValue)
SetSignedLargeIntegerValue(key,
QuadValue.q)
GetSignedLargeIntegerValue(key,
pQuadValue)
SetFloatValue(key,
FLOATValue.f)
GetFloatValue(key,
pFLOATpValue)
SetErrorValue(key,
HRESULTLongValue.l)
GetErrorValue(key,
pHRESULTLongValue)
SetKeyValue(key,
REFPROPERTYKEYValue)
GetKeyValue(key,
pPROPERTYKEYValue)
SetBoolValue(key,
BOOLLongValue)
GetBoolValue(key,
pBOOLLongValue)
SetIUnknownValue(key,
pIUnknownValue)
GetIUnknownValue(key,
ppIUnknownValue)
SetGuidValue(key,
REFGUIDValue)
GetGuidValue(key,
pGUIDValue)
SetBufferValue(key,
pValue,
cbValue.l)
GetBufferValue(key,
ppValue,
pcbValue)
SetIPortableDeviceValuesValue(key,
pValue)
GetIPortableDeviceValuesValue(key,
ppValue)
SetIPortableDevicePropVariantCollectionValue(key,
pValue)
GetIPortableDevicePropVariantCollectionValue(key,
ppValue)
SetIPortableDeviceKeyCollectionValue(key,
pValue)
GetIPortableDeviceKeyCollectionValue(key,
ppValue)
SetIPortableDeviceValuesCollectionValue(key,
pValue)
GetIPortableDeviceValuesCollectionValue(key,
ppValue)
RemoveValue(key)
CopyValuesFromPropertyStore(pStore)
CopyValuesToPropertyStore(pStore)
Clear()
EndInterface
Interface IPortableDeviceContent Extends IUnknown
;6a96ed84-7c73-4480-9938-bf5af477d426
EnumObjects(dwFlags.l,
pszParentObjectID,
pFilter,
ppEnum)
Properties(ppProperties)
Transfer(ppResources)
CreateObjectWithPropertiesOnly(pValues,
ppszObjectID)
CreateObjectWithPropertiesAndData(pValues,
ppData,
pdwOptimalWriteBufferSize,
ppszCookie)
Delete(dwOptions.l,
pObjectIDs,
ppResults)
GetObjectIDsFromPersistentUniqueIDs(pPersistentUniqueIDs,
ppObjectIDs)
Cancel()
Move(pObjectIDs,
pszDestinationFolderObjectID,
ppResults)
Copy(pObjectIDs,
pszDestinationFolderObjectID,
ppResults)
EndInterface
Interface IEnumPortableDeviceObjectIDs Extends IUnknown
;10ece955-cf41-4728-bfa0-41eedf1bbf19
Next(cObjects.l,
pObjIDs,
pcFetched)
Skip(cObjects.l)
Reset()
Clone(ppEnum)
Cancel()
EndInterface
Interface IPortableDeviceProperties Extends IUnknown
;"7f6d695c-03df-4439-a809-59266beee3a6"
GetSupportedProperties(pszObjectID,
ppKeys)
GetPropertyAttributes(pszObjectID,
Key,
ppAttributes)
GetValues(pszObjectID,
pKeys,
ppValues)
SetValues(pszObjectID,
pValues,
ppResults)
Delete(pszObjectID,
pKeys)
Cancel()
EndInterface
Interface IPortableDeviceKeyCollection Extends IUnknown
;"dada2357-e0ad-492e-98db-dd61c53ba353"
GetCount(pcElems)
GetAt(dwIndex.l,
pKey)
Add(Key)
Clear()
RemoveAt(dwIndex.l)
EndInterface
Macro CoInitialize()
CoInitializeEx_(0, 0)
EndMacro
Macro CoUninitialize()
CoUninitialize_()
EndMacro
Macro FAILED(hr)
hr < 0
EndMacro
Macro SUCCEEDED(hr)
hr = 0
EndMacro
Macro DEFINE_PROPERTYKEY(Nm,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12)
Nm:
Data.l p1
Data.w p2,p3
Data.b p4,p5,p6,p7,p8,p9,p10,p11,p12
EndMacro
Macro DEFINE_DEVSVCPROPKEY(Nm,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12)
DEFINE_PROPERTYKEY(Nm,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12)
EndMacro
Macro DEFINE_GUID(IID, Data1, Data2, Data3, Data4, Data5, Data6, Data7, Data8, Data9, Data10, Data11)
IID:
Data.l Data1
Data.w Data2, Data3
Data.b Data4, Data5, Data6, Data7, Data8, Data9, Data10, Data11
EndMacro
Macro CompareGuid(Guid1,Guid2)
CompareMemory(Guid1,Guid2,SizeOf(Guid)) > 0
EndMacro
Global CLIENT_NAME.s="WPD Sample Application"
Global CLIENT_MAJOR_VER=1
Global CLIENT_MINOR_VER=0
Global CLIENT_REVISION=2
Global WPD_DEVICE_OBJECT_ID.s = "DEVICE"
Global NUM_OBJECTS_TO_REQUEST=10
Procedure.l EnumerateAllDevices(List ListDevisId.s())
pnpDeviceIDCount.l
deviceManager.IPortableDeviceManager
hr = CoCreateInstance_(?CLSID_PortableDeviceManager,
0,
#CLSCTX_INPROC_SERVER,
?IID_IPortableDeviceManager,@deviceManager);
If (FAILED(hr))
Debug "Failed to CoCreateInstance CLSID_PortableDeviceManager"
ProcedureReturn -1
EndIf
hr = deviceManager\GetDevices(0, @pnpDeviceIDCount)
If (FAILED(hr))
Debug "Failed to get number of devices on the system"
deviceManager\Release()
ProcedureReturn -1
EndIf
Debug " Windows Portable Device(s) found on the system n=° (" +Str(pnpDeviceIDCount)+ ")"
If pnpDeviceIDCount > 0
; pnpDeviceIDs=AllocateMemory(SizeOf(integer)*pnpDeviceIDCount)
Dim pnpDeviceIDs.i(pnpDeviceIDCount) ;
retrievedDeviceIDCount = pnpDeviceIDCount
hr = deviceManager\GetDevices(@pnpDeviceIDs(0), @retrievedDeviceIDCount);
If (SUCCEEDED(hr))
S.s{124}
sl=124
For index = 0 To retrievedDeviceIDCount -1
AddElement(ListDevisId())
ListDevisId()=PeekS(pnpDeviceIDs(index))
Debug "ID: " + ListDevisId()
deviceManager\GetDeviceFriendlyName(pnpDeviceIDs(index),@s,@sl)
Debug S
S="":sl=124
deviceManager\GetDeviceDescription(pnpDeviceIDs(index),@s,@sl)
Debug S
S="":sl=124
deviceManager\GetDeviceManufacturer(pnpDeviceIDs(index),@s,@sl)
Debug S
CoTaskMemFree_(pnpDeviceIDs(index))
Next
EndIf
EndIf
deviceManager\Release()
ProcedureReturn pnpDeviceIDCount
EndProcedure
Procedure GetClientInformation()
clientInformation.IPortableDeviceValues
hr = CoCreateInstance_(?CLSID_PortableDeviceValues,
0,
#CLSCTX_INPROC_SERVER,
?IID_IPortableDeviceValues, @clientInformation);
If (SUCCEEDED(hr))
hr = clientInformation\SetStringValue(?WPD_CLIENT_NAME, @CLIENT_NAME);
If (FAILED(hr))
Debug "! Failed to set WPD_CLIENT_NAME"
ProcedureReturn -1
EndIf
hr = clientInformation\SetUnsignedIntegerValue(?WPD_CLIENT_MAJOR_VERSION, CLIENT_MAJOR_VER);
If (FAILED(hr))
Debug "! Failed to set WPD_CLIENT_MAJOR_VERSION"
EndIf
hr = clientInformation\SetUnsignedIntegerValue(?WPD_CLIENT_MINOR_VERSION, CLIENT_MINOR_VER);
If (FAILED(hr))
Debug "! Failed to set WPD_CLIENT_MINOR_VERSION"
EndIf
hr = clientInformation\SetUnsignedIntegerValue(?WPD_CLIENT_REVISION, CLIENT_REVISION);
If (FAILED(hr))
Debug "! Failed to set WPD_CLIENT_REVISION"
EndIf
hr = clientInformation\SetUnsignedIntegerValue(?WPD_CLIENT_SECURITY_QUALITY_OF_SERVICE, SECURITY_IMPERSONATION);
If (FAILED(hr))
Debug "! Failed to set WPD_CLIENT_SECURITY_QUALITY_OF_SERVICE"
EndIf
ProcedureReturn clientInformation
Else
Debug "! Failed to CoCreateInstance CLSID_PortableDeviceValues"
EndIf
EndProcedure
Procedure WrapObject(properties.IPortableDeviceProperties , objectId)
keys.IPortableDeviceKeyCollection ;
Debug properties\GetSupportedProperties(objectId, @keys);
values.IPortableDeviceValues ;
Debug properties\GetValues(objectId, keys, @values);
name.i;
Debug Hex(values\GetStringValue(?PKEY_GenericObj_Name, @name))
Debug name
; CallDebugger
contentType.Guid;
values\GetGuidValue(?WPD_OBJECT_CONTENT_TYPE, @contentType);
folderType = ?WPD_CONTENT_TYPE_FOLDER
functionalType = ?WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT
If CompareGuid(contentType,folderType) Or CompareGuid(contentType,functionalType)
Debug "IS dir"
Else
Debug "IS file"
EndIf
EndProcedure
Procedure RecursiveEnumerate(objectID, content.IPortableDeviceContent)
properties.IPortableDeviceProperties
enumObjectIDs.IEnumPortableDeviceObjectIDs
content\Properties(@properties)
hr = content\EnumObjects(0,
objectID,
0,
@enumObjectIDs);
If (FAILED(hr))
Debug "! Failed to get IEnumPortableDeviceObjectIDs from IPortableDeviceContent"
Else
Repeat
numFetched.l = 0;
objectIDi.i
hr = enumObjectIDs\Next(1,
@objectIDi,
@numFetched);
If numFetched > 0
Debug PeekS(objectIDi)
; CallDebugger
WrapObject(properties , objectIDi)
RecursiveEnumerate(objectIDi, content);
CoTaskMemFree_(objectIDi) ;
EndIf
Until numFetched=0
enumObjectIDs\Release()
EndIf
EndProcedure
Procedure EnumerateAllContent(device.IPortableDevice)
content.IPortableDeviceContent
hr= device\Content(@content)
If (FAILED(hr))
Debug "! Failed to get IPortableDeviceContent from IPortableDevice"
Else
RecursiveEnumerate(@WPD_DEVICE_OBJECT_ID, content)
content\Release()
EndIf
EndProcedure
Procedure ChooseDevice(nDevis)
clientInformation.IPortableDeviceValues
device.IPortableDevice
NewList ListDevisId.s()
If EnumerateAllDevices(ListDevisId()) > 0
ForEach ListDevisId()
If ListIndex(ListDevisId()) = nDevis
Break
EndIf
Next
clientInformation = GetClientInformation()
If clientInformation
hr = CoCreateInstance_(?CLSID_PortableDeviceFTM,
0,
#CLSCTX_INPROC_SERVER,
?IID_IPortableDevice,@device)
If (SUCCEEDED(hr))
Did.s{124}= ListDevisId()
hr = device\Open(@Did,clientInformation)
; #define E_ACCESSDENIED ((HRESULT)0x80070005L)
If hr = $80070005
clientInformation\SetUnsignedIntegerValue(?WPD_CLIENT_DESIRED_ACCESS, #GENERIC_READ)
hr = device\Open(@Did,clientInformation)
EndIf
clientInformation\Release()
clientInformation=0
If (FAILED(hr))
Debug "! Failed to Open the device"
Else
;To be continued ;)
Debug "- The device successfully opened"
ProcedureReturn device
EndIf
device\Release();
Else
Debug "! Failed to CoCreateInstance CLSID_PortableDeviceFTM"
EndIf
If clientInformation
clientInformation\Release()
EndIf
Else
Debug "! Failed to CoCreateInstance CLSID_PortableDeviceValues"
EndIf
EndIf
EndProcedure
CoInitialize()
device.IPortableDevice=ChooseDevice(0)
If device
EnumerateAllContent(device)
EndIf
CoUninitialize()
DataSection
CLSID_PortableDeviceManager:
; "{0af10cec-2ecd-4b92-9581-34f6ae0637f3}"
Data.l $0af10cec
Data.w $2ecd,$4b92
Data.b $95,$81,$34,$f6,$ae,$06,$37,$f3
IID_IPortableDeviceManager:
; "{a1567595-4c2f-4574-a6fa-ecef917b9a40}"
Data.l $a1567595
Data.w $4c2f,$4574
Data.b $a6,$fa,$ec,$ef,$91,$7b,$9a,$40
CLSID_PortableDeviceFTM:
; "{f7c0039a-4762-488a-b4b3-760ef9a1ba9b}"
Data.l $f7c0039a
Data.w $4762,$488a
Data.b $b4,$b3,$76,$0e,$f9,$a1,$ba,$9b
IID_IPortableDevice:
; "{625e2df8-6392-4cf0-9ad1-3cfa5f17775c}"
Data.l $625e2df8
Data.w $6392,$4cf0
Data.b $9a,$d1,$3c,$fa,$5f,$17,$77,$5c
CLSID_PortableDeviceValues:
;"0c15d503-d017-47ce-9016-7b3f978721cc"
Data.l $0c15d503
Data.w $d017,$47ce
Data.b $90,$16,$7b,$3f,$97,$87,$21,$cc
IID_IPortableDeviceValues:
;"6848f6f2-3155-4f86-b6f5-263eeeab3143"
Data.l $6848f6f2
Data.w $3155,$4f86
Data.b $b6,$f5,$26,$3e,$ee,$ab,$31,$43
; IID_IPortableDeviceContent
; ;6a96ed84-7c73-4480-9938-bf5af477d426
; Data.l $6a96ed84
; Data.w $7c73,$4480
; Data.b $99,$38,$bf,$5a,$f4,$77,$d4,$26
DEFINE_PROPERTYKEY( WPD_CLIENT_NAME , $204D9F0C, $2292, $4080, $9F, $42, $40, $66, $4E, $70, $F8, $59 , 2 );
DEFINE_PROPERTYKEY( WPD_CLIENT_MAJOR_VERSION , $204D9F0C, $2292, $4080, $9F, $42, $40, $66, $4E, $70, $F8, $59 , 3 );
DEFINE_PROPERTYKEY( WPD_CLIENT_MINOR_VERSION , $204D9F0C, $2292, $4080, $9F, $42, $40, $66, $4E, $70, $F8, $59 , 4 );
DEFINE_PROPERTYKEY( WPD_CLIENT_REVISION , $204D9F0C, $2292, $4080, $9F, $42, $40, $66, $4E, $70, $F8, $59 , 5 );
DEFINE_PROPERTYKEY( WPD_CLIENT_SECURITY_QUALITY_OF_SERVICE , $204D9F0C, $2292, $4080, $9F, $42, $40, $66, $4E, $70, $F8, $59 , 8 );
DEFINE_PROPERTYKEY( WPD_CLIENT_DESIRED_ACCESS , $204D9F0C, $2292, $4080, $9F, $42, $40, $66, $4E, $70, $F8, $59 , 9 );
DEFINE_PROPERTYKEY( WPD_OBJECT_CONTENT_TYPE , $EF6B490D, $5CD8, $437A, $AF, $FC, $DA, $8B, $60, $EE, $4A, $3C , 7 );
DEFINE_DEVSVCPROPKEY(PKEY_GenericObj_Name,$EF6B490D, $5CD8, $437A, $AF, $FC, $DA, $8B, $60, $EE, $4A, $3C, 4);
DEFINE_GUID(WPD_CONTENT_TYPE_FOLDER, $27E2E392, $A111, $48E0, $AB, $0C, $E1, $77, $05, $A0, $5F, $85 );
DEFINE_GUID(WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT, $99ED0160, $17FF, $4C44, $9D, $98, $1D, $7A, $6F, $94, $19, $21 )
EndDataSection