using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Vanara.InteropServices;
using static Vanara.PInvoke.Ole32;
using static Vanara.PInvoke.PropSys;
namespace Vanara.PInvoke
{
public static partial class PortableDeviceApi
{
///
/// The WPD_STREAM_UNITS enumeration specifies the unit types to be used for IPortableDeviceUnitsStream operations.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/wpd-stream-units typedef enum _WPD_STREAM_UNITS { WPD_STREAM_UNITS_BYTES =
// 0, WPD_STREAM_UNITS_FRAMES = 1, WPD_STREAM_UNITS_ROWS = 2, WPD_STREAM_UNITS_MILLISECONDS = 3, WPD_STREAM_UNITS_MICROSECONDS = 4 } WPD_STREAM_UNITS;
[PInvokeData("portabldevicetypes.h")]
public enum WPD_STREAM_UNITS
{
/// The stream units are specified in bytes.
WPD_STREAM_UNITS_BYTES = 0,
/// The stream units are specified in frames.
WPD_STREAM_UNITS_FRAMES = 1,
/// The stream units are specified in rows.
WPD_STREAM_UNITS_ROWS = 2,
/// The stream units are specified in milliseconds.
WPD_STREAM_UNITS_MILLISECONDS = 4,
/// The stream units are specified in microseconds.
WPD_STREAM_UNITS_MICROSECONDS = 8,
}
///
/// The IPortableDeviceKeyCollection interface holds a collection of PROPERTYKEY values. This interface can be
/// retrieved from a method or, if a new object is required, call CoCreate with CLSID_PortableDeviceKeyCollection.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicekeycollection
[PInvokeData("portabldevicetypes.h")]
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("DADA2357-E0AD-492E-98DB-DD61C53BA353"), CoClass(typeof(PortableDeviceKeyCollection))]
public interface IPortableDeviceKeyCollection
{
/// The GetCount method retrieves the number of keys in this collection.
/// A DWORD that contains the number of keys in the collection.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicekeycollection-getcount HRESULT GetCount( [in] DWORD
// *pcElems );
uint GetCount();
/// The GetAt method retrieves a PROPERTYKEY from the collection by index.
/// DWORD that contains the index of the key to be retrieved.
/// A PROPERTYKEY object.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicekeycollection-getat HRESULT GetAt( [in] const DWORD
// dwIndex, [out] PROPERTYKEY *pKey );
PROPERTYKEY GetAt([In] uint dwIndex);
/// The Add method adds a property key to the collection.
///
/// A REFPROPERTYKEY to add to the collection. This method copies the key to the collection, so you can release the local
/// variable after calling this method.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicekeycollection-add HRESULT Add( [in] REFPROPERTYKEY Key );
void Add(in PROPERTYKEY Key);
/// Deletes all items from the collection.
/// None.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/portabledevicetypes/nf-portabledevicetypes-iportabledevicekeycollection-clear
// HRESULT Clear();
void Clear();
/// The RemoveAt method removes the element stored at the location specified by the given index.
/// Specifies the index of the element to be removed.
/// You must specify a zero-based index.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicekeycollection-removeat HRESULT RemoveAt( [in] const
// DWORD dwIndex );
void RemoveAt([In] uint dwIndex);
}
///
///
/// The IPortableDevicePropVariantCollection interface holds a collection of indexed PROPVARIANT values of the same
/// VARTYPE. The VARTYPE of the first item that is added to the collection determines the VARTYPE of the collection. An attempt to
/// add an item of a different VARTYPE may fail if the PROPVARIANT value cannot be changed to the collection's current
/// VARTYPE. To change the VARTYPE of the collection, call ChangeType.
///
/// This interface can be retrieved from a method or, if a new object is required, call CoCreate with CLSID_PortableDevicePropVariantCollection.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicepropvariantcollection
[PInvokeData("portabldevicetypes.h")]
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("89B2E422-4F1B-4316-BCEF-A44AFEA83EB3"), CoClass(typeof(PortableDevicePropVariantCollection))]
public interface IPortableDevicePropVariantCollection
{
/// The GetCount method retrieves the number of items in this collection.
/// The number of items in the collection.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicepropvariantcollection-getcount HRESULT GetCount( [in]
// DWORD *pcElems );
uint GetCount();
/// The GetAt method retrieves an item from the collection by a zero-based index.
/// DWORD that contains the zero-based index of the item to retrieve.
/// A PROPVARIANT structure. The caller is responsible for freeing this memory by calling PropVariantClear.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicepropvariantcollection-getat HRESULT GetAt( [in] const
// DWORD dwIndex, [out] PROPVARIANT *pValue );
void GetAt([In] uint dwIndex, [Out] PROPVARIANT pValue);
/// The Add method adds an item to the collection.
///
/// A new PROPVARIANT object to add to the collection. This method copies the PROPVARIANT to the collection, so
/// you should release your local copy of the variable by calling PropVariantClear after calling this method.
///
///
///
/// When the VARTYPE for pValue is VT_VECTOR or VT_UI1, setting and retrieving a NULL or zero-sized buffer is not
/// supported. For example, neither pValue.caub.pElems = NULL nor pValue.caub.cElems = 0 are allowed.
///
///
/// If a caller tries to add an item of a different VARTYPE contained in the collection and the PROPVARIANT value cannot be
/// changed by this interface automatically, this method will fail. To change the collection type manually, call IPortableDevicePropVariantCollection::ChangeType.
///
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicepropvariantcollection-add HRESULT Add( [in] const
// PROPVARIANT *pValue );
void Add([In] PROPVARIANT pValue);
/// The GetType method retrieves the data type of the items in the collection.
/// A Platform SDK VARTYPE enumeration value that indicates the data type of all the items in the collection.
/// All items that are stored in an IPortableDevicePropVariantCollection are the same type.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicepropvariantcollection-gettype HRESULT GetType( [out]
// VARTYPE *pvt );
VARTYPE GetType();
/// The ChangeType method converts all items in the collection to the specified VARTYPE.
///
/// Specifies the VARTYPE to which you want to convert all items in the collection. Example types include VT_UI4 and VT_UI8.
///
///
/// If this method fails, the collection may be left in an intermediate state, with some members converted and some not converted.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicepropvariantcollection-changetype HRESULT ChangeType(
// [in] const VARTYPE vt );
void ChangeType([In] VARTYPE vt);
///
/// The Clear method frees, and then removes, all items from the collection. The collection is considered empty after
/// calling this method.
///
///
/// After calling Clear, the collection is considered type-less, meaning that the VARTYPE it was previously set to is no
/// longer restricting Add operations. A call to Add after calling Clear is considered the "first"
/// Add for this collection.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicepropvariantcollection-clear HRESULT Clear();
void Clear();
/// The RemoveAt method removes the element stored at the location specified by the given index.
/// Specifies the index of the element to be removed.
/// You must specify a zero-based index.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicepropvariantcollection-removeat HRESULT RemoveAt( [in]
// const DWORD dwIndex );
void RemoveAt([In] uint dwIndex);
}
///
///
/// The IPortableDeviceValues interface holds a collection of PROPERTYKEY/ PROPVARIANT pairs. Values in the
/// collection do not need to be the same VARTYPE.
///
///
/// Values are stored as key-value pairs; each key must be unique in the collection. Clients can search for items by
/// PROPERTYKEY or zero-based index. Data values are stored as PROPVARIANT structures. You can add or retrieve values
/// of any type by using the generic methods SetValue and GetValue, or you add items by using the method specific to
/// the type of data added.
///
///
/// The Get... methods require the caller to release any retrieved values appropriately. The Set... methods copy the
/// value into the collection.
///
///
/// When an IPortableDeviceValues interface is released, it calls Clear, which frees the memory that was allocated for
/// all its members appropriately.
///
/// This interface can be retrieved from a method or, if a new object is required, call CoCreate with CLSID_PortableDeviceValues.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues
[PInvokeData("portabldevicetypes.h")]
[ComImport, Guid("6848f6f2-3155-4f86-b6f5-263eeeab3143"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(PortableDeviceValues))]
public interface IPortableDeviceValues
{
/// The GetCount method retrieves the number of items in the collection.
/// A DWORD that contains the number of items in the collection.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getcount HRESULT GetCount( [in] DWORD *pcelt );
uint GetCount();
/// The GetAt method retrieves a value from the collection using the supplied zero-based index.
/// A DWORD that specifies a zero-based index in the collection.
/// An optional PROPERTYKEY pointer that retrieves the key of the specified item.
///
/// An optional PROPVARIANT that retrieves the value of the specified item. The caller must free the memory by calling
/// PropVariantClear when done with it.
///
///
/// If a property indicates a value of type VT_UNKNOWN, the property will be one of the Windows Portable Devices (
/// IPortableDeviceKeyCollection, IPortableDeviceValuesCollection, IPortableDeviceValues or
/// IPortableDevicePropVariantCollection). No other interfaces can be returned by Windows Portable Devices.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getat HRESULT GetAt( [in] const DWORD index,
// [in, out] PROPERTYKEY *pKey, [in, out] PROPVARIANT *pValue );
void GetAt(uint index, out PROPERTYKEY pKey, [Out] PROPVARIANT pValue);
/// The SetValue method adds a new PROPVARIANT value or overwrites an existing one.
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
///
/// A PROPVARIANT that specifies the new value. The SDK copies the value, so the caller can release the local variable by
/// calling PropVariantClear after calling this method.
///
///
///
/// When the VARTYPE for pValue is VT_VECTOR or VT_UI1, setting a NULL or zero-sized buffer is not supported. For
/// example, neither pValue.caub.pElems = NULL nor pValue.caub.cElems = 0 are allowed.
///
///
/// This method can be used to retrieve a value of any type from the collection. However, if you know the value type in advance,
/// use one of the specialized Set... methods of this interface to avoid the overhead of working with PROPVARIANT values directly.
///
///
/// If an existing value has the same key that is specified by the key parameter, it overwrites the existing value without any
/// warning. The existing key memory is released appropriately.
///
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-setvalue HRESULT SetValue( [in] REFPROPERTYKEY
// key, [in] const PROPVARIANT *pValue );
void SetValue(in PROPERTYKEY key, [In] PROPVARIANT pValue);
/// The GetValue method retrieves a PROPVARIANT value specified by a key.
/// A REFPROPERTYKEY key that specifies the item to retrieve.
///
/// Pointer to the retrieved PROPVARIANT value. The caller must release the memory by calling PropVariantClear
/// when done with it.
///
///
///
/// When the VARTYPE for pValue is VT_VECTOR or VT_UI1, retrieving a NULL or zero-sized buffer is not supported. For
/// example, neither pValue.caub.pElems = NULL nor pValue.caub.cElems = 0 are allowed.
///
///
/// This method can be used to retrieve a value of any type from the collection. However, if you know the value type in advance,
/// use one of the specialized retrieval methods of this interface to avoid the overhead of working with PROPVARIANT values directly.
///
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getvalue HRESULT GetValue( [in] REFPROPERTYKEY
// key, [out] PROPVARIANT *pValue );
PROPVARIANT GetValue(in PROPERTYKEY key);
/// The SetStringValue method adds a new string value (type VT_LPWSTR) or overwrites an existing one.
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
///
/// A LPCWSTR that specifies the new value. The string is copied, so the caller can release the memory allocated for this
/// value after calling this method.
///
/// Any existing key memory will be released appropriately.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-setstringvalue HRESULT SetStringValue( [in]
// REFPROPERTYKEY key, [in] LPCWSTR Value );
void SetStringValue(in PROPERTYKEY key, [In, MarshalAs(UnmanagedType.LPWStr)] string Value);
/// The GetStringValue method retrieves a string value (type VT_LPWSTR) specified by a key.
/// A REFPROPERTYKEY key that specifies the item to retrieve.
///
/// Pointer to the retrieved LPWSTR value. The caller is responsible for calling CoTaskMemFree to release the memory.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getstringvalue HRESULT GetStringValue( [in]
// REFPROPERTYKEY key, [out] LPWSTR *pValue );
[return: MarshalAs(UnmanagedType.LPWStr)]
string GetStringValue(in PROPERTYKEY key);
///
/// The SetUnsignedIntegerValue method adds a new ULONG value (type VT_UI4) or overwrites an existing one.
///
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
/// A ULONG that specifies the new value.
///
/// If an existing value has the same key that is specified by the key parameter, it overwrites the existing value without any warning.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-setunsignedintegervalue HRESULT
// SetUnsignedIntegerValue( [in] REFPROPERTYKEY key, [in] const ULONG Value );
void SetUnsignedIntegerValue(in PROPERTYKEY key, [In] uint Value);
/// The GetUnsignedIntegerValue method retrieves a ULONG value (type VT_UI4) specified by a key.
/// A REFPROPERTYKEY key that specifies the item to retrieve.
/// Pointer to the retrieved ULONG value.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getunsignedintegervalue HRESULT
// GetUnsignedIntegerValue( [in] REFPROPERTYKEY key, [out] ULONG *pValue );
uint GetUnsignedIntegerValue(in PROPERTYKEY key);
///
/// The SetSignedIntegerValue method adds a new LONG value (type VT_I4) or overwrites an existing one.
///
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
/// A LONG that specifies the new value.
///
/// If an existing value has the same key that is specified by the key parameter, it overwrites the existing value without any warning.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-setsignedintegervalue HRESULT
// SetSignedIntegerValue( [in] REFPROPERTYKEY key, [in] const LONG Value );
void SetSignedIntegerValue(in PROPERTYKEY key, [In] int Value);
/// The GetSignedIntegerValue method retrieves a LONG value (type VT_I4) specified by a key.
/// A REFPROPERTYKEY key that specifies the item to retrieve.
/// Pointer to the retrieved LONG value.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getsignedintegervalue HRESULT
// GetSignedIntegerValue( [in] REFPROPERTYKEY key, [out] LONG *pValue );
int GetSignedIntegerValue(in PROPERTYKEY key);
///
/// The SetUnsignedLargeIntegerValue method adds a new ULONGLONG value (type VT_UI8) or overwrites an existing one.
///
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
/// A ULONGLONG that specifies the new value.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-setunsignedlargeintegervalue HRESULT
// SetUnsignedLargeIntegerValue( [in] REFPROPERTYKEY key, [in] const ULONGLONG Value );
void SetUnsignedLargeIntegerValue(in PROPERTYKEY key, [In] ulong Value);
///
/// The GetUnsignedLargeIntegerValue method retrieves a ULONGLONG value (type VT_UI8) specified by a key.
///
/// A REFPROPERTYKEY key that specifies the item to retrieve.
/// Pointer to the retrieved ULONGLONG value.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getunsignedlargeintegervalue HRESULT
// GetUnsignedLargeIntegerValue( [in] REFPROPERTYKEY key, [out] ULONGLONG *pValue );
ulong GetUnsignedLargeIntegerValue(in PROPERTYKEY key);
///
/// The SetSignedLargeIntegerValue method adds a new LONGLONG value (type VT_I8) or overwrites an existing one.
///
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
/// A LONGLONG that specifies the new value.
///
/// If an existing value has the same key that is specified by the key parameter, it overwrites the existing value without any warning.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-setsignedlargeintegervalue HRESULT
// SetSignedLargeIntegerValue( [in] REFPROPERTYKEY key, [in] const LONGLONG Value );
void SetSignedLargeIntegerValue(in PROPERTYKEY key, [In] long Value);
/// The GetSignedLargeIntegerValue method retrieves a LONGLONG value (type VT_I8) specified by a key.
/// A REFPROPERTYKEY key that specifies the item to retrieve.
/// Pointer to the retrieved ULONG value.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getsignedlargeintegervalue HRESULT
// GetSignedLargeIntegerValue( [in] REFPROPERTYKEY key, [out] LONGLONG *pValue );
long GetSignedLargeIntegerValue(in PROPERTYKEY key);
/// The SetFloatValue method adds a new FLOAT value (type VT_R4) or overwrites an existing one.
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
/// A FLOAT that contains the new value.
///
/// If an existing value has the same key that is specified by the key parameter, it overwrites the existing value without any warning.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-setfloatvalue HRESULT SetFloatValue( [in]
// REFPROPERTYKEY key, [in] const FLOAT Value );
void SetFloatValue(in PROPERTYKEY key, [In] float Value);
/// The GetFloatValue method retrieves a FLOAT value (type VT_R4) specified by a key.
/// A REFPROPERTYKEY key that specifies the item to retrieve.
/// Pointer to the retrieved FLOAT value.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getfloatvalue HRESULT GetFloatValue( [in]
// REFPROPERTYKEY key, [out] FLOAT *pValue );
float GetFloatValue(in PROPERTYKEY key);
/// The SetErrorValue method adds a new HRESULT value (type VT_ERROR) or overwrites an existing one.
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
/// An HRESULT that contains the new value.
///
/// If an existing value has the same key specified by the key parameter, it overwrites the existing value without any warning.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-seterrorvalue HRESULT SetErrorValue( [in]
// REFPROPERTYKEY key, [in] const HRESULT Value );
void SetErrorValue(in PROPERTYKEY key, HRESULT Value);
/// The GetErrorValue method retrieves an HRESULT value (type VT_ERROR) specified by a key.
/// A REFPROPERTYKEY key that specifies the item to retrieve.
/// Pointer to the retrieved HRESULT value.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-geterrorvalue HRESULT GetErrorValue( [in]
// REFPROPERTYKEY key, [out] HRESULT *pValue );
HRESULT GetErrorValue(in PROPERTYKEY key);
///
/// The SetKeyValue method adds a new REFPROPERTYKEY value (type VT_UNKNOWN) or overwrites an existing one.
///
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
/// A REFPROPERTYKEY that specifies the new value.
///
/// If an existing value has the same key that is specified by the key parameter, it overwrites the existing value without any
/// warning. The existing key memory is released appropriately.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-setkeyvalue HRESULT SetKeyValue( [in]
// REFPROPERTYKEY key, [in] REFPROPERTYKEY Value );
void SetKeyValue(in PROPERTYKEY key, in PROPERTYKEY Value);
/// The GetKeyValue method retrieves a PROPERTYKEY value specified by a key.
/// A REFPROPERTYKEY key that specifies the item to retrieve.
/// Pointer to the retrieved PROPERTYKEY value.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getkeyvalue HRESULT GetKeyValue( [in]
// REFPROPERTYKEY key, [out] PROPERTYKEY *pValue );
PROPERTYKEY GetKeyValue(in PROPERTYKEY key);
/// The SetBoolValue method adds a new Boolean value (type VT_BOOL) or overwrites an existing one.
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
/// A BOOL that specifies the new value.
///
/// If an existing value has the same key specified by the key parameter, it overwrites the existing value without any warning.
/// The existing key memory is released appropriately.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-setboolvalue HRESULT SetBoolValue( [in]
// REFPROPERTYKEY key, [in] const BOOL Value );
void SetBoolValue(in PROPERTYKEY key, [In, MarshalAs(UnmanagedType.Bool)] bool Value);
/// The GetBoolValue method retrieves a Boolean value (type VT_BOOL) specified by a key.
/// A REFPROPERTYKEY key that specifies the item to retrieve.
/// Pointer to the retrieved BOOL value.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getboolvalue HRESULT GetBoolValue( [in]
// REFPROPERTYKEY key, [out] BOOL *pValue );
[return: MarshalAs(UnmanagedType.Bool)]
bool GetBoolValue(in PROPERTYKEY key);
///
/// The SetIUnknownValue method adds a new IUnknown value (type VT_UNKNOWN) or overwrites an existing one.
///
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
///
/// A pointer to an IUnknown interface that specifies the new value. The SDK copies a reference to the submitted
/// interface and calls AddRef on it.
///
///
/// If an existing value has the same key that is specified by the key parameter, it overwrites the existing value without any
/// warning. The existing key memory is released appropriately.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-setiunknownvalue HRESULT SetIUnknownValue( [in]
// REFPROPERTYKEY key, [in] IUnknown *pValue );
void SetIUnknownValue(in PROPERTYKEY key, [In, MarshalAs(UnmanagedType.IUnknown)] object pValue);
///
/// The GetIUnknownValue method retrieves an IUnknown interface value (type VT_UNKNOWN) specified by a key.
///
/// A REFPROPERTYKEY key that specifies the item to retrieve.
///
/// Address of a variable that receives a pointer to the retrieved IUnknown interface. The caller is responsible for
/// calling Release on the retrieved interface.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getiunknownvalue HRESULT GetIUnknownValue( [in]
// REFPROPERTYKEY key, [out] IUnknown **ppValue );
[return: MarshalAs(UnmanagedType.IUnknown)]
object GetIUnknownValue(in PROPERTYKEY key);
/// The SetGuidValue method adds a new GUID value (type VT_CLSID) or overwrites an existing one.
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
/// A REFGUID that contains the new value.
///
/// If an existing value has the same key that is specified by the key parameter, it overwrites the existing value without any warning.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-setguidvalue HRESULT SetGuidValue( [in]
// REFPROPERTYKEY key, [in] REFGUID Value );
void SetGuidValue(in PROPERTYKEY key, in Guid Value);
/// The GetGuidValue method retrieves a GUID value (type VT_CLSID) specified by a key.
/// A REFPROPERTYKEY key that specifies the item to retrieve.
/// Pointer to the retrieved GUID value.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getguidvalue HRESULT GetGuidValue( [in]
// REFPROPERTYKEY key, [out] GUID *pValue );
Guid GetGuidValue(in PROPERTYKEY key);
///
/// The SetBufferValue method adds a new BYTE* value (type VT_VECTOR | VT_UI1) or overwrites an existing one.
///
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
///
/// A BYTE* that contains the data to write to the item. The submitted buffer data is copied to the interface, so the
/// caller can free this buffer after making this call.
///
/// The size of the value pointed to by pValue, in bytes.
///
///
/// If an existing value has the same key that is specified by the key parameter, it overwrites the existing value without any
/// warning. The existing key memory is released appropriately.
///
/// Setting a NULL or a zero-sized buffer is not supported.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-setbuffervalue HRESULT SetBufferValue( [in]
// REFPROPERTYKEY key, [in] BYTE *pValue, [in] DWORD cbValue );
void SetBufferValue(in PROPERTYKEY key, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] byte[] pValue, [In] int cbValue);
///
/// The GetBufferValue method retrieves a byte array value (type VT_VECTOR | VT_UI1) specified by a key.
///
/// A REFPROPERTYKEY key that specifies the item to retrieve.
///
/// Pointer to the retrieved BYTE* value. The caller is responsible for freeing the memory by calling CoTaskMemFree.
///
/// Pointer to the size of ppValue, in bytes.
/// Retrieving a NULL buffer or a zero-sized buffer is not supported.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getbuffervalue HRESULT GetBufferValue( [in]
// REFPROPERTYKEY key, [out] BYTE **ppValue, [out] DWORD *pcbValue );
void GetBufferValue(in PROPERTYKEY key, [Out] out SafeCoTaskMemHandle ppValue, [Out] out int pcbValue);
///
/// The SetIPortableDeviceValuesValue method adds a new IPortableDeviceValues value (type VT_UNKNOWN) or
/// overwrites an existing one.
///
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
///
/// An IPortableDeviceValues interface that specifies the new value. The SDK copies a reference to the submitted
/// interface and calls AddRef on it.
///
///
/// If an existing value has the same key that is specified by the key parameter, it overwrites the existing value without any
/// warning. The existing key memory is released appropriately.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-setiportabledevicevaluesvalue HRESULT
// SetIPortableDeviceValuesValue( [in] REFPROPERTYKEY key, [in] IPortableDeviceValues *pValue );
void SetIPortableDeviceValuesValue(in PROPERTYKEY key, [In] IPortableDeviceValues pValue);
///
/// The GetIPortableDeviceValuesValue method retrieves an IPortableDeviceValues value (type VT_UNKNOWN) specified
/// by a key.
///
/// A REFPROPERTYKEY key that specifies the item to retrieve.
///
/// Address of a variable that receives a pointer to the retrieved IPortableDeviceValues interface. The caller is
/// responsible for calling Release on the retrieved interface.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getiportabledevicevaluesvalue HRESULT
// GetIPortableDeviceValuesValue( [in] REFPROPERTYKEY key, [out] IPortableDeviceValues **ppValue );
IPortableDeviceValues GetIPortableDeviceValuesValue(in PROPERTYKEY key);
///
/// The SetIPortableDevicePropVariantCollectionValue method adds a new IPortableDevicePropVariantCollection value
/// (type VT_UNKNOWN) or overwrites an existing one.
///
/// A REFPROPERTYKEY that specifies the item to create or overwrite.
///
/// An IPortableDevicePropVariantCollection interface that specifies the new value. The SDK copies a reference to the
/// submitted interface and calls AddRef on it.
///
///
/// If an existing value has the same key that is specified by the key parameter, it overwrites the existing value without any
/// warning. The existing key memory is released appropriately.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-setiportabledevicepropvariantcollectionvalue
// HRESULT SetIPortableDevicePropVariantCollectionValue( [in] REFPROPERTYKEY key, [in] IPortableDevicePropVariantCollection
// *pValue );
void SetIPortableDevicePropVariantCollectionValue(in PROPERTYKEY key, IPortableDevicePropVariantCollection pValue);
///
/// The GetIPortableDevicePropVariantCollectionValue method retrieves an IPortableDevicePropVariantCollection
/// value (type VT_UNKNOWN) specified by a key.
///
/// A REFPROPERTYKEY key that specifies the item to retrieve.
///
/// Address of a variable that receives a pointer to the retrieved IPortableDevicePropVariantCollection interface. The
/// caller is responsible for calling Release on the retrieved interface.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-getiportabledevicepropvariantcollectionvalue
// HRESULT GetIPortableDevicePropVariantCollectionValue( [in] REFPROPERTYKEY key, [out] IPortableDevicePropVariantCollection
// **ppValue );
IPortableDevicePropVariantCollection GetIPortableDevicePropVariantCollectionValue(in PROPERTYKEY key);
/// Adds a new SetIPortableDeviceKeyCollectionValue value (type VT_UNKNOWN) or overwrites an existing one.
/// [in] A REFPROPERTYKEY that specifies the item to create or overwrite.
///
/// [in] An IPortableDeviceKeyCollection interface that specifies the new value. The SDK copies a reference to the
/// submitted interface and calls AddRef on it.
///
///
/// If an existing value has the same key that is specified by the key parameter, it overwrites the existing value without any
/// warning. The existing key memory is released appropriately.
///
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/portabledevicetypes/nf-portabledevicetypes-iportabledevicevalues-setiportabledevicekeycollectionvalue
// HRESULT SetIPortableDeviceKeyCollectionValue( REFPROPERTYKEY key, IPortableDeviceKeyCollection *pValue );
void SetIPortableDeviceKeyCollectionValue(in PROPERTYKEY key, IPortableDeviceKeyCollection pValue);
/// Retrieves an IPortableDeviceKeyCollection value (type VT_UNKNOWN) that is specified by a key.
/// [in] A REFPROPERTYKEY key that specifies the item to retrieve.
///
/// [out] Pointer to the retrieved IPortableDeviceKeyCollection interface pointer. The caller is responsible for calling
/// Release on the retrieved interface.
///
/// None.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/portabledevicetypes/nf-portabledevicetypes-iportabledevicevalues-getiportabledevicekeycollectionvalue
// HRESULT GetIPortableDeviceKeyCollectionValue( REFPROPERTYKEY key, IPortableDeviceKeyCollection **ppValue );
IPortableDeviceKeyCollection GetIPortableDeviceKeyCollectionValue(in PROPERTYKEY key);
/// Adds a new IPortableDeviceValuesCollection value (type VT_UNKNOWN) or overwrites an existing one.
/// [in] A REFPROPERTYKEY that specifies the item to create or overwrite.
///
/// [in] An IPortableDeviceValuesCollection interface that specifies the new value. The SDK copies a reference to the
/// submitted interface and calls AddRef on it.
///
///
/// If an existing value has the same key that is specified by the key parameter, it overwrites the existing value without any
/// warning. The existing key memory is released appropriately.
///
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/portabledevicetypes/nf-portabledevicetypes-iportabledevicevalues-setiportabledevicevaluescollectionvalue
// HRESULT SetIPortableDeviceValuesCollectionValue( REFPROPERTYKEY key, IPortableDeviceValuesCollection *pValue );
void SetIPortableDeviceValuesCollectionValue(in PROPERTYKEY key, IPortableDeviceValuesCollection pValue);
/// Retrieves an IPortableDeviceValuesCollection (type VT_UNKNOWN) value specified by a key.
/// [in] A REFPROPERTYKEY key that specifies the item to retrieve.
///
/// [out] Address of a variable that receives a pointer to the retrieved IPortableDeviceValuesCollection interface. The caller
/// is responsible for calling Release on the retrieved interface.
///
/// None.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/portabledevicetypes/nf-portabledevicetypes-iportabledevicevalues-getiportabledevicevaluescollectionvalue
// HRESULT GetIPortableDeviceValuesCollectionValue( REFPROPERTYKEY key, IPortableDeviceValuesCollection **ppValue );
IPortableDeviceValuesCollection GetIPortableDeviceValuesCollectionValue(in PROPERTYKEY key);
/// The RemoveValue method removes an item from the collection.
/// A REFPROPERTYKEY that specifies the item to remove.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-removevalue HRESULT RemoveValue( [in]
// REFPROPERTYKEY key );
void RemoveValue(in PROPERTYKEY key);
/// The CopyValuesFromPropertyStore method copies the contents of an IPropertyStore into the collection.
/// An IPropertyStore to copy into the collection.
///
/// This method automatically converts all VT_BSTR values to VT_LPWSTR values.
///
/// Many external applications or components that communicate with your application, such as some shell applications, use the
/// IPropertyStore interface. This method provides a quick and easy way to exchange data with these programs.
///
/// This method is supported in Windows Vista and later versions of Windows.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-copyvaluesfrompropertystore HRESULT
// CopyValuesFromPropertyStore( [in] IPropertyStore *pStore );
void CopyValuesFromPropertyStore(IPropertyStore pStore);
///
/// The CopyValuesToPropertyStore method copies all the values from a collection into an IPropertyStore interface.
///
/// A store object.
///
///
/// This method does not convert values of VT_LPWSTR into VT_BSTR. Many external applications or components that communicate
/// with your application, such as some shell applications, use the IPropertyStore interface. This method provides a
/// quick and easy way to exchange data with these programs.
///
/// This method is supported in Windows Vista and later versions of Windows.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-copyvaluestopropertystore HRESULT
// CopyValuesToPropertyStore( [in] IPropertyStore *pStore );
void CopyValuesToPropertyStore(IPropertyStore pStore);
/// The Clear method deletes all items from the collection.
///
/// This method frees the memory for all dynamically allocated items in the collection. For interfaces, it calls Release.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevalues-clear HRESULT Clear();
void Clear();
}
///
/// The IPortableDeviceValuesCollection interface holds a collection of zero-based indexed IPortableDeviceValues
/// interfaces. This interface can be retrieved from a method, or if a new object is required, call CoCreate with CLSID_PortableDeviceValuesCollection.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevaluescollection
[PInvokeData("portabldevicetypes.h")]
[ComImport, Guid("6E3F2D79-4E07-48C4-8208-D8C2E5AF4A99"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(PortableDeviceValuesCollection))]
public interface IPortableDeviceValuesCollection
{
/// The GetCount method retrieves the number of items in the collection.
/// The number of IPortableDeviceValues interfaces in the collection.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevaluescollection-getcount HRESULT GetCount( [in] DWORD
// *pcElems );
uint GetCount();
/// The GetAt method retrieves an item from the collection by a zero-based index.
/// DWORD that specifies a zero-based index in the collection.
///
/// An IPortableDeviceValues interface from the collection. The caller is responsible for calling Release on this
/// interface when done with it.
///
/// Any changes that are made to values in the retrieved interface will be made to the version stored in the collection.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevaluescollection-getat HRESULT GetAt( [in] const DWORD
// dwIndex, [out] IPortableDeviceValues **ppValues );
IPortableDeviceValues GetAt(uint dwIndex);
/// The Add method adds an item to the collection.
///
/// An IPortableDeviceValues interface to add to the collection. The interface is not actually copied, but AddRef
/// is called on it.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevaluescollection-add HRESULT Add( [in]
// IPortableDeviceValues *pValues );
void Add(IPortableDeviceValues pValues);
/// The Clear method releases all items from the collection.
/// The method releases all memory that is allocated for the items in the collection.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevaluescollection-clear HRESULT Clear();
void Clear();
/// The RemoveAt method removes the element stored at the location specified by the given index.
/// Specifies the index of the element to be removed.
/// You must specify a zero-based index.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iportabledevicevaluescollection-removeat HRESULT RemoveAt( [in] const
// DWORD dwIndex );
void RemoveAt(uint dwIndex);
}
///
///
/// The IWpdSerializer interface is used by the device driver to serialize IPortableDeviceValues interfaces to and
/// from the raw data buffers used to communicate with the application.
///
///
/// Applications do not need to use this interface, because the data is serialized and deserialized automatically when calling IPortableDevice::SendCommand.
///
/// To get this interface, call CoCreateInstance and pass in IID_IWpdSerializer.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iwpdserializer
[PInvokeData("portabldevicetypes.h")]
[ComImport, Guid("b32f4002-bb27-45ff-af4f-06631c1e8dad"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(WpdSerializer))]
public interface IWpdSerializer
{
///
/// The GetIPortableDeviceValuesFromBuffer method deserializes a byte array to an IPortableDeviceValues interface.
///
/// Pointer to the buffer to deserialize.
/// DWORD that specifies the size of the buffer, in bytes.
///
/// An IPortableDeviceValues interface created from the buffer. The application is responsible for calling Release
/// on the interface.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iwpdserializer-getiportabledevicevaluesfrombuffer HRESULT
// GetIPortableDeviceValuesFromBuffer( [in] BYTE *pBuffer, [in] DWORD dwInputBufferLength, [out] IPortableDeviceValues
// **ppParams );
IPortableDeviceValues GetIPortableDeviceValuesFromBuffer(byte[] pBuffer, uint dwInputBufferLength);
///
/// The WriteIPortableDeviceValuesToBuffer method serializes an IPortableDeviceValues interface to a
/// caller-allocated byte array.
///
/// DWORD that specifies the size of pBuffer, in bytes.
/// An IPortableDeviceValues interface to serialize.
/// A caller-allocated buffer. To learn the size of the required buffer, call GetSerializedSize.
///
/// A DWORD that indicates the number of bytes that was actually written to the caller-allocated buffer.
///
///
/// This method copies an IPortableDeviceValues interface into an existing buffer. If you want to allocate a new buffer,
/// use GetBufferFromIPortableDeviceValues.
///
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iwpdserializer-writeiportabledevicevaluestobuffer HRESULT
// WriteIPortableDeviceValuesToBuffer( [in] DWORD dwOutputBufferLength, [in] IPortableDeviceValues *pResults, [out] BYTE
// *pBuffer, [out] DWORD *pdwBytesWritten );
void WriteIPortableDeviceValuesToBuffer(uint dwOutputBufferLength, IPortableDeviceValues pResults, byte[] pBuffer, out uint pdwBytesWritten);
///
/// The GetBufferFromIPortableDeviceValues method serializes a submitted IPortableDeviceValues interface to an
/// allocated byte array. The byte array returned is allocated for the caller and should be freed by the caller using CoTaskMemFree.
///
/// An IPortableDeviceValues interface to serialize.
///
/// A BYTE* that contains the serialized data. Windows Portable Devices allocates this memory; the caller must free it by
/// calling CoTaskMemFree.
///
/// A DWORD that specifies the size of allocated buffer, in bytes.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iwpdserializer-getbufferfromiportabledevicevalues HRESULT
// GetBufferFromIPortableDeviceValues( [in] IPortableDeviceValues *pSource, [out] BYTE **ppBuffer, [out] DWORD *pdwBufferSize );
void GetBufferFromIPortableDeviceValues(IPortableDeviceValues pSource, out SafeCoTaskMemHandle ppBuffer, out uint pdwBufferSize);
///
/// The GetSerializedSize method calculates the buffer size that is required to hold a serialized
/// IPortableDeviceValues interface.
///
/// An IPortableDeviceValues interface whose size you want to request.
/// A DWORD that indicates the buffer size that is required to serialize pSource, in bytes.
// https://docs.microsoft.com/en-us/windows/win32/wpd_sdk/iwpdserializer-getserializedsize HRESULT GetSerializedSize( [in]
// IPortableDeviceValues *pSource, [out] DWORD *pdwSize );
uint GetSerializedSize(IPortableDeviceValues pSource);
}
/// Enumerates the items in the collection.
/// The instance.
/// A sequence of values from the collection.
public static IEnumerable Enumerate(this IPortableDeviceKeyCollection intf) =>
new Vanara.Collections.IEnumFromIndexer(intf.GetCount, intf.GetAt);
/// Enumerates the items in the collection.
/// The instance.
/// A sequence of values from the collection.
public static IEnumerable Enumerate(this IPortableDevicePropVariantCollection intf) =>
new Vanara.Collections.IEnumFromIndexer(intf.GetCount, i => { PROPVARIANT pv = new(); intf.GetAt(i, pv); return pv; });
/// Enumerates the items in the collection.
/// The instance.
/// A sequence of values from the collection.
public static IEnumerable<(PROPERTYKEY, PROPVARIANT)> Enumerate(this IPortableDeviceValues intf) =>
new Vanara.Collections.IEnumFromIndexer<(PROPERTYKEY, PROPVARIANT)>(intf.GetCount, i => { PROPVARIANT pv = new(); intf.GetAt(i, out PROPERTYKEY pk, pv); return (pk, pv); });
/// Enumerates the items in the collection.
/// The instance.
/// A sequence of values from the collection.
public static IEnumerable Enumerate(this IPortableDeviceValuesCollection intf) =>
new Vanara.Collections.IEnumFromIndexer(intf.GetCount, intf.GetAt);
/// Gets the property key value from WPD_PROPERTY_COMMON_COMMAND_CATEGORY and WPD_PROPERTY_COMMON_COMMAND_ID.
/// The IPortableDeviceValues instance.
/// The PROPERTYKEY.
public static PROPERTYKEY GetCommandPKey(this IPortableDeviceValues iValues) =>
new PROPERTYKEY(iValues.GetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY), iValues.GetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID));
/// Sets the values corresponding to a command property key using WPD_PROPERTY_COMMON_COMMAND_CATEGORY and WPD_PROPERTY_COMMON_COMMAND_ID.
/// The IPortableDeviceValues instance.
/// The command property key.
public static void SetCommandPKey(this IPortableDeviceValues iValues, in PROPERTYKEY commandPropKey)
{
iValues.SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, commandPropKey.Key);
iValues.SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, commandPropKey.Id);
}
/// PortableDeviceKeyCollection Class
[PInvokeData("portabldevicetypes.h")]
[ComImport, Guid("de2d022d-2480-43be-97f0-d1fa2cf98f4f"), ClassInterface(ClassInterfaceType.None)]
public class PortableDeviceKeyCollection
{
}
/// PortableDevicePropVariantCollection Class
[PInvokeData("portabldevicetypes.h")]
[ComImport, Guid("08a99e2f-6d6d-4b80-af5a-baf2bcbe4cb9"), ClassInterface(ClassInterfaceType.None)]
public class PortableDevicePropVariantCollection
{
}
/// PortableDeviceValues Class
[PInvokeData("portabldevicetypes.h")]
[ComImport, Guid("0c15d503-d017-47ce-9016-7b3f978721cc"), ClassInterface(ClassInterfaceType.None)]
public class PortableDeviceValues
{
}
/// PortableDeviceValuesCollection Class
[PInvokeData("portabldevicetypes.h")]
[ComImport, Guid("3882134d-14cf-4220-9cb4-435f86d83f60"), ClassInterface(ClassInterfaceType.None)]
public class PortableDeviceValuesCollection
{
}
/// WpdSerializer Class
[PInvokeData("portabldevicetypes.h")]
[ComImport, Guid("0b91a74b-ad7c-4a9d-b563-29eef9167172"), ClassInterface(ClassInterfaceType.None)]
public class WpdSerializer
{
}
}
}