diff options
Diffstat (limited to 'wpd')
219 files changed, 0 insertions, 50713 deletions
diff --git a/wpd/WpdBasicHardwareDriver/Device.cpp b/wpd/WpdBasicHardwareDriver/Device.cpp deleted file mode 100644 index 22a7ade8..00000000 --- a/wpd/WpdBasicHardwareDriver/Device.cpp +++ /dev/null @@ -1,415 +0,0 @@ -#include "stdafx.h" -#include "Device.tmh" - -#include "WpdBasicHardwareDriver_i.c" - -STDMETHODIMP_(HRESULT) -CDevice::OnD0Entry(_In_ IWDFDevice* pDevice, - WDF_POWER_DEVICE_STATE previousState) -{ - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_DEVICE, "%!FUNC! Entry"); - - UNREFERENCED_PARAMETER(pDevice); - UNREFERENCED_PARAMETER(previousState); - - HRESULT hr = S_OK; - RS232Target* pTarget = NULL; - - if (m_pWpdBaseDriver != NULL) - { - pTarget = m_pWpdBaseDriver->GetRS232Target(); - if (pTarget != NULL) - { - hr = pTarget->Start(); - } - } - - return hr; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnD0Exit(_In_ IWDFDevice* pDevice, - WDF_POWER_DEVICE_STATE newState) -{ - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_DEVICE, "%!FUNC! Entry"); - - UNREFERENCED_PARAMETER(pDevice); - UNREFERENCED_PARAMETER(newState); - - HRESULT hr = S_OK; - RS232Target* pTarget = NULL; - - if (m_pWpdBaseDriver != NULL) - { - pTarget = m_pWpdBaseDriver->GetRS232Target(); - if (pTarget != NULL) - { - hr = pTarget->Stop(); - } - } - return hr; -} - -STDMETHODIMP_(VOID) -CDevice::OnSurpriseRemoval(_In_ IWDFDevice* pDevice) -{ - UNREFERENCED_PARAMETER(pDevice); - return; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnQueryRemove(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnQueryStop(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(VOID) -CDevice::OnSelfManagedIoCleanup(_In_ IWDFDevice* pDevice) -{ - UNREFERENCED_PARAMETER(pDevice); - return; -} - -STDMETHODIMP_(VOID) -CDevice::OnSelfManagedIoFlush(_In_ IWDFDevice* pDevice) -{ - UNREFERENCED_PARAMETER(pDevice); - return; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoInit(_In_ IWDFDevice* pDevice) -{ - UNREFERENCED_PARAMETER(pDevice); - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoSuspend(_In_ IWDFDevice* pDevice) -{ - UNREFERENCED_PARAMETER(pDevice); - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoRestart(_In_ IWDFDevice* pDevice) -{ - UNREFERENCED_PARAMETER(pDevice); - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoStop(_In_ IWDFDevice* pDevice) -{ - UNREFERENCED_PARAMETER(pDevice); - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnPrepareHardware(_In_ IWDFDevice* pDevice) -{ - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_DEVICE, "%!FUNC! Entry"); - - HRESULT hr = S_OK; - - if (m_pWpdBaseDriver != NULL) - { - hr = m_pWpdBaseDriver->Initialize(pDevice); - CHECK_HR(hr, "Failed to Initialize the driver class"); - } - - // Initialize the WPD Class Extension. This will enable the appropriate WPD interface GUID, - // as well as do any additional initialization (e.g. enabling Legacy Compatibility layers for those drivers - // which requested support in their INF). - if (hr == S_OK && m_pPortableDeviceClassExtension == NULL) - { - hr = CoCreateInstance(CLSID_PortableDeviceClassExtension, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceClassExtension, - (VOID**)&m_pPortableDeviceClassExtension); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceClassExtension"); - - if (hr == S_OK) - { - CComPtr<IPortableDeviceValues> pOptions; - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pOptions); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - - if (hr == S_OK) - { - CComPtr<IPortableDevicePropVariantCollection> pContentTypes; - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**)&pContentTypes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - - // Driver has no supported content types, add an empty list of supported content types to the options - if (hr == S_OK) - { - hr = pOptions->SetIPortableDevicePropVariantCollectionValue(WPD_CLASS_EXTENSION_OPTIONS_SUPPORTED_CONTENT_TYPES, pContentTypes); - CHECK_HR(hr, "Failed to set WPD_CLASS_EXTENSION_OPTIONS_SUPPORTED_CONTENT_TYPES"); - } - - if (hr == S_OK) - { - // Initialize the PortableDeviceClassExtension - hr = m_pPortableDeviceClassExtension->Initialize(pDevice, pOptions); - CHECK_HR(hr, "Failed to Initialize portable device class extension object"); - } - } - } - - if (hr == S_OK) - { - // Since users commonly have the abiltity to customize their device even when it is not - // connected to the PC, we need to make sure the PC is current when the driver loads. - // - // Send the latest device friendly name to the PortableDeviceClassExtension component - // so the system is always updated with the current device name. - // - // This call should also be made after a successful property set operation of - // WPD_DEVICE_FRIENDLY_NAME. - LPWSTR wszDeviceFriendlyName = NULL; - - if (hr == S_OK) - { - hr = GetDeviceFriendlyName(&wszDeviceFriendlyName); - CHECK_HR(hr, "Failed to get device's friendly name"); - } - - if (hr == S_OK && wszDeviceFriendlyName != NULL) - { - hr = UpdateDeviceFriendlyName(m_pPortableDeviceClassExtension, wszDeviceFriendlyName); - CHECK_HR(hr, "Failed to update device's friendly name"); - } - - // Free the memory. - CoTaskMemFree(wszDeviceFriendlyName); - wszDeviceFriendlyName = NULL; - } - } - return hr; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnReleaseHardware(_In_ IWDFDevice* pDevice) -{ - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_DEVICE, "%!FUNC! Entry"); - - UNREFERENCED_PARAMETER(pDevice); - if (m_pWpdBaseDriver != NULL) - { - m_pWpdBaseDriver->Uninitialize(); - } - - if (m_pPortableDeviceClassExtension != NULL) - { - m_pPortableDeviceClassExtension = NULL; - } - - return S_OK; -} - -HRESULT CDevice::GetDeviceFriendlyName( - _Outptr_result_maybenull_ LPWSTR* pwszDeviceFriendlyName) -{ - HRESULT hr = S_OK; - - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<IPortableDeviceKeyCollection> pKeys; - CComPtr<IPortableDeviceValues> pValues; - - if (pwszDeviceFriendlyName == NULL) - { - hr = E_INVALIDARG; - return hr; - } - - *pwszDeviceFriendlyName = NULL; - - // CoCreate a collection to store the WPD_COMMAND_OBJECT_PROPERTIES_GET command parameters. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the WPD_COMMAND_OBJECT_PROPERTIES_GET command results. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the requested property keys. In our case, we are requesting just the device friendly name - // (WPD_DEVICE_FRIENDLY_NAME) - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**)&pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection for results"); - } - - // Set the params - if (hr == S_OK) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_OBJECT_PROPERTIES_GET.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - - if (hr == S_OK) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_OBJECT_PROPERTIES_GET.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - - if (hr == S_OK) - { - hr = pParams->SetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID")); - } - - if (hr == S_OK) - { - hr = pKeys->Add(WPD_DEVICE_FRIENDLY_NAME); - CHECK_HR(hr, ("Failed to add WPD_DEVICE_FRIENDLY_NAME to key collection")); - } - - if (hr == S_OK) - { - hr = pParams->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, pKeys); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS")); - } - - // Make the call - if (hr == S_OK) - { - hr = m_pWpdBaseDriver->DispatchWpdMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to dispatch message to get supported content types")); - } - - // Get the results - if (hr == S_OK) - { - hr = pResults->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, &pValues); - CHECK_HR(hr, ("Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES")); - } - - if (hr == S_OK) - { - hr = pValues->GetStringValue(WPD_DEVICE_FRIENDLY_NAME, pwszDeviceFriendlyName); - CHECK_HR(hr, ("Failed to get WPD_DEVICE_FRIENDLY_NAME")); - } - - return hr; -} - -HRESULT UpdateDeviceFriendlyName( - _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension, - _In_ LPCWSTR wszDeviceFriendlyName) -{ - HRESULT hr = S_OK; - - // If we were passed NULL parameters we have nothing to do, return S_OK. - if ((pPortableDeviceClassExtension == NULL) || - (wszDeviceFriendlyName == NULL)) - { - return S_OK; - } - - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<IPortableDeviceValues> pValues; - - // Prepare to make a call to set the device information - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues for results"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues for results"); - } - - // Get the information values to update and set them in WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES - if (hr == S_OK) - { - hr = pValues->SetStringValue(WPD_DEVICE_FRIENDLY_NAME, wszDeviceFriendlyName); - CHECK_HR(hr, ("Failed to set WPD_DEVICE_FRIENDLY_NAME")); - } - - // Set the params - if (hr == S_OK) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_CLASS_EXTENSION_WRITE_DEVICE_INFORMATION.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - if (hr == S_OK) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_CLASS_EXTENSION_WRITE_DEVICE_INFORMATION.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - if (hr == S_OK) - { - hr = pParams->SetIPortableDeviceValuesValue(WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES, pValues); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES")); - } - - // Make the call - if (hr == S_OK) - { - hr = pPortableDeviceClassExtension->ProcessLibraryMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to process update device information message")); - } - - // A Failed ProcessLibraryMessage operation for updating this value is not considered - // fatal and should return S_OK. - - return S_OK; -} diff --git a/wpd/WpdBasicHardwareDriver/Device.h b/wpd/WpdBasicHardwareDriver/Device.h deleted file mode 100644 index 6b7ed2d0..00000000 --- a/wpd/WpdBasicHardwareDriver/Device.h +++ /dev/null @@ -1,89 +0,0 @@ -#pragma once - -#include "resource.h" -#include "WpdBasicHardwareDriver.h" - -class ATL_NO_VTABLE CDevice : - public CComObjectRootEx<CComMultiThreadModel>, - public IPnpCallback, - public IPnpCallbackSelfManagedIo, - public IPnpCallbackHardware -{ -public: - CDevice() : - m_pWpdBaseDriver(NULL) - { - } - - DECLARE_NOT_AGGREGATABLE(CDevice) - - BEGIN_COM_MAP(CDevice) - COM_INTERFACE_ENTRY(IPnpCallback) - COM_INTERFACE_ENTRY(IPnpCallbackSelfManagedIo) - COM_INTERFACE_ENTRY(IPnpCallbackHardware) - END_COM_MAP() - -public: - static HRESULT - CreateInstance( - _In_ IWDFDeviceInitialize* pDeviceInit, - _In_ WpdBaseDriver* pWpdBaseDriver, - _COM_Outptr_ IUnknown** ppUnkwn) - { - *ppUnkwn = NULL; - - // - // Set device properties. - // - pDeviceInit->SetLockingConstraint(None); - - CComObject< CDevice> *pMyDevice = NULL; - HRESULT hr = CComObject<CDevice>::CreateInstance( &pMyDevice ); - if( SUCCEEDED (hr) ) - { - pMyDevice->AddRef(); - hr = pMyDevice->QueryInterface( __uuidof(IUnknown),(void **) ppUnkwn); - if (hr == S_OK) - { - pMyDevice->m_pWpdBaseDriver = pWpdBaseDriver; - } - pMyDevice->Release(); - pMyDevice = NULL; - } - - return hr; - } - - // IPnpCallback - // - STDMETHOD_(HRESULT, OnD0Entry) (_In_ IWDFDevice* pDevice, WDF_POWER_DEVICE_STATE previousState); - STDMETHOD_(HRESULT, OnD0Exit) (_In_ IWDFDevice* pDevice, WDF_POWER_DEVICE_STATE newState); - STDMETHOD_(VOID, OnSurpriseRemoval)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnQueryRemove) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnQueryStop) (_In_ IWDFDevice* pDevice); - - // IPnpCallbackSelfManagedIo - // - STDMETHOD_(VOID, OnSelfManagedIoCleanup)(_In_ IWDFDevice* pDevice); - STDMETHOD_(VOID, OnSelfManagedIoFlush) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoInit) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoSuspend)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoRestart)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoStop) (_In_ IWDFDevice* pDevice); - - // IPnpCallbackHardware - // - STDMETHOD_(HRESULT, OnPrepareHardware)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnReleaseHardware)(_In_ IWDFDevice* pDevice); - -private: - - HRESULT GetDeviceFriendlyName( - _Outptr_result_maybenull_ LPWSTR* pwszDeviceFriendlyName); - -private: - - WpdBaseDriver* m_pWpdBaseDriver; - CComPtr<IPortableDeviceClassExtension> m_pPortableDeviceClassExtension; -}; - diff --git a/wpd/WpdBasicHardwareDriver/Driver.cpp b/wpd/WpdBasicHardwareDriver/Driver.cpp deleted file mode 100644 index ca0697a1..00000000 --- a/wpd/WpdBasicHardwareDriver/Driver.cpp +++ /dev/null @@ -1,197 +0,0 @@ -#include "stdafx.h" - -#include "Driver.tmh" - -CDriver::CDriver() -{ - - -} - -HRESULT -CDriver::OnDeviceAdd( - _In_ IWDFDriver* pDriver, - _In_ IWDFDeviceInitialize* pDeviceInit - ) -/*++ - -Routine Description: - - The framework calls this function when a device is being added to - the driver stack. - -Arguments: - - IWDFDriver - Framework interface. The driver uses this - interface to create device objects. - IWDFDeviceInitialize - Framework interface. The driver uses this - interface to set device parameters before - creating the device obeject. - -Return Value: - - HRESULT S_OK - Device added successfully - ---*/ -{ - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_DRIVER, "%!FUNC! Entry"); - - HRESULT hr = S_OK; - CComPtr<IUnknown> pDeviceCallback; - - WpdBaseDriver *pWpdBaseDriver = NULL; - - // - // Create the WPD driver object that handles all WPD messages for this device - // - pWpdBaseDriver = new WpdBaseDriver(); - if(pWpdBaseDriver == NULL) - { - hr = E_OUTOFMEMORY; - } - - if(SUCCEEDED(hr)) - { - // - // Create device callback object - // - hr = CDevice::CreateInstance(pDeviceInit, pWpdBaseDriver, &pDeviceCallback); - } - - // - // This driver has no special power management requirements and so - // we set power policy ownership to UMDF to indicate that UMDF should - // handle powermanagement for us. - // - pDeviceInit->SetPowerPolicyOwnership(FALSE); - - // - // Create WDFDevice. - // - CComPtr<IWDFDevice> pIWDFDevice; - if(SUCCEEDED(hr)) - { - hr = pDriver->CreateDevice( - pDeviceInit, - pDeviceCallback, - &pIWDFDevice); - } - - // - // Assign pWpdBaseDriver to the device object. Each UMDF device requires its own instance of - // a WpdBaseDriver to handle WPD messages. - // - if(SUCCEEDED(hr)) - { - hr = pIWDFDevice->AssignContext(this, (void*)pWpdBaseDriver); - if(SUCCEEDED(hr)) - { - // AddRef the WpdBaseDriver object since it is not stored with the - // device context. - pWpdBaseDriver->AddRef(); - } - } - - // - // Create queue callback object - // - CComPtr<IUnknown> pIUnknown; - if(S_OK == hr) - { - hr = CQueue::CreateInstance(&pIUnknown); - } - - // - // Configure the default queue. - // - if(S_OK == hr) - { - CComPtr<IWDFIoQueue> pDefaultQueue; - hr = pIWDFDevice->CreateIoQueue( - pIUnknown, - TRUE, // bDefaultQueue - WdfIoQueueDispatchSequential, - TRUE, // bPowerManaged - FALSE, // bAllowZeroLengthRequests - &pDefaultQueue); - } - - pDeviceCallback = NULL; - pIWDFDevice = NULL; - - // - // It is fine to release the interface on the callback object. - // The framework has its own refcount on this object and will - // provide an interface when calling into the driver. - // - pIUnknown = NULL; - - // Release the WpdBaseDriver object. If it was successfully added to the device context, - // it was already addref'd above. Releasing it here ensures it will be destroyed if - // an error occured and it could not be added to the device context. - SAFE_RELEASE(pWpdBaseDriver); - - return hr; -} - -void -CDriver::OnDeinitialize( - _In_ IWDFDriver* pDriver - ) -/*++ - -Routine Description: - - The framework calls this function just before de-initializing itself. All - WDF framework resources should be released by driver before returning from this call. - -Arguments: - -Return Value: - ---*/ -{ - UNREFERENCED_PARAMETER(pDriver); - return; -} - -HRESULT -CDriver::OnInitialize( - _In_ IWDFDriver* pDriver - ) -/*++ - -Routine Description: - - The framework calls this function just after loading the driver. The driver can - perform any global, device independent intialization in this routine. - -Arguments: - -Return Value: - ---*/ -{ - UNREFERENCED_PARAMETER(pDriver); - return S_OK; -} - -STDMETHODIMP_ (void) -CDriver::OnCleanup( - _In_ IWDFObject* pWdfObject - ) -{ - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_DRIVER, "%!FUNC! Entry"); - - // Release the base driver object - HRESULT hr = S_OK; - WpdBaseDriver* pWpdBaseDriver = NULL; - - hr = pWdfObject->RetrieveContext((void**)&pWpdBaseDriver); - if((hr == S_OK) && (pWpdBaseDriver != NULL)) - { - pWpdBaseDriver->Release(); - pWpdBaseDriver = NULL; - } -} - diff --git a/wpd/WpdBasicHardwareDriver/Driver.h b/wpd/WpdBasicHardwareDriver/Driver.h deleted file mode 100644 index 9b8cadec..00000000 --- a/wpd/WpdBasicHardwareDriver/Driver.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -class ATL_NO_VTABLE CDriver : - public CComObjectRootEx<CComMultiThreadModel>, - public CComCoClass<CDriver, &CLSID_WpdBasicHardwareDriver>, - public IDriverEntry, - public IObjectCleanup -{ -public: - CDriver(); - - DECLARE_REGISTRY_RESOURCEID(IDR_WpdBasicHardwareDriver) - - DECLARE_NOT_AGGREGATABLE(CDriver) - - BEGIN_COM_MAP(CDriver) - COM_INTERFACE_ENTRY(IDriverEntry) - END_COM_MAP() - -public: - // - // IDriverEntry - // - STDMETHOD (OnInitialize)( - _In_ IWDFDriver* pDriver - ); - STDMETHOD (OnDeviceAdd)( - _In_ IWDFDriver* pDriver, - _In_ IWDFDeviceInitialize* pDeviceInit - ); - STDMETHOD_ (void, OnDeinitialize)( - _In_ IWDFDriver* pDriver - ); - - // - // IObjectCleanup - // - STDMETHOD_ (void, OnCleanup)( - _In_ IWDFObject* pWdfObject - ); -}; - -OBJECT_ENTRY_AUTO(__uuidof(WpdBasicHardwareDriver), CDriver) - diff --git a/wpd/WpdBasicHardwareDriver/Queue.cpp b/wpd/WpdBasicHardwareDriver/Queue.cpp deleted file mode 100644 index e4e81c09..00000000 --- a/wpd/WpdBasicHardwareDriver/Queue.cpp +++ /dev/null @@ -1,340 +0,0 @@ -// Queue.cpp : Implementation of CQueue - - -#include "stdafx.h" -#include <devioctl.h> - -#include "Queue.tmh" - -// Add table used to lookup the Access required for Wpd Commands -BEGIN_WPD_COMMAND_ACCESS_MAP(g_WpdCommandAccessMap) - DECLARE_WPD_STANDARD_COMMAND_ACCESS_ENTRIES - // Add any custom commands here e.g. - // WPD_COMMAND_ACCESS_ENTRY(MyCustomCommand, WPD_COMMAND_ACCESS_READWRITE) -END_WPD_COMMAND_ACCESS_MAP - -// This enables use to use VERIFY_WPD_COMMAND_ACCESS to check command access function for us. -DECLARE_VERIFY_WPD_COMMAND_ACCESS; - -/****************************************************************************** - * This function calls the WpdBaseDriver to handle the WPD message. In order - * to do this it does the following: - * - * - Deserializes pBuffer into an IPortableDeviceValues which holds the command - * input parameters from the WPD application. - * - Creates an IPortableDeviceValues for the results. - * - Calls the WpdBaseDriver to handle the message. (The results of this - * operation are put into the previously created results IPortableDeviceValues.) - * - The results IPortableDeviceValues is then serialized back into pBuffer, making - * sure that it does not overrun ulOutputBufferLength. - * - *****************************************************************************/ -HRESULT CQueue::ProcessWpdMessage( - ULONG ControlCode, - _In_ ContextMap* pClientContextMap, - _In_ IWDFDevice* pDevice, - _In_reads_bytes_(ulInputBufferLength) PVOID pInBuffer, - ULONG ulInputBufferLength, - _Out_writes_bytes_to_(ulOutputBufferLength, *pdwBytesWritten) PVOID pOutBuffer, - ULONG ulOutputBufferLength, - _Out_ DWORD* pdwBytesWritten) -{ - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<WpdBaseDriver> pWpdBaseDriver; - - *pdwBytesWritten = 0; - - if (hr == S_OK) - { - hr = m_pWpdSerializer->GetIPortableDeviceValuesFromBuffer((BYTE*)pInBuffer, - ulInputBufferLength, - &pParams); - CHECK_HR(hr, "Failed to deserialize command parameters from input buffer"); - } - - // Verify that that command was sent with the appropriate access - if (hr == S_OK) - { - hr = VERIFY_WPD_COMMAND_ACCESS(ControlCode, pParams, g_WpdCommandAccessMap); - CHECK_HR(hr, "Wpd Command was sent with incorrect access flags"); - } - - // Create the WPD results collection - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Insert the client context map as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the context map. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, pClientContextMap); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Insert the IWDFDevice interface as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the WUDF Device object. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT, pDevice); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT"); - } - - // Insert the IWpdSerializer interface as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the WPD Serializer object. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT, m_pWpdSerializer); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT"); - } - - // Get the WpdBaseDriver so we can dispatch the message - if (hr == S_OK) - { - hr = GetWpdBaseDriver(pDevice, &pWpdBaseDriver); - CHECK_HR(hr, "Failed to get WpdBaseDriver"); - } - - if (hr == S_OK) - { - hr = pWpdBaseDriver->DispatchWpdMessage(pParams, pResults); - CHECK_HR(hr, "Failed to handle WPD command"); - } - - if (hr == S_OK) - { - hr = m_pWpdSerializer->WriteIPortableDeviceValuesToBuffer(ulOutputBufferLength, - pResults, - (BYTE*)pOutBuffer, - pdwBytesWritten); - CHECK_HR(hr, "Failed to serialize results to output buffer"); - } - - return hr; -} - -/****************************************************************************** - * This method gets the WpdBaseDriver associated with the UMDF device object. - * The caller should Release *ppWpdBaseDriver when it is done. - * - * When this device was created, we assigned the WpdBaseDriver as the context. - * So, in order to retrieve the correct WpdBaseDriver for this device, we simply - * get the device context. - *****************************************************************************/ -HRESULT CQueue::GetWpdBaseDriver( - _In_ IWDFDevice* pDevice, - _Outptr_result_nullonfailure_ WpdBaseDriver** ppWpdBaseDriver) -{ - HRESULT hr = S_OK; - WpdBaseDriver* pContext = NULL; - - if((pDevice == NULL) || (ppWpdBaseDriver == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter for pDevice or ppWpdBaseDriver"); - } - - *ppWpdBaseDriver = NULL; - - if(SUCCEEDED(hr)) - { - hr = pDevice->RetrieveContext((void**)&pContext); - if(SUCCEEDED(hr)) - { - if(pContext != NULL) - { - pContext->AddRef(); - *ppWpdBaseDriver = pContext; - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Device context is NULL"); - } - } - } - - return hr; -} - -// CQueue - -STDMETHODIMP_ (void) -CQueue::OnCreateFile( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - _In_ IWDFFile* pFileObject - ) -{ - UNREFERENCED_PARAMETER(pQueue); - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_QUEUE, "%!FUNC! Entry"); - - // This critical section protects the section of code where we - // Create the serializer and results interfaces used in handling I/O messages. - // We only need to create them once, then we hang on to them for the lifetime of this - // queue object. - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - HRESULT hr = S_OK; - - // Create the WPD serializer - if ((hr == S_OK) && - (m_pWpdSerializer == NULL)) - { - hr = CoCreateInstance(CLSID_WpdSerializer, - NULL, - CLSCTX_INPROC_SERVER, - IID_IWpdSerializer, - (VOID**)&m_pWpdSerializer); - - CHECK_HR(hr, "Failed to CoCreate CLSID_WpdSerializer"); - } - - // Create the client context map and associate it with the File Object - // so we can obtain it on a per-client basis. - if (hr == S_OK) - { - ContextMap* pClientContextMap = new ContextMap(); - - if(pClientContextMap != NULL) - { - hr = pFileObject->AssignContext(this, (void*)pClientContextMap); - CHECK_HR(hr, "Failed to set client context map"); - - // Release the client context map if we cannot set it - // properly - if(FAILED(hr)) - { - pClientContextMap->Release(); - pClientContextMap = NULL; - } - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to create client context map"); - } - } - - pRequest->Complete(hr); - return; -} - -STDMETHODIMP_ (void) -CQueue::OnDeviceIoControl( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - ULONG ControlCode, - SIZE_T InputBufferSizeInBytes, - SIZE_T OutputBufferSizeInBytes - ) -{ - UNREFERENCED_PARAMETER(InputBufferSizeInBytes); - UNREFERENCED_PARAMETER(OutputBufferSizeInBytes); - - HRESULT hr = S_OK; - DWORD dwBytesWritten = 0; - - if(IS_WPD_IOCTL(ControlCode)) - { - BYTE* pInputBuffer = NULL; - SIZE_T cbInputBuffer = 0; - BYTE* pOutputBuffer = NULL; - SIZE_T cbOutputBuffer = 0; - ContextMap* pClientContextMap = NULL; - CComPtr<IWDFMemory> pMemoryIn; - CComPtr<IWDFMemory> pMemoryOut; - CComPtr<IWDFDevice> pDevice; - CComPtr<IWDFFile> pFileObject; - - // - // Get input memory buffer, the memory object is always returned even if the - // underlying buffer is NULL - // - pRequest->GetInputMemory(&pMemoryIn); - pInputBuffer = (BYTE*) pMemoryIn->GetDataBuffer(&cbInputBuffer); - - // - // Get output memory buffer, the memory object is always returned even if the - // underlying buffer is NULL - // - pRequest->GetOutputMemory(&pMemoryOut); - pOutputBuffer = (BYTE*) pMemoryOut->GetDataBuffer(&cbOutputBuffer); - - // Get the Context map for this client - pRequest->GetFileObject(&pFileObject); - if (pFileObject != NULL) - { - hr = pFileObject->RetrieveContext((void**)&pClientContextMap); - CHECK_HR(hr, "Failed to get Contextmap from WDF File Object"); - - if (hr == S_OK) - { - // Get the device object - pQueue->GetDevice(&pDevice ); - hr = ProcessWpdMessage(ControlCode, - pClientContextMap, - pDevice, - pInputBuffer, - (DWORD)cbInputBuffer, - pOutputBuffer, - (DWORD)cbOutputBuffer, - &dwBytesWritten); - } - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "WDF File Object is NULL"); - } - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Received invalid/unsupported IOCTL code '0x%lx'",ControlCode); - } - - // Complete the request - if (hr == S_OK) - { - pRequest->CompleteWithInformation(hr, dwBytesWritten); - } - else - { - pRequest->Complete(hr); - } - - return; -} - -STDMETHODIMP_ (void) -CQueue::OnCleanup( - _In_ IWDFObject* pWdfObject - ) -{ - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_QUEUE, "%!FUNC! Entry"); - - // Destroy the client context map - HRESULT hr = S_OK; - ContextMap* pClientContextMap = NULL; - - hr = pWdfObject->RetrieveContext((void**)&pClientContextMap); - if((hr == S_OK) && (pClientContextMap != NULL)) - { - pClientContextMap->Release(); - pClientContextMap = NULL; - } -} - diff --git a/wpd/WpdBasicHardwareDriver/Queue.h b/wpd/WpdBasicHardwareDriver/Queue.h deleted file mode 100644 index e5cea69d..00000000 --- a/wpd/WpdBasicHardwareDriver/Queue.h +++ /dev/null @@ -1,93 +0,0 @@ -// Queue.h : Declaration of the CQueue - -#pragma once -#include "resource.h" // main symbols -#include "WpdBasicHardwareDriver.h" - -class ATL_NO_VTABLE CQueue : - public CComObjectRootEx<CComMultiThreadModel>, - public IQueueCallbackDeviceIoControl, - public IQueueCallbackCreate, - public IObjectCleanup -{ -public: - CQueue() - { - - } - - DECLARE_NOT_AGGREGATABLE(CQueue) - - BEGIN_COM_MAP(CQueue) - COM_INTERFACE_ENTRY(IQueueCallbackDeviceIoControl) - COM_INTERFACE_ENTRY(IQueueCallbackCreate) - END_COM_MAP() - -public: - static - HRESULT CreateInstance( - _COM_Outptr_ IUnknown **ppUkwn) - { - *ppUkwn = NULL; - CComObject< CQueue> *pMyQueue = NULL; - HRESULT hr = CComObject<CQueue>::CreateInstance( &pMyQueue ); - if( SUCCEEDED (hr) ) - { - pMyQueue->AddRef(); - hr = pMyQueue->QueryInterface( __uuidof(IUnknown), (void **) ppUkwn ); - pMyQueue->Release(); - pMyQueue = NULL; - } - - return hr; - } - - // - // Wdf Callbacks - // - - // IQueueCallbackCreateClose - // - STDMETHOD_ (void, OnCreateFile)( - _In_ IWDFIoQueue *pQueue, - _In_ IWDFIoRequest *pRequest, - _In_ IWDFFile *pFileObject - ); - - // - // IQueueCallbackDeviceIoControl - // - STDMETHOD_ (void, OnDeviceIoControl)( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - ULONG ControlCode, - SIZE_T InputBufferSizeInBytes, - SIZE_T OutputBufferSizeInBytes - ); - - // - // IObjectCleanup - // - STDMETHOD_ (void, OnCleanup)( - _In_ IWDFObject* pWdfObject - ); - -private: - HRESULT ProcessWpdMessage( - ULONG ControlCode, - _In_ ContextMap* pClientContextMap, - _In_ IWDFDevice* pDevice, - _In_reads_bytes_(ulInputBufferLength) PVOID pInBuffer, - ULONG ulInputBufferLength, - _Out_writes_bytes_to_(ulOutputBufferLength, *pdwBytesWritten) PVOID pOutBuffer, - ULONG ulOutputBufferLength, - _Out_ DWORD* pdwBytesWritten); - - HRESULT GetWpdBaseDriver( - _In_ IWDFDevice* pDevice, - _Outptr_result_nullonfailure_ WpdBaseDriver** ppWpdBaseDriver); - - CComPtr<IWpdSerializer> m_pWpdSerializer; - CComAutoCriticalSection m_CriticalSection; -}; - diff --git a/wpd/WpdBasicHardwareDriver/README.md b/wpd/WpdBasicHardwareDriver/README.md deleted file mode 100644 index 56414e93..00000000 --- a/wpd/WpdBasicHardwareDriver/README.md +++ /dev/null @@ -1,52 +0,0 @@ ---- -page_type: sample -description: "Supports nine sensor devices that integrate with the Parallax BS2 programmable microcontroller." -languages: -- cpp -products: -- windows -- windows-wdk ---- - -# WPD Basic Hardware Sample Driver (UMDF Version 1) - -The WpdBasicHardwareDriver is a WPD driver that supports nine devices. These devices were selected because of their simplicity. This simplicity allowed the sample to focus on the tasks that are common to portable devices without getting bogged down in hardware complexities. - -This sample driver is based on the WpdHelloWorldDriver that is also included in the Windows Driver Kit (WDK). The "Supporting the WPD Infrastructure" sections for this driver show the changes that were made to the WpdHelloWorldDriver source so that it can communicate with basic hardware devices. Before you work through the topics in this section of the documentation, be familiar with the WpdHelloWorldDriver. - -The sensor devices that are supported by the WpdBasicHardwareDriver, such as the Memsic 2125 Accelerometer, are sold by the Parallax Corporation in Rocklin, California. - -To use these sensors with the WpdBasicHardwareDriver, you must purchase the sensors, a programmable microcontroller (Parallax BS2), a test board (like the Parallax BASIC Stamp Homework Board), an RS232 cable, and miscellaneous parts. All of this hardware is available from Parallax and can be ordered through their Web site. - -The circuit designs are based on the sample circuits provided by Parallax in their sensor data sheets. These circuits are designed to integrate each sensor with the Parallax BS2 programmable microcontroller . - -The microcontroller firmware for each of the nine circuits is included in the **\\firmware** subdirectory of this sample. - -For a complete description of this sample and its underlying code and functionality, refer to the [WPD Basic Hardware Driver](https://docs.microsoft.com/windows-hardware/drivers/portable/the-wpdbasichardwaredriver-sample) description in the Windows Driver Kit documentation. - -## Related topics - -[WPD Design Guide](https://docs.microsoft.com/windows-hardware/drivers/portable/wpd-design-guide) - -[WPD Driver Development Tools](https://docs.microsoft.com/windows-hardware/drivers/portable/familiarizing-yourself-with-the-sample-driver) - -[WPD Programming Guide](https://docs.microsoft.com/windows-hardware/drivers/portable/wpd-programming-guide) - -## Installation - -To test this sample, you must have a test computer. This can be a second computer or, if necessary, your development computer. - -To install the WpdBasicHardwareDriver sample, do the following: - -1. Copy the driver binary and the wpdbasichardwaredriver.inf file to a directory on your test computer (for example, C:\\wpdbasichardwaredriver.) - -1. Copy the UMDF coinstaller, WUDFUpdate\_*MMmmmm*.dll, from the \\redist\\wdf\\\<architecture\> directory to the same directory (for example, C:\\wpdbasichardwaredriver). - - > [!NOTE] - > You can obtain the co-installers by downloading and installing the "Windows Driver Framework (WDF)" package from [WDK 8 Redistributable Components](https://go.microsoft.com/fwlink/p/?LinkID=253170). - -1. Navigate to the directory that contains the INF file and binaries (for example, cd /d c:\\wpdbasichardwaredriver), and run DevCon.exe as follows: - - `devcon.exe install wpdbasichardwaredriver.inf WUDF\WpdBasicHardware` - - You can find DevCon.exe in the \\tools directory of the WDK (for example, \\tools\\devcon\\i386\\devcon.exe). diff --git a/wpd/WpdBasicHardwareDriver/RS232Connection.cpp b/wpd/WpdBasicHardwareDriver/RS232Connection.cpp deleted file mode 100644 index eab5479b..00000000 --- a/wpd/WpdBasicHardwareDriver/RS232Connection.cpp +++ /dev/null @@ -1,316 +0,0 @@ -#include "stdafx.h" - -#include "RS232Connection.tmh" - -/*----------------------------------------------------------------------------- - -FUNCTION: RS232Connection() - -PURPOSE: Constructor. Initializes TTY structure - -COMMENTS: This structure is a collection of TTY attributes - used by all parts of this program - -HISTORY: Date: Author: Comment: - 10/27/95 AllenD Wrote it - 2/14/96 AllenD Removed npTTYInfo - 12/06/06 DonnMo Changed return value type - 12/06/06 DonnMo Replaced macro calls with member-variable settings - 12/06/06 DonnMo Removed initialization of font-related variables - ------------------------------------------------------------------------------*/ -RS232Connection::RS232Connection() -{ - // - // initialize generial TTY info - // - m_hCommPort = NULL; - m_fConnected = FALSE; - m_fLocalEcho = FALSE; - m_bPort = 1; - m_dwBaudRate = CBR_9600; - m_bByteSize = 8; - m_bParity = NOPARITY; - m_bStopBits = ONESTOPBIT; - m_fAutowrap = TRUE; - m_fNewLine = FALSE; - m_fDisplayErrors = TRUE; - - // - // timeouts - // - - // - // TimeoutsDefault - // We need ReadIntervalTimeout here to cause the read operations - // that we do to actually timeout and become overlapped. - // Specifying 1 here causes ReadFile to return very quickly - // so that our reader thread will continue execution. - // - - m_TimeoutsDefault = { 25, 0, 0, 0, 0 }; - m_timeoutsnew = m_TimeoutsDefault; - - // - // read state and status events - // - m_dwReceiveState = RECEIVE_TTY; - m_dwEventFlags = EVENTFLAGS_DEFAULT; - m_chFlag = FLAGCHAR_DEFAULT; - - // - // Flow Control Settings - // - m_fDtrControl = DTR_CONTROL_ENABLE; - m_fRtsControl = RTS_CONTROL_ENABLE; - m_chXON = ASCII_XON; - m_chXOFF = ASCII_XOFF; - m_wXONLimit = 0; - m_wXOFFLimit = 0; - m_fCTSOutFlow = FALSE; - m_fDSROutFlow = FALSE; - m_fDSRInFlow = FALSE; - m_fXonXoffOutFlow = FALSE; - m_fXonXoffInFlow = FALSE; - m_fTXafterXoffSent = FALSE; - m_fNoReading = FALSE; - m_fNoWriting = FALSE; - m_fNoEvents = FALSE; - m_fNoStatus = FALSE; - m_fDisplayTimeouts = FALSE; - -} - - -/*----------------------------------------------------------------------------- - -FUNCTION: SetPortState( void ) - -PURPOSE: Sets port state based on settings from the user - -COMMENTS: Sets up DCB structure and calls SetCommState. - Sets up new timeouts by calling SetCommTimeouts. - -HISTORY: Date: Author: Comment: - 1/9/96 AllenD Wrote it - 12/06/06 DonnMo Replaced calls to ErrorReporter() with CHECK_HR() - ------------------------------------------------------------------------------*/ -HRESULT RS232Connection::SetPortState() -{ - HRESULT hr = S_OK; - DCB dcb = {0}; - DWORD dwLastError = 0; - - dcb.DCBlength = sizeof(dcb); - - // - // get current DCB settings - // - if (!GetCommState(m_hCommPort, &dcb)) - { - dwLastError = GetLastError(); - hr = HRESULT_FROM_WIN32(dwLastError); - CHECK_HR(hr, "GetCommState() failed within SetPortState()."); - return hr; - } - - // - // update DCB rate, byte size, parity, and stop bits size - // - dcb.BaudRate = m_dwBaudRate; - dcb.ByteSize = m_bByteSize; - dcb.Parity = m_bParity; - dcb.StopBits = m_bStopBits; - - // - // update event flags - // - if (m_dwEventFlags & EV_RXFLAG) - { - dcb.EvtChar = m_chFlag; - } - else - { - dcb.EvtChar = '\0'; - } - - dcb.EofChar = '\n'; - - // - // update flow control settings - // - dcb.fDtrControl = m_fDtrControl; - dcb.fRtsControl = m_fRtsControl; - - dcb.fOutxCtsFlow = m_fCTSOutFlow; - dcb.fOutxDsrFlow = m_fDSROutFlow; - dcb.fDsrSensitivity = m_fDSRInFlow; - dcb.fOutX = m_fXonXoffOutFlow; - dcb.fInX = m_fXonXoffInFlow; - dcb.fTXContinueOnXoff = m_fTXafterXoffSent; - dcb.XonChar = m_chXON; - dcb.XoffChar = m_chXOFF; - dcb.XonLim = m_wXONLimit; - dcb.XoffLim = m_wXOFFLimit; - - // - // DCB settings not in the user's control - // - dcb.fParity = TRUE; - - // - // set new state - // - if (!SetCommState(m_hCommPort, &dcb)) - { - dwLastError = GetLastError(); - hr = HRESULT_FROM_WIN32(dwLastError); - CHECK_HR(hr, "SetCommState() failed within SetPortState() when setting the new state."); - return hr; - } - - - // - // set new timeouts - // - if (!SetCommTimeouts(m_hCommPort, &m_timeoutsnew)) - { - dwLastError = GetLastError(); - hr = HRESULT_FROM_WIN32(dwLastError); - CHECK_HR(hr, "SetCommTimeouts() failed within SetPortState() when setting the new timeouts."); - return hr; - } - - return hr; -} - - -/*----------------------------------------------------------------------------- - -FUNCTION: Connect( void ) - -PURPOSE: Setup Communication Port with our settings - -RETURN: - S_OK and handle of com port if successful - ------------------------------------------------------------------------------*/ -HRESULT RS232Connection::Connect(_In_ LPCWSTR wszPortName, _Out_ HANDLE *phCommPort) -{ - HRESULT hr = S_OK; - DWORD dwLastError = 0; - - if (phCommPort == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "A NULL phCommPort parameter was received"); - return hr; - } - - *phCommPort = NULL; - - // - // retrieve a handle for the com port - // and configure the port for asynchronous - // communications. - // - m_hCommPort = CreateFileW(wszPortName, - GENERIC_READ | GENERIC_WRITE, - 0, - 0, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, - 0); - - if (m_hCommPort == NULL) - { - dwLastError = GetLastError(); - hr = HRESULT_FROM_WIN32(dwLastError); - CHECK_HR(hr, "CreateFileW() failed in RS232Connection::Connect"); - return hr; - } - - // - // Save original comm timeouts and set new ones - // - if (!GetCommTimeouts( m_hCommPort, &(m_timeoutsorig))) - { - dwLastError = GetLastError(); - hr = HRESULT_FROM_WIN32(dwLastError); - CHECK_HR(hr, "GetCommTimeouts() failed within RS232Connection::Connect"); - return hr; - } - - // - // Set port state - // - hr = SetPortState(); - if (FAILED(hr)) - { - CHECK_HR(hr, "SetPortState() failed within RS232Connection::Connect"); - return hr; - } - - // - // set comm buffer sizes - // - if (!SetupComm(m_hCommPort, MAX_READ_BUFFER, MAX_WRITE_BUFFER)) - { - dwLastError = GetLastError(); - hr = HRESULT_FROM_WIN32(dwLastError); - CHECK_HR(hr, "SetupComm(SETDTR) failed within RS232Connection::Connect"); - return hr; - } - - // - // raise DTR - // - if (!EscapeCommFunction(m_hCommPort, SETDTR)) - { - dwLastError = GetLastError(); - hr = HRESULT_FROM_WIN32(dwLastError); - CHECK_HR(hr, "EscapeCommFunction() failed within RS232Connection::Connect"); - return hr; - } - - // - // set overall connect flag - // - m_fConnected = TRUE; - - // - // set the return value - // - *phCommPort = m_hCommPort; - - - if (SUCCEEDED(hr)) - { - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_DEVICE, "%!FUNC! handle: %p", m_hCommPort); - } - - return hr; -} - - -/*----------------------------------------------------------------------------- - -FUNCTION: Disconnect( void ) - -PURPOSE: Tears down the Communication Port - -RETURN: nothing - ------------------------------------------------------------------------------*/ -void RS232Connection::Disconnect() -{ - if (m_hCommPort != NULL) - { - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_DEVICE, "%!FUNC! handle: %p", m_hCommPort); - - CloseHandle(m_hCommPort); - m_hCommPort = NULL; - - } -}
\ No newline at end of file diff --git a/wpd/WpdBasicHardwareDriver/RS232Connection.h b/wpd/WpdBasicHardwareDriver/RS232Connection.h deleted file mode 100644 index cd7f10b7..00000000 --- a/wpd/WpdBasicHardwareDriver/RS232Connection.h +++ /dev/null @@ -1,153 +0,0 @@ -#pragma once - -// -// Sensor device structures and definitions -// - -// -// Format of the 9-byte receive packet (device to PC): -// -// ORIGINAL TEMP_SENSOR PACKET FORMAT: [ VALUE (4 bytes) | INTERVAL (5 bytes) ] -// -// Format of the multi-byte receive packet (device to PC): -// -// NEW PACKET FORMAT: [ SENSOR_ID (1 byte) | ELEMENT_COUNT (1 byte) | ELEMENT_SIZE (1 byte) | ELEMENTS (size bytes) | INTERVAL (5 bytes) ] -// COMPASS PACKET FORMAT: [ SENSOR_ID = 1 | ELEMENT_COUNT = 1 | ELEMENT_SIZE = 3 | HEADING 3-bytes | INTERVAL (5 bytes) ] -// SENSIRON PACKET FORMAT: [ SENSOR_ID = 2 | ELEMENT_COUNT = 1 | ELEMENT_SIZE = 7 | TEMP 4-bytes | HUMIDITY 3-bytes | INTERVAL (5 bytes) ] -// FLEX PACKET FORMAT: [ SENSOR_ID = 3 | ELEMENT_COUNT = 1 | ELEMENT_SIZE = 5 | PRESSURE 5-bytes | INTERVAL (5 bytes) ] -// PING PACKET FORMAT: [ SENSOR_ID = 4 | ELEMENT_COUNT = 1 | ELEMENT_SIZE = 5 | PRESSURE 5-bytes | INTERVAL (5 bytes) ] -// PIR PACKET FORMAT: [ SENSOR_ID = 5 | ELEMENT_COUNT = 1 | ELEMENT_SIZE = 1 | STATE 1-byte | INTERVAL (5 bytes) ] -// MEMSIC PACKET FORMAT: [ SENSOR_ID = 6 | ELEMENT_COUNT = 1 | ELEMENT_SIZE = 6 | X-Axis Gs 3-bytes | Y-Axis Gs 3-bytes | INTERVAL (5 bytes) ] -// QTI PACKET FORMAT: [ SENSOR_ID = 7 | ELEMENT_COUNT = 1 | ELEMENT_SIZE = 4 | PRESSURE 4-bytes | INTERVAL (5 bytes) ] -// PIEZO PACKET FORMAT: [ SENSOR_ID = 8 | ELEMENT_COUNT = 1 | ELEMENT_SIZE = 1 | STATE 1-byte | INTERVAL (5 bytes) -// HITACHI PACKET FORMAT: [ SENSOR_ID = 9 | ELEMENT_COUNT = 3 | ELEMENT_SIZE = 4 | X-Axis Gs 4-bytes | Y-Axis Gs 4-bytes | Z-Axis Gs 4-bytes | INTERVAL (5 bytes) ] -// -// -// Format of the 6-byte send packet (PC to device): -// The final NULL byte signals the SERIN DEC formatter to stop reading -// -// [ INTERVAL (5 bytes) | 0 (1 byte) ] -// -#define INTERVAL_DATA_LENGTH 6 // count of bytes for interval -#define MIN_DATA_LENGTH 4 // minimum count of bytes for any sensor -#define MAX_DATA_LENGTH 21 // maximum count of bytes for any sensor -#define MAX_AMOUNT_TO_READ (MAX_DATA_LENGTH+INTERVAL_DATA_LENGTH) // maximum total bytes to read - -#define MEMSIC_DATA_LENGTH 9 // count of data bytes for Memsic dual-axis accelerometer -#define HITACHI_DATA_LENGTH 15 // count of data bytes for Hitachi tri-axis accelerometer -#define COMPASS_DATA_LENGTH 6 // count of data bytes for Compass -#define SENSIRON_DATA_LENGTH 10 // count of data bytes for Sensiron temp/humidity sensor -#define PING_DATA_LENGTH 8 // count of data bytes for Ping distance sensor -#define FLEX_DATA_LENGTH 8 // count of data bytes for Flexiforce pressure sensor -#define PIR_DATA_LENGTH 4 // count of data bytes for PIR -#define QTI_DATA_LENGTH 7 // count of data bytes for QTI -#define PIEZO_DATA_LENGTH 4 // count of data bytes for Piezo - -#define MEMSIC_AMOUNT_TO_READ (MEMSIC_DATA_LENGTH+INTERVAL_DATA_LENGTH) // total Memsic byte count -#define HITACHI_AMOUNT_TO_READ (HITACHI_DATA_LENGTH+INTERVAL_DATA_LENGTH) // total Hitachi byte count -#define COMPASS_AMOUNT_TO_READ (COMPASS_DATA_LENGTH+INTERVAL_DATA_LENGTH) // total Compass byte count -#define SENSIRON_AMOUNT_TO_READ (SENSIRON_DATA_LENGTH+INTERVAL_DATA_LENGTH) // total Sensiron byte count -#define PING_AMOUNT_TO_READ (PING_DATA_LENGTH+INTERVAL_DATA_LENGTH) // total Ping byte count -#define FLEX_AMOUNT_TO_READ (FLEX_DATA_LENGTH+INTERVAL_DATA_LENGTH) // total Flexiforce byte count -#define PIR_AMOUNT_TO_READ (PIR_DATA_LENGTH+INTERVAL_DATA_LENGTH) // total PIR byte count -#define QTI_AMOUNT_TO_READ (QTI_DATA_LENGTH+INTERVAL_DATA_LENGTH) // total QTI byte count -#define PIEZO_AMOUNT_TO_READ (PIEZO_DATA_LENGTH+INTERVAL_DATA_LENGTH) // total Piezo byte count - -#define DEVICE_ID 0 // byte 0 contains the Device ID -#define ELEMENT_SIZE 1 // byte 1 contains the Element Size -#define ELEMENT_COUNT 2 // byte 2 contains the Element Count - -// Update interval range in milliseconds -#define SENSOR_UPDATE_INTERVAL_MIN 10 // milliseconds -#define SENSOR_UPDATE_INTERVAL_MAX 60000 // milliseconds -#define SENSOR_UPDATE_INTERVAL_STEP 1 // milliseconds - -// TODO: Change these range values to match your sensor hardware -#define SENSOR_READING_MIN 1 // ?Units -#define SENSOR_READING_MAX 378 // ?Units -#define SENSOR_READING_STEP 1 // ?Units - -// TODO: Change this to match the default COM port to use -#define COM_PORT_NAME L"COM1" -#define NUM_READSTAT_HANDLES 4 -#define MAX_STATUS_LENGTH 100 - -// Ascii definitions -#define ASCII_BEL 0x07 -#define ASCII_BS 0x08 -#define ASCII_LF 0x0A -#define ASCII_CR 0x0D -#define ASCII_XON 0x11 -#define ASCII_XOFF 0x13 - -// Miscellaneous definitions -#define MAX_READ_BUFFER 2048 -#define MAX_WRITE_BUFFER 1024 -#define EVENTFLAGS_DEFAULT EV_BREAK | EV_CTS | EV_DSR | EV_ERR | EV_RING | EV_RLSD -#define FLAGCHAR_DEFAULT '\n' - -// Read states -#define RECEIVE_TTY 0x01 -#define RECEIVE_CAPTURED 0x02 - -class RS232Connection -{ - -public: - RS232Connection(); - - ~RS232Connection() - { - Disconnect(); - } - - HRESULT Connect(_In_ LPCWSTR wszPortName, _Out_ HANDLE *phCommPort); - void Disconnect(); - -private: - HRESULT SetPortState(); - -private: - - // - // Required for the RS232 initialization and communication. - // - - // TTY member variables and defines - HANDLE m_hCommPort; - DWORD m_dwEventFlags; - CHAR m_chFlag; - CHAR m_chXON; - CHAR m_chXOFF; - WORD m_wXONLimit; - WORD m_wXOFFLimit; - DWORD m_fRtsControl; - DWORD m_fDtrControl; - BOOL m_fConnected; - BOOL m_fTransferring; - BOOL m_fRepeating; - BOOL m_fLocalEcho; - BOOL m_fNewLine; - BOOL m_fDisplayErrors; - BOOL m_fAutowrap; - BOOL m_fCTSOutFlow; - BOOL m_fDSROutFlow; - BOOL m_fDSRInFlow; - BOOL m_fXonXoffOutFlow; - BOOL m_fXonXoffInFlow; - BOOL m_fTXafterXoffSent; - BOOL m_fNoReading; - BOOL m_fNoWriting; - BOOL m_fNoEvents; - BOOL m_fNoStatus; - BOOL m_fDisplayTimeouts; - BYTE m_bPort; - BYTE m_bByteSize; - BYTE m_bParity; - BYTE m_bStopBits; - DWORD m_dwBaudRate; - COMMTIMEOUTS m_timeoutsorig; - COMMTIMEOUTS m_timeoutsnew; - COMMTIMEOUTS m_TimeoutsDefault; - DWORD m_dwReceiveState; -};
\ No newline at end of file diff --git a/wpd/WpdBasicHardwareDriver/RS232Target.cpp b/wpd/WpdBasicHardwareDriver/RS232Target.cpp deleted file mode 100644 index bedfecd2..00000000 --- a/wpd/WpdBasicHardwareDriver/RS232Target.cpp +++ /dev/null @@ -1,433 +0,0 @@ -#include "stdafx.h" - -#include "RS232Target.tmh" - -RS232Target::RS232Target() : - m_cRef(1), m_pBaseDriver(NULL) -{ -} - -RS232Target::~RS232Target() -{ - Delete(); -} - -ULONG __stdcall RS232Target::AddRef() -{ - InterlockedIncrement((long*) &m_cRef); - return m_cRef; -} - -ULONG __stdcall RS232Target::Release() -{ - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; -} - -HRESULT __stdcall RS232Target::QueryInterface( - REFIID riid, - void** ppv) -{ - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - if(riid == __uuidof(IRequestCallbackRequestCompletion)) - { - *ppv = static_cast<IRequestCallbackRequestCompletion*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - return hr; -} - - - -/** - * This method is called to initialize the RS232 I/O Target - */ -HRESULT RS232Target::Create(_In_ WpdBaseDriver* pBaseDriver, - _In_ IWDFDevice* pDevice, - HANDLE hRS232Port) -{ - CComPtr<IWDFFileHandleTargetFactory> pFileHandleTargetFactory; - - HRESULT hr = S_OK; - - if (pDevice == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "NULL parameter received for IWDFDevice"); - return hr; - } - - m_pWDFDevice = pDevice; - m_pBaseDriver = pBaseDriver; - - hr = m_pWDFDevice->QueryInterface(IID_PPV_ARGS(&pFileHandleTargetFactory)); - CHECK_HR(hr, "QI of IID_IWDFFileHandleTargetFactory failed"); - - if (hr == S_OK) - { - hr = pFileHandleTargetFactory->CreateFileHandleTarget(hRS232Port, &m_pFileTarget); - CHECK_HR(hr, "Failed to create an I/O Target for the port file handle"); - } - - if (hr == S_OK) - { - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_DEVICE, - "%!FUNC! Created win32 I/O target %p for handle %p", m_pFileTarget, hRS232Port); - } - - return hr; -} - -/** - * This method is called to remove the RS232 I/O Target object - * and do any cleanup - */ -void RS232Target::Delete() -{ - if (m_pFileTarget) - { - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_DEVICE, - "%!FUNC! Deleted win32 I/O target %p", m_pFileTarget); - m_pFileTarget = NULL; - } - - if (m_pWDFDevice) - { - m_pWDFDevice = NULL; - } - - if (m_pBaseDriver) - { - m_pBaseDriver = NULL; - } -} - -/** - * This method is called to start the RS232 I/O Target after it - * it has been created - */ -HRESULT RS232Target::Start() -{ - CComPtr<IWDFIoTargetStateManagement> pStateMgmt; - - HRESULT hr = S_OK; - - if (m_pFileTarget) - { - hr = m_pFileTarget->QueryInterface(IID_PPV_ARGS(&pStateMgmt)); - CHECK_HR(hr, "Failed to QI IWDFIoTargetStateManagement from the I/O target"); - - if (hr == S_OK) - { - hr = pStateMgmt->Start(); - CHECK_HR(hr, "Failed to start the I/O target"); - } - - if (hr == S_OK && IsReady()) - { - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_DEVICE, "%!FUNC! I/O target ready. Sending read request"); - hr = SendReadRequest(); - CHECK_HR(hr, "SendReadRequest failed"); - } - } - return hr; -} - -/** - * This method is called to stop the RS232 I/O Target - * if it is currently running - */ -HRESULT RS232Target::Stop() -{ - CComPtr<IWDFIoTargetStateManagement> pStateMgmt; - - HRESULT hr = S_OK; - - // Stop the target only if it is started. - if (m_pFileTarget && (WdfIoTargetStarted == GetState())) - { - hr = m_pFileTarget->QueryInterface(IID_PPV_ARGS(&pStateMgmt)); - CHECK_HR(hr, "Failed to QI IWDFIoTargetStateManagement from the I/O target"); - - if (hr == S_OK) - { - // Stop the target, and cancel sent I/O - hr = pStateMgmt->Stop(WdfIoTargetCancelSentIo); - CHECK_HR(hr, "Failed to stop the I/O target"); - } - - if (hr == S_OK) - { - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_DEVICE, "%!FUNC! S_OK"); - } - } - return hr; -} - -/** - * This method is called to return the current state of the RS232 I/O Target - */ -WDF_IO_TARGET_STATE RS232Target::GetState() -{ - CComPtr<IWDFIoTargetStateManagement> pStateMgmt; - - WDF_IO_TARGET_STATE State = WdfIoTargetStateUndefined; - HRESULT hr = S_OK; - - if (m_pFileTarget) - { - hr = m_pFileTarget->QueryInterface(IID_PPV_ARGS(&pStateMgmt)); - CHECK_HR(hr, "Failed to QI IWDFIoTargetStateManagement from the I/O target"); - - if (hr == S_OK) - { - State = pStateMgmt->GetState(); - } - } - return State; -} - - -/** - * This method returns TRUE is the target is ready to receive requests - */ -BOOL RS232Target::IsReady() -{ - if (WdfIoTargetStarted == GetState()) - { - return TRUE; - } - return FALSE; -} - - -/** - * This method is called to dispatch an asynchronous read request to the RS232 I/O Target - * with a completion callback - */ -HRESULT RS232Target::SendReadRequest() -{ - CComPtr<IWDFDriver> pWdfDriver; - CComPtr<IWDFFile> pWdfFile; - CComPtr<IWDFMemory> pWdfBuffer; - CComPtr<IWDFIoRequest> pWdfReadRequest; - CComPtr<IRequestCallbackRequestCompletion> pCompletionCallback; - - HRESULT hr = S_OK; - - if (m_pWDFDevice == NULL || m_pFileTarget == NULL) - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_READY); - CHECK_HR(hr, "Device is not ready to receive read requests"); - return hr; - } - - m_pWDFDevice->GetDriver(&pWdfDriver); - - ZeroMemory((void*)m_pReadBuffer, sizeof(m_pReadBuffer)); - - // Create the WDF memory buffer - hr = pWdfDriver->CreatePreallocatedWdfMemory(m_pReadBuffer, - sizeof(m_pReadBuffer), - NULL, // no object event callback - NULL, // driver object as parent - &pWdfBuffer); - CHECK_HR(hr, "Failed to create the pre-allocaed WDF memory"); - - if (hr == S_OK) - { - hr = m_pWDFDevice->CreateRequest(NULL, // no object event callback - m_pWDFDevice, // device object as parent - &pWdfReadRequest); - - CHECK_HR(hr, "Failed to create a WDF request"); - } - - if (hr == S_OK) - { - // Format the read request - m_pFileTarget->GetTargetFile(&pWdfFile); - - hr = m_pFileTarget->FormatRequestForRead(pWdfReadRequest, - pWdfFile, - pWdfBuffer, - NULL, // no memory offset - NULL); // no device offset - - CHECK_HR(hr, "Failed to format the WDF request for read"); - } - - if (hr == S_OK) - { - this->QueryInterface(IID_PPV_ARGS(&pCompletionCallback)); - - // Set the completion callback - pWdfReadRequest->SetCompletionCallback(pCompletionCallback, NULL); - - hr = pWdfReadRequest->Send(m_pFileTarget, 0, 0); - CHECK_HR(hr, "Failed to send the read request"); - } - - if (FAILED(hr)) - { - // Cleanup on failure - if (pWdfReadRequest) - { - pWdfReadRequest->DeleteWdfObject(); - } - } - - return hr; -} - - -/** - * This method is called to dispatch an asynchronous write request to the RS232 I/O Target - * with a completion callback - */ -HRESULT RS232Target::SendWriteRequest( - _In_reads_(cbBufferSize) BYTE* pBuffer, - size_t cbBufferSize) -{ - CComPtr<IWDFDriver> pWdfDriver; - CComPtr<IWDFFile> pWdfFile; - CComPtr<IWDFMemory> pWdfBuffer; - CComPtr<IWDFIoRequest> pWdfWriteRequest; - CComPtr<IRequestCallbackRequestCompletion> pCompletionCallback; - - HRESULT hr = S_OK; - - if (pBuffer == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "A NULL buffer parameter was received"); - return hr; - } - - if (m_pWDFDevice == NULL || m_pFileTarget == NULL) - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_READY); - CHECK_HR(hr, "Device is not ready to receive write requests"); - } - - m_pWDFDevice->GetDriver(&pWdfDriver); - m_pFileTarget->GetTargetFile(&pWdfFile); - - // Create the WDF memory buffer - hr = pWdfDriver->CreatePreallocatedWdfMemory(pBuffer, - cbBufferSize, - NULL, // no object event callback - NULL, // driver object as parent - &pWdfBuffer); - CHECK_HR(hr, "Failed to create a pre-allocaed Wdf memory buffer from the input buffer of size %d", static_cast<DWORD>(cbBufferSize)); - - if (hr == S_OK) - { - hr = m_pWDFDevice->CreateRequest(NULL, // no object event callback - m_pWDFDevice, // device object as parent - &pWdfWriteRequest); - - CHECK_HR(hr, "Failed to create a WDF request"); - } - - if (hr == S_OK) - { - hr = m_pFileTarget->FormatRequestForWrite(pWdfWriteRequest, - pWdfFile, - pWdfBuffer, - NULL, // no memory offset - NULL); // no device offset - - CHECK_HR(hr, "Failed to format the WDF request for write"); - } - - if (hr == S_OK) - { - this->QueryInterface(IID_PPV_ARGS(&pCompletionCallback)); - - // Set the completion callback - pWdfWriteRequest->SetCompletionCallback(pCompletionCallback, NULL); - - hr = pWdfWriteRequest->Send(m_pFileTarget, 0, 0); - CHECK_HR(hr, "Failed to send the write request"); - } - - if (FAILED(hr)) - { - // Cleanup on failure - if (pWdfWriteRequest) - { - pWdfWriteRequest->DeleteWdfObject(); - } - } - - return hr; -} - - -/** - * This callback method is called by UMDF on the completion of the asynchronous reads and writes - */ -void RS232Target::OnCompletion( - _In_ IWDFIoRequest* pWdfRequest, - _In_ IWDFIoTarget* pIoTarget, - _In_ IWDFRequestCompletionParams* pParams, - _In_ PVOID pContext) -{ - UNREFERENCED_PARAMETER(pIoTarget); - UNREFERENCED_PARAMETER(pContext); - UNREFERENCED_PARAMETER(pParams); - - CComPtr<IWDFRequestCompletionParams> pCompletionParams; - HRESULT hr = S_OK; - - // Get the request completion status - pWdfRequest->GetCompletionParams(&pCompletionParams); - - HRESULT hrStatus = pCompletionParams->GetCompletionStatus(); - WDF_REQUEST_TYPE RequestType = pCompletionParams->GetCompletedRequestType(); - - if (RequestType == WdfRequestRead) - { - TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_FLAG_DEVICE, "%!FUNC! Read Status %!HRESULT!", hrStatus); - - // Retrieve the data from the completed read request if successful - if (SUCCEEDED(hrStatus) && m_pBaseDriver) - { - m_pBaseDriver->ProcessReadData(m_pReadBuffer, sizeof(m_pReadBuffer)); - } - - // Send another read request if the target is not stopped or removed - if (IsReady()) - { - hr = SendReadRequest(); - CHECK_HR(hr, "SendReadRequest failed"); - } - - - } - else if (RequestType == WdfRequestWrite) - { - TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_FLAG_DEVICE, "%!FUNC! Write Status %!HRESULT!", hrStatus); - } - - // Clean up the existing request - pWdfRequest->DeleteWdfObject(); -} diff --git a/wpd/WpdBasicHardwareDriver/RS232Target.h b/wpd/WpdBasicHardwareDriver/RS232Target.h deleted file mode 100644 index b4754639..00000000 --- a/wpd/WpdBasicHardwareDriver/RS232Target.h +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -class RS232Target : - public IRequestCallbackRequestCompletion -{ -public: - RS232Target(); - - ~RS232Target(); - - HRESULT Create(_In_ WpdBaseDriver* pBaseDriver, - _In_ IWDFDevice* pDevice, - HANDLE hRS232Port); - - void Delete(); - - HRESULT Start(); - - HRESULT Stop(); - - BOOL IsReady(); - - WDF_IO_TARGET_STATE GetState(); - - HRESULT SendReadRequest(); - - HRESULT SendWriteRequest(_In_reads_(cbBufferSize) BYTE* pBuffer, - size_t cbBufferSize); - -public: // IUnknown - ULONG __stdcall AddRef(); - ULONG __stdcall Release(); - HRESULT __stdcall QueryInterface(REFIID riid, void** ppv); - - // - // IRequestCallbackRequestCompletion - // - STDMETHOD_ (void, OnCompletion)(_In_ IWDFIoRequest* pWdfRequest, - _In_ IWDFIoTarget* pIoTarget, - _In_ IWDFRequestCompletionParams* pParams, - _In_ PVOID pContext); - -private: - ULONG m_cRef; - - WpdBaseDriver* m_pBaseDriver; - - // Ensure ample buffer size - BYTE m_pReadBuffer[MAX_AMOUNT_TO_READ*2]; - - CComPtr<IWDFDevice> m_pWDFDevice; - CComPtr<IWDFIoTarget> m_pFileTarget; -};
\ No newline at end of file diff --git a/wpd/WpdBasicHardwareDriver/Stdafxsrc.cpp b/wpd/WpdBasicHardwareDriver/Stdafxsrc.cpp deleted file mode 100644 index 5105a28d..00000000 --- a/wpd/WpdBasicHardwareDriver/Stdafxsrc.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Stdafx.h"
\ No newline at end of file diff --git a/wpd/WpdBasicHardwareDriver/WpdBaseDriver.cpp b/wpd/WpdBasicHardwareDriver/WpdBaseDriver.cpp deleted file mode 100644 index cf1665c2..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdBaseDriver.cpp +++ /dev/null @@ -1,506 +0,0 @@ -#include "stdafx.h" - -#include "WpdBaseDriver.tmh" - - -WpdBaseDriver::WpdBaseDriver() : - m_cRef(1) -{ -} - -WpdBaseDriver::~WpdBaseDriver() -{ -} - -ULONG __stdcall WpdBaseDriver::AddRef() -{ - InterlockedIncrement((long*) &m_cRef); - return m_cRef; -} - -_At_(this, __drv_freesMem(Mem)) -ULONG __stdcall WpdBaseDriver::Release() -{ - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; -} - -HRESULT __stdcall WpdBaseDriver::QueryInterface( - REFIID riid, - void** ppv) -{ - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - return hr; -} - -RS232Target* WpdBaseDriver::GetRS232Target() -{ - return &m_Target; -} - -HRESULT WpdBaseDriver::DispatchWpdMessage(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidCommandCategory = {0}; - DWORD dwCommandID = 0; - PROPERTYKEY CommandKey = WPD_PROPERTY_NULL; - - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, &guidCommandCategory); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_CATEGORY from input parameters"); - } - - if (hr == S_OK) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, &dwCommandID); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_ID from input parameters"); - } - - // If WPD_PROPERTY_COMMON_COMMAND_CATEGORY or WPD_PROPERTY_COMMON_COMMAND_ID could not be extracted - // properly then we should return E_INVALIDARG to the client. - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_CATEGORY or WPD_PROPERTY_COMMON_COMMAND_ID from input parameters"); - } - - if (hr == S_OK) - { - CommandKey.fmtid = guidCommandCategory; - CommandKey.pid = dwCommandID; - - if (CommandKey.fmtid == WPD_CATEGORY_OBJECT_ENUMERATION) - { - hr = m_ObjectEnum.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_OBJECT_PROPERTIES) - { - hr = m_ObjectProperties.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_CAPABILITIES) - { - hr = m_Capabilities.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (IsEqualPropertyKey(CommandKey, WPD_COMMAND_COMMON_GET_OBJECT_IDS_FROM_PERSISTENT_UNIQUE_IDS)) - { - hr = OnGetObjectIDsFromPersistentUniqueIDs(pParams, pResults); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "Unknown command %ws.%d received",CComBSTR(CommandKey.fmtid), CommandKey.pid); - } - } - - HRESULT hrTemp = pResults->SetErrorValue(WPD_PROPERTY_COMMON_HRESULT, hr); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_COMMON_HRESULT")); - - // Set to a success code, to indicate that the message was received. - // the return code for the actual command's results is stored in the - // WPD_PROPERTY_COMMON_HRESULT property. - hr = S_OK; - - return hr; -} - -/** - * This method is called to initialize the driver object. - * This is where the driver establishes a connection with the - * COM port, creates the IoTarget to forward read/write requests to, and - * starts the thread which monitors these events. - */ -HRESULT WpdBaseDriver::Initialize(_In_ IWDFDevice* pDevice) -{ - HRESULT hr = S_OK; - HANDLE hPort = NULL; - - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_DRIVER, "%!FUNC! Entry"); - - if (pDevice == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "A NULL IWDFDevice parameter was received."); - return hr; - } - - // Save the WDF device instance - m_pWDFDevice = pDevice; - m_ObjectProperties.Initialize(this); - m_ObjectEnum.Initialize(this); - - // Initialize the Wpd Serializer for posting events - hr = CoCreateInstance(CLSID_WpdSerializer, - NULL, - CLSCTX_INPROC_SERVER, - IID_IWpdSerializer, - (VOID**)&m_pWpdSerializer); - - CHECK_HR(hr, "Failed to CoCreate the Wpd Serializer."); - - - // Initialize a handle to the RS232 connection - hr = m_Connection.Connect(COM_PORT_NAME, &hPort); - CHECK_HR(hr, "Failed to connect to port: %ws", COM_PORT_NAME); - - // Initialize the IoTarget to wrap the opened handle - if (hr == S_OK) - { - hr = m_Target.Create(this, pDevice, hPort); - CHECK_HR(hr, "Failed to create the port I/O target."); - } - - return hr; -} - -/** - * This method is called to uninitialize the driver object. - * This is where the driver disables the connection with the - * COM port and performs the necessary cleanup. - */ -void WpdBaseDriver::Uninitialize() -{ - TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_FLAG_DRIVER, "%!FUNC! Entry"); - - m_Target.Delete(); - m_Connection.Disconnect(); - - m_pWDFDevice = NULL; -} - -/** - * This method is called to extract the sensor data and interval prop from the raw serial buffer - * and to post a new reading PnP event if valid data is received - */ -HRESULT WpdBaseDriver::ProcessReadData(_In_reads_(cbData) BYTE* pData, size_t cbData) -{ - HRESULT hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); - LONGLONG llSensorReading = 0; // was originally DWORD but the accelerometers required addt'l bytes - DWORD dwUpdateInterval = 0; - - // Parse the serial data - CHAR szInterval[INTERVAL_DATA_LENGTH + 1] = {0}; // last byte is always null - CHAR* szReading = NULL; // buffer containing the reading - - const SENSOR_INFO c_SensorInfoTable [] = { - {'1', COMPASS_DATA_LENGTH}, // Compass - {'2', SENSIRON_DATA_LENGTH}, // Temp/humidity sensor - {'3', FLEX_DATA_LENGTH}, // Flexiforce sensor - {'4', PING_DATA_LENGTH}, // Ultrasonic ping - {'5', PIR_DATA_LENGTH}, // Passive infrared - {'6', MEMSIC_DATA_LENGTH}, // 2-axis accelerometer - {'7', QTI_DATA_LENGTH}, // Light sensor - {'8', PIEZO_DATA_LENGTH}, // Vibration Sensor - {'9', HITACHI_DATA_LENGTH}, // 3-axis accelerometer - }; - - // Allocate the necessary bytes for collecting the sensor data. - // We'll examine the DEVICE_ID field of the batched serial data and allocate - // the necessary bytes accordingly... - // This is also where we set the sensor identifier and related properties). - - if (cbData > DEVICE_ID) - { - switch (pData[DEVICE_ID]){ - case '1': - m_SensorType = COMPASS; - szReading = (CHAR *)malloc(COMPASS_DATA_LENGTH + 1); // last byte is always null - hr = S_OK; - break; - case '2': - m_SensorType = SENSIRON; - szReading = (CHAR *)malloc(SENSIRON_DATA_LENGTH + 1); // last byte is always null - hr = S_OK; - break; - case '3': - m_SensorType = FLEX; - szReading = (CHAR *)malloc(FLEX_DATA_LENGTH + 1); // last byte is always null - hr = S_OK; - break; - case '4': - m_SensorType = PING; - szReading = (CHAR *)malloc(PING_DATA_LENGTH + 1); // last byte is always null - hr = S_OK; - break; - case '5': - m_SensorType = PIR; - szReading = (CHAR *)malloc(PIR_DATA_LENGTH + 1); // last byte is always null - hr = S_OK; - break; - case '6': - m_SensorType = MEMSIC; - szReading = (CHAR *)malloc(MEMSIC_AMOUNT_TO_READ + 1); // last byte is always null - hr = S_OK; - break; - case '7': - m_SensorType = QTI; - szReading = (CHAR *)malloc(QTI_DATA_LENGTH + 1); // last byte is always null - hr = S_OK; - break; - case '8': - m_SensorType = PIEZO; - szReading = (CHAR *)malloc(PIEZO_DATA_LENGTH + 1); // last byte is always null - hr = S_OK; - break; - case '9': - m_SensorType = HITACHI; - szReading = (CHAR *)malloc(HITACHI_DATA_LENGTH + 1); // last byte is always null - hr = S_OK; - break; - default: - break; - } - } - - if ((hr == S_OK) && (szReading == NULL)) - { - hr = E_OUTOFMEMORY; - } - - // Ensure we have sufficient input buffer size, and, if we do - // process the data for the given sensor. - if (hr == S_OK && (cbData >= (INTERVAL_DATA_LENGTH + MIN_DATA_LENGTH))) - { - for (int i=0; i<ARRAYSIZE(c_SensorInfoTable); i++) - { - if (pData[DEVICE_ID] == c_SensorInfoTable[i].deviceID) - { - memcpy((void*)szReading, (void*)pData, c_SensorInfoTable[i].dataLength); - szReading[c_SensorInfoTable[i].dataLength] = '\0'; // ensure null termination - llSensorReading = _atoi64(szReading); - hr = (errno == ERANGE) ? HRESULT_FROM_WIN32(ERROR_INVALID_DATA) : S_OK; - if (hr == S_OK) - { - // Process the Interval data - memcpy((void*)szInterval, (void*)(pData+c_SensorInfoTable[i].dataLength), INTERVAL_DATA_LENGTH); - szInterval[INTERVAL_DATA_LENGTH] = '\0'; // ensure null termination - dwUpdateInterval = atoi(szInterval); - hr = (errno == ERANGE) ? HRESULT_FROM_WIN32(ERROR_INVALID_DATA) : S_OK; - } - break; - } - } - } - - if (hr == S_OK) - { - // Post the Updated PnP event so applications receive the notification - hr = PostSensorReadingEvent(llSensorReading, dwUpdateInterval); - CHECK_HR(hr, "Failed to post a sensor reading event"); - - // If the cached interval has not yet been initialized, set to the value returned from the device - if (m_ObjectProperties.GetUpdateInterval() == 0) - { - m_ObjectProperties.SetUpdateInterval(dwUpdateInterval); - } - - // Update the sensor reading property for the sensor functional object - m_ObjectProperties.SetSensorReading(llSensorReading); - } - - if (szReading) - { - // Free the bytes allocated with malloc() - free(szReading); - } - - return hr; -} - -/** - * This method is called to send a device event with - * the new sensor data - */ -HRESULT WpdBaseDriver::PostSensorReadingEvent( - LONGLONG llSensorData, - DWORD dwUpdateInterval) -{ - HRESULT hr = S_OK; - BYTE* pBuffer = NULL; - DWORD cbBuffer = 0; - - CComPtr<IPortableDeviceValues> pEventParams; - - TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_FLAG_DRIVER, "%!FUNC! Reading: %I64d, Interval: %d", llSensorData, dwUpdateInterval); - - // Create the event parameters collection if it doesn't exist - if (m_pEventParams == NULL) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&m_pEventParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - // Initialize the event parameters - m_pEventParams->Clear(); - - // Populate the event parameters - hr = m_pEventParams->SetGuidValue(WPD_EVENT_PARAMETER_EVENT_ID, EVENT_SENSOR_READING_UPDATED); - CHECK_HR(hr, "Failed to set the WPD_EVENT_PARAMETER_EVENT_ID"); - } - - if (hr == S_OK) - { - //hr = m_pEventParams->SetUnsignedIntegerValue(SENSOR_READING, dwTemperatureData); - hr = m_pEventParams->SetUnsignedLargeIntegerValue(SENSOR_READING, llSensorData); - CHECK_HR(hr, "Failed to set the sensor reading"); - } - - if (hr == S_OK) - { - hr = m_pEventParams->SetUnsignedIntegerValue(SENSOR_UPDATE_INTERVAL, dwUpdateInterval); - CHECK_HR(hr, "Failed to set the sensor update interval"); - } - - if (hr == S_OK) - { - // Create a buffer with the serialized parameters - hr = m_pWpdSerializer->GetBufferFromIPortableDeviceValues(m_pEventParams, &pBuffer, &cbBuffer); - CHECK_HR(hr, "Failed to get buffer from IPortableDeviceValues"); - } - - // Send the event - if (hr == S_OK && pBuffer != NULL) - { - hr = m_pWDFDevice->PostEvent(WPD_EVENT_NOTIFICATION, WdfEventBroadcast, pBuffer, cbBuffer); - CHECK_HR(hr, "Failed to post the WPD broadcast event"); - } - - // Free the memory - CoTaskMemFree(pBuffer); - pBuffer = NULL; - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_COMMON_GET_OBJECT_IDS_FROM_PERSISTENT_UNIQUE_IDS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS: Contains an IPortableDevicePropVariantCollection of VT_LPWSTR, - * indicating the PersistentUniqueIDs. - * - * The driver should: - * - Iterate through the PersistentUniqueIDs, and convert to a currently valid object id. - * This object ID list should be returned as an IPortableDevicePropVariantCollection of VT_LPWSTR - * in WPD_PROPERTY_COMMON_OBJECT_IDS. - * Order is implicit, i.e. the first element in the Persistent Unique ID list corresponds to the - * to the first element of the ObjectID list and so on. - * - * For those elements where an existing ObjectID could not be found (e.g. the - * object is no longer present on the device), the element will contain the - * empty string (L""). - */ -HRESULT WpdBaseDriver::OnGetObjectIDsFromPersistentUniqueIDs( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - - HRESULT hr = S_OK; - DWORD dwCount = 0; - CComPtr<IPortableDevicePropVariantCollection> pPersistentIDs; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - - if((pParams == NULL) || - (pResults == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Get the list of Persistent IDs - if (hr == S_OK) - { - hr = pParams->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS, &pPersistentIDs); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS"); - } - - // Create the collection to hold the ObjectIDs - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pObjectIDs); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Iterate through the persistent ID list and add the equivalent object ID for each element. - if (hr == S_OK) - { - hr = pPersistentIDs->GetCount(&dwCount); - CHECK_HR(hr, "Failed to get count from persistent ID collection"); - - if (hr == S_OK) - { - DWORD dwIndex = 0; - PROPVARIANT pvPersistentID = {0}; - PROPVARIANT pvObjectID = {0}; - - PropVariantInit(&pvPersistentID); - PropVariantInit(&pvObjectID); - - for(dwIndex = 0; dwIndex < dwCount; dwIndex++) - { - pvObjectID.vt = VT_LPWSTR; - hr = pPersistentIDs->GetAt(dwIndex, &pvPersistentID); - CHECK_HR(hr, "Failed to get persistent ID at index %d", dwIndex); - - // Since our persistent unique identifier are identical to our object - // identifiers, we just return it back to the caller. - if (hr == S_OK) - { - pvObjectID.pwszVal = AtlAllocTaskWideString(pvPersistentID.pwszVal); - } - - if (hr == S_OK) - { - hr = pObjectIDs->Add(&pvObjectID); - CHECK_HR(hr, "Failed to add next Object ID"); - } - - PropVariantClear(&pvPersistentID); - PropVariantClear(&pvObjectID); - - if(FAILED(hr)) - { - break; - } - } - } - } - - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_COMMON_OBJECT_IDS, pObjectIDs); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_COMMON_OBJECT_IDS"); - } - - return hr; -} diff --git a/wpd/WpdBasicHardwareDriver/WpdBaseDriver.h b/wpd/WpdBasicHardwareDriver/WpdBaseDriver.h deleted file mode 100644 index 13dd4694..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdBaseDriver.h +++ /dev/null @@ -1,69 +0,0 @@ -#pragma once - -typedef struct tagSENSOR_INFO{ - unsigned char deviceID; - unsigned short dataLength; -} SENSOR_INFO; - -class WpdBaseDriver : - public IUnknown -{ -public: - WpdBaseDriver(); - virtual ~WpdBaseDriver(); - - HRESULT Initialize(_In_ IWDFDevice *pDevice); - void Uninitialize(); - - HRESULT DispatchWpdMessage(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT ProcessReadData(_In_reads_(cbData) BYTE* pData, size_t cbData); - - RS232Target* GetRS232Target(); - -public: // IUnknown - ULONG __stdcall AddRef(); - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release(); - - HRESULT __stdcall QueryInterface(REFIID riid, void** ppv); - -private: - HRESULT OnGetObjectIDsFromPersistentUniqueIDs(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT PostSensorReadingEvent(LONGLONG llSensorData, DWORD dwUpdateInterval); - -public: - - enum SensorType{ - UNKNOWN, // Unknown - COMPASS, // Compass - SENSIRON, // Temp/humidity sensor - FLEX, // Flexiforce sensor - PING, // Ultrasonic ping - PIR, // Passive infrared - MEMSIC, // 2-axis accelerometer - QTI, // Light sensor - PIEZO, // Vibration Sensor - HITACHI, // 3-axis accelerometer - }; - - SensorType m_SensorType; // enum value specifying sensor type - -private: - WpdObjectEnumerator m_ObjectEnum; - WpdObjectProperties m_ObjectProperties; - WpdCapabilities m_Capabilities; - - ULONG m_cRef; - RS232Connection m_Connection; - RS232Target m_Target; - - CComPtr<IWDFDevice> m_pWDFDevice; - CComPtr<IWpdSerializer> m_pWpdSerializer; - CComPtr<IPortableDeviceValues> m_pEventParams; -}; - diff --git a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.cpp b/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.cpp deleted file mode 100644 index 2620e909..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "stdafx.h" - -#include "WpdBasicHardwareDriver.tmh" - -HINSTANCE g_hInstance = NULL; - -class CWpdBasicHardwareDriverModule : public CAtlDllModuleT< CWpdBasicHardwareDriverModule > -{ -public : - DECLARE_REGISTRY_APPID_RESOURCEID(IDR_WpdBasicHardwareDriver, "{021AD204-6411-4698-8CFB-C1A72B581733}") - DECLARE_LIBID(LIBID_WpdBasicHardwareDriverLib) -}; - -CWpdBasicHardwareDriverModule _AtlModule; - -// DLL Entry Point -extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) -{ - if(dwReason == DLL_PROCESS_ATTACH) - { - g_hInstance = hInstance; - - // Initialize tracing. - WPP_INIT_TRACING(MYDRIVER_TRACING_ID); - } - else if (dwReason == DLL_PROCESS_DETACH) - { - // Cleanup tracing. - WPP_CLEANUP(); - } - - return _AtlModule.DllMain(dwReason, lpReserved); -} - -// Used to determine whether the DLL can be unloaded by OLE -STDAPI DllCanUnloadNow(void) -{ - return _AtlModule.DllCanUnloadNow(); -} - -// Returns a class factory to create an object of the requested type -STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID* ppv) -{ - return _AtlModule.DllGetClassObject(rclsid, riid, ppv); -} - -// DllRegisterServer - Adds entries to the system registry -STDAPI DllRegisterServer(void) -{ - // registers object, typelib and all interfaces in typelib - HRESULT hr = _AtlModule.DllRegisterServer(); - return hr; -} - -// DllUnregisterServer - Removes entries from the system registry -STDAPI DllUnregisterServer(void) -{ - HRESULT hr = _AtlModule.DllUnregisterServer(); - return hr; -} diff --git a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.def b/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.def deleted file mode 100644 index 4af498d9..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.def +++ /dev/null @@ -1,9 +0,0 @@ -; WpdBasicHardwareDriver.def : Declares the module parameters. - -LIBRARY "WpdBasicHardwareDriver.DLL" - -EXPORTS - DllCanUnloadNow PRIVATE - DllGetClassObject PRIVATE - DllRegisterServer PRIVATE - DllUnregisterServer PRIVATE diff --git a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.idl b/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.idl deleted file mode 100644 index 73ff16af..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.idl +++ /dev/null @@ -1,24 +0,0 @@ - -import "oaidl.idl"; -import "ocidl.idl"; - -import "wudfddi.idl"; - -[ - uuid(69A9B934-73F0-45AF-B3C5-1D5BC7BC982B), - version(1.0), - helpstring("Windows Portable Device Basic Hardware Driver Type Library") -] -library WpdBasicHardwareDriverLib -{ - importlib("stdole2.tlb"); - [ - uuid(EC7445EE-BC00-4CED-AFE7-A52849F10239), - helpstring("WpdBasicHardwareDriver Class") - ] - coclass WpdBasicHardwareDriver - { - [default] interface IDriverEntry; - }; -}; - diff --git a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.inx b/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.inx deleted file mode 100644 index 493a1964..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.inx +++ /dev/null @@ -1,81 +0,0 @@ -; -; WpdBasicHardwareDriver.inf -; - -[Version] -Signature="$Windows NT$" -Class=WPD -ClassGuid={EEC5AD98-8080-425f-922A-DABF3DE3F69A} -Provider=%Provider% -CatalogFile=WpdBasicHardwareDriver.cat -DriverVer=01/24/2007,1.1.1.1 - -[Manufacturer] -%Mfg%=Standard,NT$ARCH$ - -[Standard.NT$ARCH$] -%BasicDeviceName%=Basic_Install,WUDF\WpdBasicHardware - -[SourceDisksFiles] -WudfUpdate_$UMDFCOINSTALLERVERSION$.dll=1 -WpdBasicHardwareDriver.dll=1 - -[SourceDisksNames] -1 = %MediaDescription% - -; =================== WPD Sample Device ================================== - -[Basic_Install] -CopyFiles=System32Copy - -[Basic_Install.hw] -AddReg=Device_AddReg - -[Basic_Install.Services] -AddService=WUDFRd,0x000001fa,WUDFRD_ServiceInstall - -[Basic_Install.CoInstallers] -AddReg=Basic_Install.CoInstallers_AddReg -CopyFiles=CoInstallers_CopyFiles - -[CoInstallers_CopyFiles] -WudfUpdate_$UMDFCOINSTALLERVERSION$.dll - -[Basic_Install.CoInstallers_AddReg] -HKR,,CoInstallers32,0x00010000,"WudfUpdate_$UMDFCOINSTALLERVERSION$.dll" - -[Basic_Install.Wdf] -UmdfService=WpdBasicHardwareDriver, WpdBasicHardwareDriver_Install -UmdfServiceOrder=WpdBasicHardwareDriver -; Enable file-handle-based I/O targets -UmdfDispatcher = FileHandle - -[WpdBasicHardwareDriver_Install] -UmdfLibraryVersion=$UMDFVERSION$ -DriverCLSID="{EC7445EE-BC00-4CED-AFE7-A52849F10239}" -ServiceBinary=%12%\UMDF\WpdBasicHardwareDriver.dll - -[Device_AddReg] -; HKR,,"EnableLegacySupport",0x10001,0 - -[WUDFRD_ServiceInstall] -ServiceType=1 -StartType=3 -ErrorControl=1 -ServiceBinary=%12%\WUDFRd.sys - -[DestinationDirs] -System32Copy=12,UMDF ; copy to system32\drivers\umdf -CoInstallers_CopyFiles=11 - -[System32Copy] -WpdBasicHardwareDriver.dll - - -; =================== Generic ================================== - -[Strings] -Mfg="Windows Portable Devices" -Provider="TODO-Set-Provider" -MediaDescription="WPD Basic Hardware Driver Installation Media" -BasicDeviceName="WPD Basic Hardware Driver" diff --git a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.rc b/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.rc deleted file mode 100644 index f743120a..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.rc +++ /dev/null @@ -1,15 +0,0 @@ -#include "resource.h" -#include <windows.h> -#include <ntverp.h> - -#define VER_FILETYPE VFT_DLL -#define VER_FILESUBTYPE VFT2_UNKNOWN -#define VER_FILEDESCRIPTION_STR "Windows Portable Device Basic Hardware Driver" -#define VER_INTERNALNAME_STR "WpdBasicHardwareDriver.dll" - -#include <common.ver> - -1 TYPELIB "WpdBasicHardwareDriver.tlb" - -IDR_WpdTempSensorDriver REGISTRY "WpdBasicHardwareDriver.rgs" - diff --git a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.rgs b/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.rgs deleted file mode 100644 index 6b4ae538..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.rgs +++ /dev/null @@ -1,26 +0,0 @@ -HKCR -{ - WpdBasicHardwareDriver.WpdBasicHardwareDriver.1 = s 'WpdBasicHardwareDriver Class' - { - CLSID = s '{FB2CC0AD-6723-45D2-9EC6-7B603F9BCD17}' - } - WpdBasicHardwareDriver.WpdBasicHardwareDriver = s 'WpdBasicHardwareDriver Class' - { - CLSID = s '{FB2CC0AD-6723-45D2-9EC6-7B603F9BCD17}' - CurVer = s 'WpdBasicHardwareDriver.WpdBasicHardwareDriver.1' - } - NoRemove CLSID - { - ForceRemove {FB2CC0AD-6723-45D2-9EC6-7B603F9BCD17} = s 'WpdBasicHardwareDriver Class' - { - ProgID = s 'WpdBasicHardwareDriver.WpdBasicHardwareDriver.1' - VersionIndependentProgID = s 'WpdBasicHardwareDriver.WpdBasicHardwareDriver.1' - InprocServer32 = s '%MODULE%' - { - val ThreadingModel = s 'Free' - } - 'TypeLib' = s '{20E7797C-2981-49EE-8A78-85A11440785C}' - } - } -} - diff --git a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.sln b/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.sln deleted file mode 100644 index df39a1bb..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.sln +++ /dev/null @@ -1,28 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0 -MinimumVisualStudioVersion = 12.0 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WpdBasicHardwareDriver", "WpdBasicHardwareDriver.vcxproj", "{7A722DFC-8A5B-42CB-BC5D-BD6A66446260}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - Debug|x64 = Debug|x64 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7A722DFC-8A5B-42CB-BC5D-BD6A66446260}.Debug|Win32.ActiveCfg = Debug|Win32 - {7A722DFC-8A5B-42CB-BC5D-BD6A66446260}.Debug|Win32.Build.0 = Debug|Win32 - {7A722DFC-8A5B-42CB-BC5D-BD6A66446260}.Release|Win32.ActiveCfg = Release|Win32 - {7A722DFC-8A5B-42CB-BC5D-BD6A66446260}.Release|Win32.Build.0 = Release|Win32 - {7A722DFC-8A5B-42CB-BC5D-BD6A66446260}.Debug|x64.ActiveCfg = Debug|x64 - {7A722DFC-8A5B-42CB-BC5D-BD6A66446260}.Debug|x64.Build.0 = Debug|x64 - {7A722DFC-8A5B-42CB-BC5D-BD6A66446260}.Release|x64.ActiveCfg = Release|x64 - {7A722DFC-8A5B-42CB-BC5D-BD6A66446260}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.vcxproj b/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.vcxproj deleted file mode 100644 index e7c78060..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.vcxproj +++ /dev/null @@ -1,352 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup Label="ProjectConfigurations"> - <ProjectConfiguration Include="Debug|Win32"> - <Configuration>Debug</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|Win32"> - <Configuration>Release</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Debug|x64"> - <Configuration>Debug</Configuration> - <Platform>x64</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|x64"> - <Configuration>Release</Configuration> - <Platform>x64</Platform> - </ProjectConfiguration> - </ItemGroup> - <PropertyGroup Label="Globals"> - <ProjectGuid>{7A722DFC-8A5B-42CB-BC5D-BD6A66446260}</ProjectGuid> - <RootNamespace>$(MSBuildProjectName)</RootNamespace> - <UMDF_VERSION_MAJOR>1</UMDF_VERSION_MAJOR> - <KMDF_VERSION_MAJOR>1</KMDF_VERSION_MAJOR> - <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration> - <Platform Condition="'$(Platform)' == ''">Win32</Platform> - <SampleGuid>{67BF652A-585A-43F0-BAB1-C84527A6B802}</SampleGuid> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>False</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>True</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>False</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>True</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> - <PropertyGroup> - <OutDir>$(IntDir)</OutDir> - </PropertyGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ItemGroup Label="WrappedTaskItems"> - <ClCompile Include="WpdBasicHardwareDriver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Driver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Device.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Queue.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="RS232Connection.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="RS232Target.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdBaseDriver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectEnum.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectProperties.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdCapabilities.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <Inf Include="WpdBasicHardwareDriver.inx"> - <Architecture>$(InfArch)</Architecture> - <SpecifyArchitecture>true</SpecifyArchitecture> - <CopyOutput>.\$(IntDir)\WpdBasicHardwareDriver.inf</CopyOutput> - </Inf> - <OtherWpp Include="WpdBasicHardwareDriver.rc; WpdBasicHardwareDriver.idl"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - </OtherWpp> - </ItemGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <TargetName>WpdBasicHardwareDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <TargetName>WpdBasicHardwareDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <TargetName>WpdBasicHardwareDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <TargetName>WpdBasicHardwareDriver</TargetName> - </PropertyGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <ClCompile> - <ExceptionHandling>Sync</ExceptionHandling> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <ClCompile> - <ExceptionHandling>Sync</ExceptionHandling> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <ClCompile> - <ExceptionHandling>Sync</ExceptionHandling> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <ClCompile> - <ExceptionHandling>Sync</ExceptionHandling> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Link> - <ModuleDefinitionFile>WpdBasicHardwareDriver.def</ModuleDefinitionFile> - </Link> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Link> - <ModuleDefinitionFile>WpdBasicHardwareDriver.def</ModuleDefinitionFile> - </Link> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Link> - <ModuleDefinitionFile>WpdBasicHardwareDriver.def</ModuleDefinitionFile> - </Link> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Link> - <ModuleDefinitionFile>WpdBasicHardwareDriver.def</ModuleDefinitionFile> - </Link> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemGroup> - <ClCompile Include="Stdafxsrc.cpp"> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Create</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <Midl Include="WpdBasicHardwareDriver.idl" /> - <ResourceCompile Include="WpdBasicHardwareDriver.rc" /> - </ItemGroup> - <ItemGroup> - <Inf Exclude="@(Inf)" Include="*.inf" /> - <FilesToPackage Include="$(TargetPath)" Condition="'$(ConfigurationType)'=='Driver' or '$(ConfigurationType)'=='DynamicLibrary'" /> - </ItemGroup> - <ItemGroup> - <None Exclude="@(None)" Include="*.txt;*.htm;*.html" /> - <None Exclude="@(None)" Include="*.ico;*.cur;*.bmp;*.dlg;*.rct;*.gif;*.jpg;*.jpeg;*.wav;*.jpe;*.tiff;*.tif;*.png;*.rc2" /> - <None Exclude="@(None)" Include="*.def;*.bat;*.hpj;*.asmx" /> - </ItemGroup> - <ItemGroup> - <ClInclude Exclude="@(ClInclude)" Include="*.h;*.hpp;*.hxx;*.hm;*.inl;*.xsd" /> - </ItemGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> -</Project>
\ No newline at end of file diff --git a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.vcxproj.Filters b/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.vcxproj.Filters deleted file mode 100644 index 2b0c894d..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdBasicHardwareDriver.vcxproj.Filters +++ /dev/null @@ -1,72 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup> - <Filter Include="Source Files"> - <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;*</Extensions> - <UniqueIdentifier>{87BC3193-63DE-407F-9D36-4672BA568413}</UniqueIdentifier> - </Filter> - <Filter Include="Header Files"> - <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> - <UniqueIdentifier>{34A617F5-BA38-4A42-80E9-F38C652127D4}</UniqueIdentifier> - </Filter> - <Filter Include="Resource Files"> - <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml</Extensions> - <UniqueIdentifier>{B731F5B5-20D6-4344-A6C6-344B616EDE83}</UniqueIdentifier> - </Filter> - <Filter Include="Driver Files"> - <Extensions>inf;inv;inx;mof;mc;</Extensions> - <UniqueIdentifier>{A6935631-CF1A-44E0-978B-A8A0D1F3E7D6}</UniqueIdentifier> - </Filter> - </ItemGroup> - <ItemGroup> - <ClCompile Include="Device.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Driver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Queue.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="RS232Connection.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="RS232Target.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Stdafxsrc.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdBaseDriver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdBasicHardwareDriver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdCapabilities.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectEnum.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectProperties.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <Midl Include="WpdBasicHardwareDriver.idl"> - <Filter>Source Files</Filter> - </Midl> - <None Include="WpdBasicHardwareDriver.def"> - <Filter>Source Files</Filter> - </None> - </ItemGroup> - <ItemGroup> - <Inf Include="WpdBasicHardwareDriver.inx"> - <Filter>Driver Files</Filter> - </Inf> - </ItemGroup> - <ItemGroup> - <ResourceCompile Include="WpdBasicHardwareDriver.rc"> - <Filter>Resource Files</Filter> - </ResourceCompile> - </ItemGroup> -</Project>
\ No newline at end of file diff --git a/wpd/WpdBasicHardwareDriver/WpdCapabilities.cpp b/wpd/WpdBasicHardwareDriver/WpdCapabilities.cpp deleted file mode 100644 index e14c53c2..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdCapabilities.cpp +++ /dev/null @@ -1,505 +0,0 @@ -#include "stdafx.h" - -#include "WpdCapabilities.tmh" - -const PROPERTYKEY g_SupportedCommands[] = -{ - // WPD_CATEGORY_OBJECT_ENUMERATION - WPD_COMMAND_OBJECT_ENUMERATION_START_FIND, - WPD_COMMAND_OBJECT_ENUMERATION_FIND_NEXT, - WPD_COMMAND_OBJECT_ENUMERATION_END_FIND, - - // WPD_CATEGORY_OBJECT_PROPERTIES - WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED, - WPD_COMMAND_OBJECT_PROPERTIES_GET, - WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL, - WPD_COMMAND_OBJECT_PROPERTIES_SET, - WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES, - WPD_COMMAND_OBJECT_PROPERTIES_DELETE, - - // WPD_CATEGORY_CAPABILITIES - WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS, - WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS, - WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES, - WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS, - WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_EVENTS, - WPD_COMMAND_CAPABILITIES_GET_EVENT_OPTIONS, -}; - -const GUID g_SupportedFunctionalCategories[] = -{ - WPD_FUNCTIONAL_CATEGORY_DEVICE, - FUNCTIONAL_CATEGORY_SENSOR_SAMPLE, // Our device's functional category -}; - -const GUID g_SupportedEvents[] = -{ - EVENT_SENSOR_READING_UPDATED, -}; - -WpdCapabilities::WpdCapabilities() -{ - -} - -WpdCapabilities::~WpdCapabilities() -{ - -} - -HRESULT WpdCapabilities::DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (Command.fmtid != WPD_CATEGORY_CAPABILITIES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS)) - { - hr = OnGetSupportedCommands(pParams, pResults); - CHECK_HR(hr, "Failed to get supported commands"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS)) - { - hr = OnGetCommandOptions(pParams, pResults); - CHECK_HR(hr, "Failed to get command options"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES)) - { - hr = OnGetFunctionalCategories(pParams, pResults); - CHECK_HR(hr, "Failed to get functional categories"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS)) - { - hr = OnGetFunctionalObjects(pParams, pResults); - CHECK_HR(hr, "Failed to get functional objects"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_EVENTS)) - { - hr = OnGetSupportedEvents(pParams, pResults); - CHECK_HR(hr, "Failed to get supported events"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_EVENT_OPTIONS)) - { - hr = OnGetEventOptions(pParams, pResults); - CHECK_HR(hr, "Failed to get event options"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return all commands supported by this driver as an - * IPortableDeviceKeyCollection in WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS. - * This includes custom commands, if any. - * - * Note that certain commands require a "command target" to function correctly. - * (e.g. delete object command) It is understood that not all objects are necessarily - * valid targets (e.g. you cannot delete the device object). - */ -HRESULT WpdCapabilities::OnGetSupportedCommands( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pCommands; - UNREFERENCED_PARAMETER(pParams); - - // CoCreate a collection to store the supported commands. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pCommands); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // Add the supported commands to the collection. - if (hr == S_OK) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedCommands); dwIndex++) - { - hr = pCommands->Add(g_SupportedCommands[dwIndex]); - CHECK_HR(hr, "Failed to add supported command at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS, pCommands); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_COMMAND: a collection of property keys containing a single value, - * which identifies the specific command options are requested to return. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS, containing - * the relevant options. If no options are available for this command, the driver should - * return an IPortableDeviceValues with no elements in it. - */ -HRESULT WpdCapabilities::OnGetCommandOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - PROPERTYKEY Command = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pOptions; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the command whose options have been requested - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_CAPABILITIES_COMMAND, &Command); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_COMMAND"); - } - - // CoCreate a collection to store the command options. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pOptions); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Add command options to the collection - if (hr == S_OK) - { - // If your driver supports command options, then they should be added here - // to the command options collection 'pOptions'. - } - - // Set the WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS, pOptions); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_CLSID) in - * WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES, containing - * the supported functional categories for this device. - */ -HRESULT WpdCapabilities::OnGetFunctionalCategories( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDevicePropVariantCollection> pFunctionalCategories; - - UNREFERENCED_PARAMETER(pParams); - - // CoCreate a collection to store the supported functional categories. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFunctionalCategories); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported functional categories to the collection. - if (hr == S_OK) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedFunctionalCategories); dwIndex++) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - // Don't call PropVariantClear, since we did not allocate the memory for these GUIDs - - pv.vt = VT_CLSID; - pv.puuid = (GUID*) &g_SupportedFunctionalCategories[dwIndex]; - - hr = pFunctionalCategories->Add(&pv); - CHECK_HR(hr, "Failed to add supported functional category at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES, pFunctionalCategories); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS - * command. It is sent when the caller is interesting in finding the object IDs for all - * functional objects belonging to the specified functional category. - * Note: the number of functional objects is expected to be very small (less than 8 for the - * whole device). - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY - a GUID value containing the category - * the caller is looking for. If the value is WPD_FUNCTIONAL_CATEGORY_ALL, then the driver - * must return all functional objects, no matter which category they belong to. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_LPWSTR) in - * WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS, containing - * the ids of the functional objects who belong to the specified functional category. - * If there are no objects in the specified category, the driver should return an - * empty collection. - */ -HRESULT WpdCapabilities::OnGetFunctionalObjects( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidFunctionalCategory = GUID_NULL; - CComPtr<IPortableDevicePropVariantCollection> pFunctionalObjects; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the functional category whose functional object identifiers have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY, &guidFunctionalCategory); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY"); - } - - // CoCreate a collection to store the supported functional object identifiers. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFunctionalObjects); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported functional object identifiers for the specified functional - // category to the collection. - if (hr == S_OK) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - // Don't call PropVariantClear, since we did not allocate the memory for these object identifiers - - // Add WPD_DEVICE_OBJECT_ID to the functional object identifiers collection - if (hr == S_OK) - { - - if ((guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_DEVICE) || - (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_ALL)) - { - pv.vt = VT_LPWSTR; - pv.pwszVal = WPD_DEVICE_OBJECT_ID; - hr = pFunctionalObjects->Add(&pv); - CHECK_HR(hr, "Failed to add device object ID"); - } - } - - // Add FUNCTIONAL_CATEGORY_SENSOR_SAMPLE to the functional object - // identifiers collection - if (hr == S_OK) - { - if ((guidFunctionalCategory == FUNCTIONAL_CATEGORY_SENSOR_SAMPLE) || - (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_ALL)) - { - pv.vt = VT_LPWSTR; - pv.pwszVal = SENSOR_OBJECT_ID; - hr = pFunctionalObjects->Add(&pv); - CHECK_HR(hr, "Failed to add sensor object ID"); - } - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS, pFunctionalObjects); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS"); - } - - return hr; -} - - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_EVENTS - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return all events supported by this driver should be returned as an - * IPortableDeviceKeyCollection in WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS. - * That includes custom commands, if any. - */ -HRESULT WpdCapabilities::OnGetSupportedEvents( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDevicePropVariantCollection> pEvents; - UNREFERENCED_PARAMETER(pParams); - - // CoCreate a collection to store the supported events. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pEvents); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported events to the collection. - if (hr == S_OK) - { - // populate the supported events collection - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedEvents); dwIndex++) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - // Don't call PropVariantClear, since we did not allocate the memory for these GUIDs - - pv.vt = VT_CLSID; - pv.puuid = (GUID*) &g_SupportedEvents[dwIndex]; - - hr = pEvents->Add(&pv); - CHECK_HR(hr, "Failed to add supported event at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS, pEvents); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_EVENT_OPTIONS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_EVENT: a GUID value indicating the Event whose options should be returned. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS, containing - * the relevant options. - */ -HRESULT WpdCapabilities::OnGetEventOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID Event = GUID_NULL; - CComPtr<IPortableDeviceValues> pOptions; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the event whose options have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_EVENT, &Event); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_EVENT"); - } - - // CoCreate a collection to store the event options. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pOptions); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Add event options to the collection - if (hr == S_OK) - { - // Check for the events we support - if (Event == EVENT_SENSOR_READING_UPDATED) - { - // These events are broadcast events - hr = pOptions->SetBoolValue(WPD_EVENT_OPTION_IS_BROADCAST_EVENT, TRUE); - CHECK_HR(hr, "Failed to set WPD_EVENT_OPTION_IS_BROADCAST_EVENT"); - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS, pOptions); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS"); - } - - return hr; -} - - diff --git a/wpd/WpdBasicHardwareDriver/WpdCapabilities.h b/wpd/WpdBasicHardwareDriver/WpdCapabilities.h deleted file mode 100644 index b7435830..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdCapabilities.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -class WpdCapabilities -{ -public: - WpdCapabilities(); - virtual ~WpdCapabilities(); - - HRESULT Initialize(); - - HRESULT DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedCommands( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetCommandOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFunctionalCategories( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFunctionalObjects( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedEvents( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetEventOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -}; - diff --git a/wpd/WpdBasicHardwareDriver/WpdObjectEnum.cpp b/wpd/WpdBasicHardwareDriver/WpdObjectEnum.cpp deleted file mode 100644 index d804802e..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdObjectEnum.cpp +++ /dev/null @@ -1,431 +0,0 @@ -#include "stdafx.h" - -#include "WpdObjectEnum.tmh" - -WpdObjectEnumerator::WpdObjectEnumerator() -{ - -} - -WpdObjectEnumerator::~WpdObjectEnumerator() -{ - -} - -HRESULT WpdObjectEnumerator::Initialize(_In_ WpdBaseDriver* pBaseDriver) -{ - m_pBaseDriver = pBaseDriver; - return S_OK; -} - -HRESULT WpdObjectEnumerator::DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (Command.fmtid != WPD_CATEGORY_OBJECT_ENUMERATION) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - - if (hr == S_OK) - { - if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_START_FIND.pid) - { - hr = OnStartFind(pParams, pResults); - CHECK_HR(hr, "Failed to begin enumeration"); - } - else if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_FIND_NEXT.pid) - { - hr = OnFindNext(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to find next object"); - } - } - else if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_END_FIND.pid) - { - hr = OnEndFind(pParams, pResults); - CHECK_HR(hr, "Failed to end enumeration"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_ENUMERATION_START_FIND - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID: the parent where we should start - * the enumeration. - * - WPD_PROPERTY_OBJECT_ENUMERATION_FILTER: the filter to use when doing - * enumeration. Since this parameter is optional, it may not exist. - * This driver currently ignores the filter parameter. - * - * The driver should: - * - Create a new context for this enumeration. - * - Set the string identifier in WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT for the newly created enumeration context. - * This value will be passed back during OnFindNext and OnEndFind. - */ -HRESULT WpdObjectEnumerator::OnStartFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszParentID = NULL; - ContextMap* pContextMap = NULL; - CAtlStringW strEnumContext; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier of the parent where the enumeration is starting from. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID, &wszParentID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID"); - } - - // Get the client context map so we can store an enumeration context for this enumeration - // operation. - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Create and initialize a new enumeration context. - // Add the new enumertion context to the client context map. This context is used to - // keep track of this particular enumeration operation. - if (hr == S_OK) - { - WpdObjectEnumeratorContext* pEnumeratorContext = new WpdObjectEnumeratorContext(); - if (pEnumeratorContext != NULL) - { - // Initialize the enumeration context - InitializeEnumerationContext(pEnumeratorContext, wszParentID); - - // Add the enumeration context to the client context map. - pContextMap->Add(pEnumeratorContext, strEnumContext); - - // Release the context because Add AddRef's it - SAFE_RELEASE(pEnumeratorContext); - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate enumeration context"); - } - } - - // Set the WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT value in the results. - // This context identifier will be passed back during OnFindNext and OnEndFind to allow the driver to access it. - if (hr == S_OK) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, strEnumContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - // Free the memory. - CoTaskMemFree(wszParentID); - wszParentID = NULL; - - SAFE_RELEASE(pContextMap); - - return hr; -} - -HRESULT WpdObjectEnumerator::OnFindNext(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszEnumContext = NULL; - DWORD dwNumObjectsRequested = 0; - ContextMap* pContextMap = NULL; - WpdObjectEnumeratorContext* pEnumeratorContext = NULL; - DWORD NumObjectsEnumerated = 0; - - CComPtr<IPortableDevicePropVariantCollection> pObjectIDCollection; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the enumeration context identifier for this enumeration operation. - // The enumeration context identifier is needed to lookup the specific - // enumeration context in the client context map for this enumeration operation. - // NOTE that more than one enumeration may be in progress. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, &wszEnumContext); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - // Get the number of objects requested for this enumeration call. - // The driver should always attempt to meet this requested value. - // If there are fewer children than requested, the driver should return the remaining - // children and a return code of S_FALSE. - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_ENUMERATION_NUM_OBJECTS_REQUESTED, &dwNumObjectsRequested); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_NUM_OBJECTS_REQUESTED"); - } - - // Get the client context map so we can retrieve the enumeration context for this enumeration - // operation. - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (hr == S_OK) - { - pEnumeratorContext = (WpdObjectEnumeratorContext*)pContextMap->GetContext(wszEnumContext); - if (pEnumeratorContext == NULL) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing enumeration context"); - } - } - - // CoCreate a collection to store the object identifiers being returned for this enumeration call. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pObjectIDCollection); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // If the enumeration context reports that their are more objects to return, then continue, if not, - // return an empty results set. - if ((hr == S_OK) && (pEnumeratorContext != NULL) && (pEnumeratorContext->HasMoreChildrenToEnumerate() == TRUE)) - { - if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(L"") == 0) - { - // We are being asked for the WPD_DEVICE_OBJECT_ID - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to add 'DEVICE' object ID to enumeration collection"); - - // Update the the number of children we are returning for this enumeration call - NumObjectsEnumerated++; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(WPD_DEVICE_OBJECT_ID) == 0) - { - - // We are being asked for direct children of the WPD_DEVICE_OBJECT_ID - switch (m_pBaseDriver->m_SensorType) - { - case WpdBaseDriver::UNKNOWN: - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, SENSOR_OBJECT_ID); - break; - case WpdBaseDriver::COMPASS: - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, COMPASS_SENSOR_OBJECT_ID); - break; - case WpdBaseDriver::SENSIRON: - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, TEMP_SENSOR_OBJECT_ID); - break; - case WpdBaseDriver::FLEX: - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, FLEX_SENSOR_OBJECT_ID); - break; - case WpdBaseDriver::PING: - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, PING_SENSOR_OBJECT_ID); - break; - case WpdBaseDriver::PIR: - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, PIR_SENSOR_OBJECT_ID); - break; - case WpdBaseDriver::MEMSIC: - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, MEMSIC_SENSOR_OBJECT_ID); - break; - case WpdBaseDriver::QTI: - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, QTI_SENSOR_OBJECT_ID); - break; - case WpdBaseDriver::PIEZO: - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, PIEZO_SENSOR_OBJECT_ID); - break; - case WpdBaseDriver::HITACHI: - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, HITACHI_SENSOR_OBJECT_ID); - break; - default: - break; - } - CHECK_HR(hr, "Failed to add storage object ID to enumeration collection"); - - // Update the the number of children we are returning for this enumeration call - NumObjectsEnumerated++; - - } - } - - // Set the collection of object identifiers enumerated in the results - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_ENUMERATION_OBJECT_IDS, pObjectIDCollection); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_ENUMERATION_OBJECT_IDS"); - } - - // If the enumeration context reports that their are no more objects to return then return S_FALSE indicating to the - // caller that we are finished. - if (hr == S_OK) - { - if (pEnumeratorContext != NULL) - { - // Update the number of children we have enumerated and returned to the caller - pEnumeratorContext->m_ChildrenEnumerated += NumObjectsEnumerated; - - // Check the number requested against the number enumerated and set the HRESULT - // accordingly. - if (NumObjectsEnumerated < dwNumObjectsRequested) - { - // We returned less than the number of objects requested to the caller - hr = S_FALSE; - } - else - { - // We returned exactly the number of objects requested to the caller - hr = S_OK; - } - } - } - - // Free the memory. - CoTaskMemFree(wszEnumContext); - wszEnumContext = NULL; - - SAFE_RELEASE(pContextMap); - SAFE_RELEASE(pEnumeratorContext); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_ENUMERATION_END_FIND - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT: the context the driver returned to - * the client in OnStartFind. - * - * The driver should: - * - Destroy any data associated with this context. - */ -HRESULT WpdObjectEnumerator::OnEndFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszEnumContext = NULL; - ContextMap* pContextMap = NULL; - - UNREFERENCED_PARAMETER(pResults); - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the enumeration context identifier for this enumeration operation. We will - // need this to lookup the specific enumeration context in the client context map. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, &wszEnumContext); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - // Get the client context map so we can retrieve the enumeration context for this enumeration - // operation using the WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT property value obtained above. - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Destroy any data allocated/associated with the enumeration context and then remove it from the context map. - // We no longer need to keep this context around because the enumeration has been ended. - if (hr == S_OK) - { - pContextMap->Remove(wszEnumContext); - } - - // Free the memory. - CoTaskMemFree(wszEnumContext); - wszEnumContext = NULL; - - SAFE_RELEASE(pContextMap); - - return hr; -} - -// Initialize the enumeration context -VOID WpdObjectEnumerator::InitializeEnumerationContext( - _In_ WpdObjectEnumeratorContext* pEnumeratorContext, - _In_ LPCWSTR wszParentObjectID) -{ - if (pEnumeratorContext == NULL) - { - return; - } - - // Initialize the enumeration context with the parent object identifier - pEnumeratorContext->m_strParentObjectID = wszParentObjectID; - - // Our sample driver has a very simple object structure where we know - // how many children are under each parent. - // The eumeration context is initialized below with this information. - if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(L"") == 0) - { - // Clients passing an 'empty' string for the parent are asking for the - // 'DEVICE' object. We should return 1 child in this case. - pEnumeratorContext->m_TotalChildren = 1; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(WPD_DEVICE_OBJECT_ID) == 0) - { - // The device object contains 1 child (the storage object). - pEnumeratorContext->m_TotalChildren = 1; - } - // If the sensor objects have children, add them here... - else - { - // The sensor object contains 0 children. - pEnumeratorContext->m_TotalChildren = 0; - } -} - -HRESULT WpdObjectEnumerator::AddStringValueToPropVariantCollection( - _In_ IPortableDevicePropVariantCollection* pCollection, - _In_ LPCWSTR wszValue) -{ - HRESULT hr = S_OK; - - if ((pCollection == NULL) || - (wszValue == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - - pv.vt = VT_LPWSTR; - pv.pwszVal = (LPWSTR)wszValue; - - // The wszValue will be copied into the collection, keeping the ownership - // of the string belonging to the caller. - // Don't call PropVariantClear, since we did not allocate the memory for these string values - - hr = pCollection->Add(&pv); - - return hr; -} diff --git a/wpd/WpdBasicHardwareDriver/WpdObjectEnum.h b/wpd/WpdBasicHardwareDriver/WpdObjectEnum.h deleted file mode 100644 index e6dc0542..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdObjectEnum.h +++ /dev/null @@ -1,107 +0,0 @@ -#pragma once - -// This class is used to store the context for a specific enumeration. -class WpdObjectEnumeratorContext : public IUnknown -{ -public: - WpdObjectEnumeratorContext() : - m_cRef(1), - m_TotalChildren(0), - m_ChildrenEnumerated(0) - { - - } - - ~WpdObjectEnumeratorContext() - { - - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -private: - DWORD m_cRef; - -public: - BOOL HasMoreChildrenToEnumerate() - { - return (m_TotalChildren > m_ChildrenEnumerated)?TRUE:FALSE; - } - -// WpdObjectEnumeratorContext specific data -public: - CAtlStringW m_strParentObjectID; // object identifier of the object whose children are being enumerated - DWORD m_TotalChildren; // number of bytes transferred from the resource to the caller - DWORD m_ChildrenEnumerated; // number of children returned during the enumeration operation -}; - -class WpdObjectEnumerator -{ -public: - WpdObjectEnumerator(); - virtual ~WpdObjectEnumerator(); - - HRESULT Initialize(_In_ WpdBaseDriver* pBaseDriver); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnStartFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnFindNext(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnEndFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - WpdBaseDriver* m_pBaseDriver; - - VOID InitializeEnumerationContext( - _In_ WpdObjectEnumeratorContext* pEnumeratorContext, - _In_ LPCWSTR wszParentObjectID); - - HRESULT AddStringValueToPropVariantCollection( - _In_ IPortableDevicePropVariantCollection* pCollection, - _In_ LPCWSTR wszValue); -}; diff --git a/wpd/WpdBasicHardwareDriver/WpdObjectProperties.cpp b/wpd/WpdBasicHardwareDriver/WpdObjectProperties.cpp deleted file mode 100644 index 927b8a19..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdObjectProperties.cpp +++ /dev/null @@ -1,1314 +0,0 @@ -#include "stdafx.h" - -#include "WpdObjectProperties.tmh" - -const PROPERTYKEY g_SupportedCommonProperties[] = -{ - WPD_OBJECT_ID, - WPD_OBJECT_PERSISTENT_UNIQUE_ID, - WPD_OBJECT_PARENT_ID, - WPD_OBJECT_NAME, - WPD_OBJECT_FORMAT, - WPD_OBJECT_CONTENT_TYPE, - WPD_OBJECT_CAN_DELETE, -}; - -const PROPERTYKEY g_SupportedDeviceProperties[] = -{ - WPD_DEVICE_FIRMWARE_VERSION, - WPD_DEVICE_POWER_LEVEL, - WPD_DEVICE_POWER_SOURCE, - WPD_DEVICE_PROTOCOL, - WPD_DEVICE_MODEL, - WPD_DEVICE_SERIAL_NUMBER, - WPD_DEVICE_SUPPORTS_NON_CONSUMABLE, - WPD_DEVICE_MANUFACTURER, - WPD_DEVICE_FRIENDLY_NAME, - WPD_DEVICE_TYPE, - WPD_FUNCTIONAL_OBJECT_CATEGORY, -}; - -const PROPERTYKEY g_SupportedSensorProperties[] = -{ - SENSOR_READING, - SENSOR_UPDATE_INTERVAL, - WPD_FUNCTIONAL_OBJECT_CATEGORY, -}; - - -WpdObjectProperties::WpdObjectProperties() : - m_dwUpdateInterval(0), - m_llSensorReading(0) -{ - -} - -WpdObjectProperties::~WpdObjectProperties() -{ - m_pBaseDriver = NULL; -} - -HRESULT WpdObjectProperties::Initialize(_In_ WpdBaseDriver* pBaseDriver) -{ - m_pBaseDriver = pBaseDriver; - return S_OK; -} - -HRESULT WpdObjectProperties::DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (Command.fmtid != WPD_CATEGORY_OBJECT_PROPERTIES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED)) - { - hr = OnGetSupportedProperties(pParams, pResults); - CHECK_HR(hr, "Failed to get supported properties"); - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET)) - { - hr = OnGetPropertyValues(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to get properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL)) - { - hr = OnGetAllPropertyValues(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to get all properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_SET)) - { - hr = OnSetPropertyValues(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to set properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES)) - { - hr = OnGetPropertyAttributes(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to get property attributes"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_DELETE)) - { - hr = OnDeleteProperties(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to delete properties"); - } - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose supported properties have - * been requested. - * - * - WPD_PROPERTY_OBJECT_PROPERTIES_FILTER: the filter to use when returning supported properties. - * Since this parameter is optional, it may not exist. - * ! This driver currently ignores the filter parameter. ! - * - * The driver should: - * - Return supported property keys for the specified object in WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS - */ -HRESULT WpdObjectProperties::OnGetSupportedProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose supported properties have been requested - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing string value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // CoCreate a collection to store the supported property keys. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // Add supported property keys for the specified object to the collection - if (hr == S_OK) - { - hr = AddSupportedPropertyKeys(wszObjectID, pKeys); - CHECK_HR(hr, "Failed to add supported property keys for object '%ws'", wszObjectID); - } - - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, pKeys); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - // Free the memory. - CoTaskMemFree(wszObjectID); - wszObjectID = NULL; - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values have been requested. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys, identifying which - * specific property values we are requested to return. - * - * The driver should: - * - Return all requested property values in WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES. If any property read failed, the corresponding value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were read successfully. - * - S_FALSE should be returned if any property read failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property values have been requested - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // Get the list of property keys for the property values the caller wants to retrieve from the specified object - if (hr == S_OK) - { - hr = pParams->GetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, &pKeys); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - // CoCreate a collection to store the property values. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Read the specified properties on the specified object and add the property values to the collection. - if (hr == S_OK) - { - hr = GetPropertyValuesForObject(wszObjectID, pKeys, pValues); - CHECK_HR(hr, "Failed to get property values for object '%ws'", wszObjectID); - } - - // S_OK or S_FALSE can be returned from GetPropertyValuesForObject( ). - // S_FALSE means that 1 or more property values could not be retrieved successfully. - // The value for the specified property should be set to an error HRESULT of - // the reason why the property could not be read. - // (e.g. If the property being requested is not supported on the object then an error of - // HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) should be set as the value. - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES value in the results. - HRESULT hrTemp = S_OK; - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, pValues); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. - CoTaskMemFree(wszObjectID); - wszObjectID = NULL; - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values have been requested. - * - * The driver should: - * - Return all property values in WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES. If any property read failed, the corresponding value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were read successfully. - * - S_FALSE should be returned if any property read failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetAllPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property values have been requested - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // CoCreate a collection to store the property values. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the property keys we are going to use - // to request the property values of. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // First we make a request for ALL supported property keys for the specified object. - // Next, we delegate to our helper function GetPropertyValuesForObject( ) passing - // the entire property key collection. This will reuse existing implementation - // in our driver to perform the GetAllPropertyValues operation. - if (hr == S_OK) - { - hr = AddSupportedPropertyKeys(wszObjectID, pKeys); - CHECK_HR(hr, "Failed to get ALL supported properties for object '%ws'", wszObjectID); - if (hr == S_OK) - { - hr = GetPropertyValuesForObject(wszObjectID, pKeys, pValues); - CHECK_HR(hr, "Failed to get property values for object '%ws'", wszObjectID); - } - } - - // S_OK or S_FALSE can be returned from GetPropertyValuesForObject( ). - // S_FALSE means that 1 or more property values could not be retrieved successfully. - // The value for the specified property key should be set to the error HRESULT of - // the reason why the property could not be read. - // (i.e. an error of HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) if a property value was - // requested and is not supported by the specified object.) - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES value in the results - HRESULT hrTemp = S_OK; - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, pValues); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. - CoTaskMemFree(wszObjectID); - wszObjectID = NULL; - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_SET - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values we want to return. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES: an IPortableDeviceValues of values, identifying which - * specific property values we are requested to write. - * - * The driver should: - * - Write all requested property values. For each property, a write result should be returned in the - * write result property store. - * - If any property write failed, the corresponding write result value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were written successfully. - * - S_FALSE should be returned if any property write failed. - * - Any error return indicates that the driver did not write any results, and the caller will - * not attempt to unpack any property write results. - */ -HRESULT WpdObjectProperties::OnSetPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - HRESULT hrResult = S_OK; - LPWSTR wszObjectID = NULL; - DWORD cValues = 0; - CAtlStringW strObjectID; - - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceValues> pWriteResults; - CComPtr<IPortableDeviceValues> pEventParams; - - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property values are being set - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // Get the caller-supplied property values requested to be set on the object - if (hr == S_OK) - { - strObjectID = wszObjectID; - - hr = pParams->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, &pValues); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES"); - } - - // CoCreate a collection to store the property set operation results. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pWriteResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Set the property values on the specified object - if (hr == S_OK) - { - // Since this driver does not support setting any properties, all property set operation - // results will be set to E_ACCESSDENIED. - if (hr == S_OK) - { - hr = pValues->GetCount(&cValues); - CHECK_HR(hr, "Failed to get total number of values"); - } - - if (hr == S_OK) - { - for (DWORD dwIndex = 0; dwIndex < cValues; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - PROPVARIANT Value = {0}; - - PropVariantInit(&Value); - - hr = pValues->GetAt(dwIndex, &Key, &Value); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d", dwIndex); - - if (hr == S_OK) - { - // TODO: Add other ...OBJECT_ID strings where applicable - if ( - (strObjectID.CompareNoCase(SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(TEMP_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(FLEX_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(PIR_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(PING_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(QTI_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(MEMSIC_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(HITACHI_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(PIEZO_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(COMPASS_SENSOR_OBJECT_ID) == 0) - ) - { - if (IsEqualPropertyKey(Key, SENSOR_UPDATE_INTERVAL)) - { - if (Value.vt == VT_UI4) - { - hr = SendUpdateIntervalToDevice(Value.ulVal); - CHECK_HR(hr, "Failed to send the new SENSOR_UPDATE_INTERVAL %d on the device", Value.ulVal); - } - else - { - // property failed to be set as it is an invalid vartype - hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); - CHECK_HR(hr, "Failed to update the SENSOR_UPDATE_INTERVAL because the vartype is invalid. Expected VT_UI4, got %d", Value.vt); - } - - // An error has occurred, set the overall result to S_FALSE - if (hr != S_OK) - { - hrResult = S_FALSE; - } - - hr = pWriteResults->SetErrorValue(Key, hr); - CHECK_HR(hr, "Failed to set error result value of SENSOR_UPDATE_INTERVAL for '%ws'", wszObjectID); - } - else - { - // Other properties for the sensor object are read only - hr = pWriteResults->SetErrorValue(Key, E_ACCESSDENIED); - CHECK_HR(hr, "Failed to set error result value at index %d for '%ws'", dwIndex, wszObjectID); - hrResult = S_FALSE; - } - } - else - { - // Properties for all other objects are read only - hr = pWriteResults->SetErrorValue(Key, E_ACCESSDENIED); - CHECK_HR(hr, "Failed to set error result value at index %d for '%ws'", dwIndex, wszObjectID); - hrResult = S_FALSE; - } - } - - PropVariantClear(&Value); - - } // end for - } // end if - } - - // At least one property failed to be set - if (hrResult != S_OK) - { - hr = hrResult; - } - - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_WRITE_RESULTS value in the results - HRESULT hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_WRITE_RESULTS, pWriteResults); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_WRITE_RESULTS")); - - // Don't override the S_FALSE hresult that indicates at least one property had failed - if (hr == S_OK) - { - hr = hrTemp; - } - } - - // Free the memory. - CoTaskMemFree(wszObjectID); - wszObjectID = NULL; - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property attributes we want to return. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys containing a single value, - * which is the key identifying the specific property attributes we are requested to return. - * - * The driver should: - * - Return the requested property attributes. If any property attributes failed to be retrieved, - * the corresponding value should be set to type VT_ERROR with the 'scode' member holding the - * HRESULT reason for the failure. - * - S_OK should be returned if all property attributes were read successfully. - * - S_FALSE should be returned if any property attribute failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - PROPERTYKEY Key = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pAttributes; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property attributes have been requested - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // Get the list of property keys whose attributes are being requested - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, &Key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - // CoCreate a collection to store the property attributes. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Get the attributes for the specified properties on the specified object and add them - // to the collection. - if (hr == S_OK) - { - hr = GetPropertyAttributesForObject(wszObjectID, Key, pAttributes); - CHECK_HR(hr, "Failed to get property attributes"); - } - - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_ATTRIBUTES value in the results - HRESULT hrTemp = S_OK; - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_ATTRIBUTES, pAttributes); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_ATTRIBUTES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. - CoTaskMemFree(wszObjectID); - wszObjectID = NULL; - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_DELETE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose properties should be deleted. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys indicating which - * properties to delete. - * - * The driver should: - * - Delete the specified properties from the object. - * - S_OK should be returned if all specified properties were successfully deleted. - * - E_ACCESSDENIED should be returned if the client attempts to delete a property which is not deletable (i.e. - * WPD_PROPERTY_ATTRIBUTE_CAN_DELETE is FALSE for that property.) - */ -HRESULT WpdObjectProperties::OnDeleteProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = E_ACCESSDENIED; - - UNREFERENCED_PARAMETER(pParams); - UNREFERENCED_PARAMETER(pResults); - - // This driver has no properties which can be deleted. - - return hr; -} - -/** - * This method is called to populate supported PROPERTYKEYs found on objects. - * - * The parameters sent to us are: - * wszObjectID - the object whose supported property keys are being requested - * pKeys - An IPortableDeviceKeyCollection to be populated with supported PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the specified object. - */ -HRESULT AddSupportedPropertyKeys( - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys) -{ - HRESULT hr = S_OK; - CAtlStringW strObjectID = wszObjectID; - - // Add Common PROPERTYKEYs for ALL WPD objects - AddCommonPropertyKeys(pKeys); - - if (strObjectID.CompareNoCase(WPD_DEVICE_OBJECT_ID) == 0) - { - // Add the PROPERTYKEYs for the 'DEVICE' object - AddDevicePropertyKeys(pKeys); - } - - // Add other PROPERTYKEYs for other supported objects... - // TODO: Add comparison to other ..._OBJECT_IDs where applicable - if ( - (strObjectID.CompareNoCase(SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(TEMP_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(FLEX_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(PIR_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(PING_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(QTI_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(MEMSIC_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(HITACHI_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(PIEZO_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(COMPASS_SENSOR_OBJECT_ID) == 0) - ) - { - // Add the PROPERTYKEYs for the Sensor object - AddSensorPropertyKeys(pKeys); - } - - - - return hr; -} - -/** - * This method is called to populate common PROPERTYKEYs found on ALL objects. - * - * The parameters sent to us are: - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the ALL objects. - */ -VOID AddCommonPropertyKeys( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - if (pKeys != NULL) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedCommonProperties); dwIndex++) - { - HRESULT hr = S_OK; - hr = pKeys->Add(g_SupportedCommonProperties[dwIndex] ); - CHECK_HR(hr, "Failed to add common property"); - } - } -} - -/** - * This method is called to populate PROPERTYKEYs found on the SENSOR object. - * - * The parameters sent to us are: - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the DEVICE object. - */ -VOID AddSensorPropertyKeys( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - if (pKeys != NULL) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedSensorProperties); dwIndex++) - { - HRESULT hr = S_OK; - hr = pKeys->Add(g_SupportedSensorProperties[dwIndex] ); - CHECK_HR(hr, "Failed to add sensor property"); - } - } -} - -/** - * This method is called to populate common PROPERTYKEYs found on the DEVICE object. - * - * The parameters sent to us are: - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the DEVICE object. - */ -VOID AddDevicePropertyKeys( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - if (pKeys != NULL) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedDeviceProperties); dwIndex++) - { - HRESULT hr = S_OK; - hr = pKeys->Add(g_SupportedDeviceProperties[dwIndex] ); - CHECK_HR(hr, "Failed to add device property"); - } - } -} - - -/** - * This method is called to populate property values for the object specified. - * - * The parameters sent to us are: - * wszObjectID - the object whose properties are being requested. - * pKeys - the list of property keys of the properties to request from the object - * pValues - an IPortableDeviceValues which will contain the property values retreived from the object - * - * The driver should: - * Read the specified properties for the specified object and populate pValues with the - * results. - */ -HRESULT WpdObjectProperties::GetPropertyValuesForObject( - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys, - _In_ IPortableDeviceValues* pValues) -{ - HRESULT hr = S_OK; - CAtlStringW strObjectID = wszObjectID; - DWORD cKeys = 0; - - if ((wszObjectID == NULL) || - (pKeys == NULL) || - (pValues == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - hr = pKeys->GetCount(&cKeys); - CHECK_HR(hr, "Failed to number of PROPERTYKEYs in collection"); - - if (hr == S_OK) - { - // Get values for the DEVICE object - if (strObjectID.CompareNoCase(WPD_DEVICE_OBJECT_ID) == 0) - { - for (DWORD dwIndex = 0; dwIndex < cKeys; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - hr = pKeys->GetAt(dwIndex, &Key); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d in collection", dwIndex); - - if (hr == S_OK) - { - // Preset the property value to 'error not supported'. The actual value - // will replace this value, if read from the device. - pValues->SetErrorValue(Key, HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)); - - // Set DEVICE object properties - if (IsEqualPropertyKey(Key, WPD_DEVICE_FIRMWARE_VERSION)) - { - hr = pValues->SetStringValue(WPD_DEVICE_FIRMWARE_VERSION, DEVICE_FIRMWARE_VERSION_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_FIRMWARE_VERSION"); - } - - else if (IsEqualPropertyKey(Key, WPD_DEVICE_POWER_LEVEL)) - { - hr = pValues->SetUnsignedIntegerValue(WPD_DEVICE_POWER_LEVEL, DEVICE_POWER_LEVEL_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_POWER_LEVEL"); - } - - else if (IsEqualPropertyKey(Key, WPD_DEVICE_POWER_SOURCE)) - { - hr = pValues->SetUnsignedIntegerValue(WPD_DEVICE_POWER_SOURCE, WPD_POWER_SOURCE_EXTERNAL); - CHECK_HR(hr, "Failed to set WPD_DEVICE_POWER_SOURCE"); - } - - else if (IsEqualPropertyKey(Key, WPD_DEVICE_PROTOCOL)) - { - hr = pValues->SetStringValue(WPD_DEVICE_PROTOCOL, DEVICE_PROTOCOL_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_PROTOCOL"); - } - - else if (IsEqualPropertyKey(Key, WPD_DEVICE_MODEL)) - { - hr = pValues->SetStringValue(WPD_DEVICE_MODEL, DEVICE_MODEL_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_MODEL"); - } - - else if (IsEqualPropertyKey(Key, WPD_DEVICE_SERIAL_NUMBER)) - { - hr = pValues->SetStringValue(WPD_DEVICE_SERIAL_NUMBER, DEVICE_SERIAL_NUMBER_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_SERIAL_NUMBER"); - } - - else if (IsEqualPropertyKey(Key, WPD_DEVICE_SUPPORTS_NON_CONSUMABLE)) - { - hr = pValues->SetBoolValue(WPD_DEVICE_SUPPORTS_NON_CONSUMABLE, DEVICE_SUPPORTS_NONCONSUMABLE_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_SUPPORTS_NON_CONSUMABLE"); - } - - else if (IsEqualPropertyKey(Key, WPD_DEVICE_MANUFACTURER)) - { - hr = pValues->SetStringValue(WPD_DEVICE_MANUFACTURER, DEVICE_MANUFACTURER_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_MANUFACTURER"); - } - - else if (IsEqualPropertyKey(Key, WPD_DEVICE_FRIENDLY_NAME)) - { - hr = pValues->SetStringValue(WPD_DEVICE_FRIENDLY_NAME, DEVICE_FRIENDLY_NAME_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_FRIENDLY_NAME"); - } - - else if (IsEqualPropertyKey(Key, WPD_DEVICE_TYPE)) - { - hr = pValues->SetUnsignedIntegerValue(WPD_DEVICE_TYPE, WPD_DEVICE_TYPE_GENERIC); - CHECK_HR(hr, "Failed to set WPD_DEVICE_TYPE"); - } - - // Set general properties for DEVICE - else if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ID, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID"); - } - - else if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - // Retrieves the "DEVICE" string that identifies the root device - hr = pValues->SetStringValue(WPD_OBJECT_NAME, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME"); - } - - else if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - - else if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PARENT_ID, L""); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PARENT_ID"); - } - - else if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_FORMAT, WPD_OBJECT_FORMAT_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT"); - } - - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CONTENT_TYPE"); - } - - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - hr = pValues->SetBoolValue(WPD_OBJECT_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CAN_DELETE"); - } - - else if (IsEqualPropertyKey(Key, WPD_FUNCTIONAL_OBJECT_CATEGORY)) - { - hr = pValues->SetGuidValue(WPD_FUNCTIONAL_OBJECT_CATEGORY, WPD_FUNCTIONAL_CATEGORY_DEVICE); - CHECK_HR(hr, "Failed to set WPD_FUNCTIONAL_OBJECT_CATEGORY"); - } - } - } - } - // Retrieve the temperature sensor properties - else if ( - (strObjectID.CompareNoCase(SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(TEMP_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(FLEX_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(PIR_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(PING_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(QTI_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(MEMSIC_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(HITACHI_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(PIEZO_SENSOR_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(COMPASS_SENSOR_OBJECT_ID) == 0) - ) - { - for (DWORD dwIndex = 0; dwIndex < cKeys; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - hr = pKeys->GetAt(dwIndex, &Key); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d in collection", dwIndex); - - if (hr == S_OK) - { - // Preset the property value to 'error not supported'. The actual value - // will replace this value, if read from the device. - pValues->SetErrorValue(Key, HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)); - if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ID, strObjectID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID"); - } - - else if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - - // Retrieve the ID of the sensor using the m_SensorType member of the - // basedriver that is set during the data-read operation. - hr = pValues->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, strObjectID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - - else if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PARENT_ID, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PARENT_ID"); - } - - else if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - // Retrieve the name of the sensor using the m_SensorType member of the - // basedriver that is set during the data-read operation. - if (m_pBaseDriver->m_SensorType == 0) - hr = pValues->SetStringValue(WPD_OBJECT_NAME, SENSOR_OBJECT_NAME_VALUE); - else if (m_pBaseDriver->m_SensorType == 2) - hr = pValues->SetStringValue(WPD_OBJECT_NAME, TEMP_SENSOR_OBJECT_NAME_VALUE); - else if (m_pBaseDriver->m_SensorType == 3) - hr = pValues->SetStringValue(WPD_OBJECT_NAME, FLEX_SENSOR_OBJECT_NAME_VALUE); - else if (m_pBaseDriver->m_SensorType == 4) - hr = pValues->SetStringValue(WPD_OBJECT_NAME, PING_SENSOR_OBJECT_NAME_VALUE); - else if (m_pBaseDriver->m_SensorType == 5) - hr = pValues->SetStringValue(WPD_OBJECT_NAME, PIR_SENSOR_OBJECT_NAME_VALUE); - else if (m_pBaseDriver->m_SensorType == 6) - hr = pValues->SetStringValue(WPD_OBJECT_NAME, MEMSIC_SENSOR_OBJECT_NAME_VALUE); - else if (m_pBaseDriver->m_SensorType == 7) - hr = pValues->SetStringValue(WPD_OBJECT_NAME, QTI_SENSOR_OBJECT_NAME_VALUE); - else if (m_pBaseDriver->m_SensorType == 8) - hr = pValues->SetStringValue(WPD_OBJECT_NAME, PIEZO_SENSOR_OBJECT_NAME_VALUE); - else if (m_pBaseDriver->m_SensorType == 9) - hr = pValues->SetStringValue(WPD_OBJECT_NAME, HITACHI_SENSOR_OBJECT_NAME_VALUE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME"); - } - - else if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_FORMAT, WPD_OBJECT_FORMAT_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT"); - } - - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CONTENT_TYPE"); - } - - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - hr = pValues->SetBoolValue(WPD_OBJECT_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CAN_DELETE"); - } - - else if (IsEqualPropertyKey(Key, SENSOR_READING)) - { - hr = pValues->SetUnsignedLargeIntegerValue(SENSOR_READING, GetSensorReading()); - CHECK_HR(hr, "Failed to set SENSOR_READING"); - } - - else if (IsEqualPropertyKey(Key, SENSOR_UPDATE_INTERVAL)) - { - hr = pValues->SetUnsignedLargeIntegerValue(SENSOR_UPDATE_INTERVAL, GetUpdateInterval()); - CHECK_HR(hr, "Failed to set SENSOR_UPDATE_INTERVAL"); - } - else if (IsEqualPropertyKey(Key, WPD_FUNCTIONAL_OBJECT_CATEGORY)) - { - hr = pValues->SetGuidValue(WPD_FUNCTIONAL_OBJECT_CATEGORY, FUNCTIONAL_CATEGORY_SENSOR_SAMPLE); - CHECK_HR(hr, "Failed to set WPD_FUNCTIONAL_OBJECT_CATEGORY"); - } - } - } // end for - } // end else if - } - - return hr; -} - -/** - * This method is called to populate property attributes for the object and property specified. - * - * The parameters sent to us are: - * wszObjectID - the object whose property attributes are being requested. - * Key - the property whose attributes are being requested - * pAttributes - an IPortableDeviceValues which will contain the resulting property attributes - * - * The driver should: - * Read the property attributes for the specified property on the specified object and - * populate pAttributes with the results. - */ -HRESULT WpdObjectProperties::GetPropertyAttributesForObject( - _In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if ((wszObjectID == NULL) || - (pAttributes == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - // - // Since ALL of our properties have the same attributes, we are ignoring the - // passed in wszObjectID parameter. This parameter allows you to - // customize attributes for properties on specific objects. (i.e. WPD_OBJECT_ORIGINAL_FILE_NAME - // may be READ/WRITE on some objects and READONLY on others. ) - // - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_DELETE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_READ"); - } - - if (hr == S_OK) - { - // Allow writes for the update interval property - if (IsEqualPropertyKey(Key, SENSOR_UPDATE_INTERVAL)) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_WRITE, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_WRITE for SENSOR_UPDATE_INTERVAL"); - } - else - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_WRITE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_WRITE"); - } - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY"); - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Key, SENSOR_UPDATE_INTERVAL)) - { - // Form range attributes for the update interval property - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_FORM, WPD_PROPERTY_ATTRIBUTE_FORM_RANGE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_RANGE_MIN for SENSOR_UPDATE_INTERVAL"); - - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_RANGE_MIN, SENSOR_UPDATE_INTERVAL_MIN); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_RANGE_MIN for SENSOR_UPDATE_INTERVAL"); - - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_RANGE_MAX, SENSOR_UPDATE_INTERVAL_MAX); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_RANGE_MAX for SENSOR_UPDATE_INTERVAL"); - - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_RANGE_STEP, SENSOR_UPDATE_INTERVAL_STEP); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_RANGE_STEP for SENSOR_UPDATE_INTERVAL"); - } - else if (IsEqualPropertyKey(Key, SENSOR_READING)) - { - // Form range attributes for the reading property - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_FORM, WPD_PROPERTY_ATTRIBUTE_FORM_RANGE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_RANGE_MIN for SENSOR_READING"); - - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_RANGE_MIN, SENSOR_READING_MIN); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_RANGE_MIN for SENSOR_READING"); - - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_RANGE_MAX, SENSOR_READING_MAX); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_RANGE_MAX for SENSOR_READING"); - - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_RANGE_STEP, SENSOR_READING_STEP); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_RANGE_STEP for SENSOR_READING"); - } - else - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_FORM, WPD_PROPERTY_ATTRIBUTE_FORM_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FORM"); - } - } - - return hr; -} - - -/** - * This method is called to update the sensor reading - * - * The parameters sent to us are: - * dwNewReading - the temperature reading to set - * - * The driver should: - * Update the sensor reading. - */ -VOID WpdObjectProperties::SetSensorReading(LONGLONG llNewReading) -{ - // Ensure that this value isn't currently being accessed by another thread - CComCritSecLock<CComAutoCriticalSection> Lock(m_SensorReadingCriticalSection); - - m_llSensorReading = llNewReading; -} - - -/** - * This method is called to retrieve the sensor reading - * - * The parameters sent to us are: - * - * The driver should: - * Return the saved sensor reading. - */ -LONGLONG WpdObjectProperties::GetSensorReading() -{ - // Ensure that this value isn't currently being accessed by another thread - CComCritSecLock<CComAutoCriticalSection> Lock(m_SensorReadingCriticalSection); - - return m_llSensorReading; -} - - -/** - * This method is called to set the cached sensor interval - * - * The parameters sent to us are: - * dwNewInterval - the sensor update interval to set - * - * The driver should: - * Update the cached sensor interval property. - */ -VOID WpdObjectProperties::SetUpdateInterval(DWORD dwNewInterval) -{ - m_dwUpdateInterval = dwNewInterval; -} - - -/** - * This method is called to retrieve the sensor update interval - * - * The parameters sent to us are: - * - * The driver should: - * Return the interval property. - */ -DWORD WpdObjectProperties::GetUpdateInterval() -{ - return m_dwUpdateInterval; -} - - -/** - * This method is called to update the sensor interval on the device - * - * The parameters sent to us are: - * dwNewInterval - the sensor update interval to set - * - * The driver should: - * Update the cached sensor property and send a write request to the device - */ -HRESULT WpdObjectProperties::SendUpdateIntervalToDevice(DWORD dwNewInterval) -{ - HRESULT hr = S_OK; - RS232Target* pDeviceTarget = NULL; - - CHAR szInterval[INTERVAL_DATA_LENGTH+1] = {0}; - - // Check the input value - if (IsValidUpdateInterval(dwNewInterval) == FALSE) - { - hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); - CHECK_HR(hr, "Invalid update interval: %d", dwNewInterval); - } - - // Format a write request with the input value - if (hr == S_OK) - { - hr = StringCchPrintfA(szInterval, ARRAYSIZE(szInterval), "%u", dwNewInterval); - CHECK_HR(hr, "Failed to convert the new interval to a CHAR string"); - } - - // Send the write request to the device - if (hr == S_OK) - { - pDeviceTarget = m_pBaseDriver->GetRS232Target(); - - if (pDeviceTarget->IsReady()) - { - hr = pDeviceTarget->SendWriteRequest((BYTE *)szInterval, sizeof(szInterval)); - CHECK_HR(hr, "Failed to send the write request to set the new sensor update interval"); - - if (hr == S_OK) - { - TraceEvents(TRACE_LEVEL_VERBOSE, TRACE_FLAG_DRIVER, "%!FUNC! Sent new interval: %s", szInterval); - } - } - else - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_READY); - CHECK_HR(hr, "Device is not ready to receive write requests"); - } - } - - if (hr == S_OK) - { - // Update the cached value on the driver - SetUpdateInterval(dwNewInterval); - } - - return hr; -} - - -/** - * This method is called to check that interval value falls within the accepted range - * of 2000 to 60000 milliseconds - * - * The parameters sent to us are: - * wszInterval - the sensor update interval to check - * - * The driver should: - * Return TRUE if the interval is within range - */ -BOOL WpdObjectProperties::IsValidUpdateInterval(DWORD dwInterval) -{ - if ((dwInterval >= SENSOR_UPDATE_INTERVAL_MIN) && - (dwInterval <= SENSOR_UPDATE_INTERVAL_MAX)) - { - return TRUE; - } - - return FALSE; -} - diff --git a/wpd/WpdBasicHardwareDriver/WpdObjectProperties.h b/wpd/WpdBasicHardwareDriver/WpdObjectProperties.h deleted file mode 100644 index 1860e0ad..00000000 --- a/wpd/WpdBasicHardwareDriver/WpdObjectProperties.h +++ /dev/null @@ -1,111 +0,0 @@ -#pragma once - -#define DEVICE_PROTOCOL_VALUE L"Sensor Protocol ver 1.00" -#define DEVICE_FIRMWARE_VERSION_VALUE L"1.0.0.0" -#define DEVICE_POWER_LEVEL_VALUE 100 -#define DEVICE_MODEL_VALUE L"RS232 Sensor" -#define DEVICE_FRIENDLY_NAME_VALUE L"Parallax BS2 Sensor" -#define DEVICE_MANUFACTURER_VALUE L"Windows Portable Devices Group" -#define DEVICE_SERIAL_NUMBER_VALUE L"01234567890123-45676890123456" -#define DEVICE_SUPPORTS_NONCONSUMABLE_VALUE FALSE - -#define SENSOR_OBJECT_ID L"Sensor" -#define SENSOR_OBJECT_NAME_VALUE L"Parallax Sensor" -#define COMPASS_SENSOR_OBJECT_ID L"Compass" -#define COMPASS_SENSOR_OBJECT_NAME_VALUE L"HM55B Compass Sensor" -#define PIR_SENSOR_OBJECT_ID L"PIR" -#define PIR_SENSOR_OBJECT_NAME_VALUE L"Passive Infra-Red Sensor" -#define QTI_SENSOR_OBJECT_ID L"QTI" -#define QTI_SENSOR_OBJECT_NAME_VALUE L"QTI Light Sensor" -#define FLEX_SENSOR_OBJECT_ID L"Flex" -#define FLEX_SENSOR_OBJECT_NAME_VALUE L"Flex Force Sensor" -#define PING_SENSOR_OBJECT_ID L"Ping" -#define PING_SENSOR_OBJECT_NAME_VALUE L"Ultrasonic Distance Sensor" -#define PIEZO_SENSOR_OBJECT_ID L"Piezo" -#define PIEZO_SENSOR_OBJECT_NAME_VALUE L"Piezo Vibration Sensor" -#define TEMP_SENSOR_OBJECT_ID L"TempHumidity" -#define TEMP_SENSOR_OBJECT_NAME_VALUE L"Sensiron Temperature and Humidity Sensor" -#define MEMSIC_SENSOR_OBJECT_ID L"Memsic" -#define MEMSIC_SENSOR_OBJECT_NAME_VALUE L"Memsic Dual-Axis G-Force Sensor" -#define HITACHI_SENSOR_OBJECT_ID L"Hitachi" -#define HITACHI_SENSOR_OBJECT_NAME_VALUE L"Hitachi Tri-Axis G-Force Sensor" -// INSERT ID and NAME definitions for other sensors here!! - - -GUID GetObjectFormat(CAtlStringW strObjectID); -GUID GetObjectContentType(CAtlStringW strObjectID); -HRESULT AddSupportedPropertyKeys(_In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys); - -VOID AddCommonPropertyKeys(_In_ IPortableDeviceKeyCollection* pKeys); -VOID AddDevicePropertyKeys(_In_ IPortableDeviceKeyCollection* pKeys); - -VOID AddSensorPropertyKeys(_In_ IPortableDeviceKeyCollection* pKeys); //Required for sensor props - -class WpdObjectProperties -{ -public: - - WpdObjectProperties(); - virtual ~WpdObjectProperties(); - - HRESULT Initialize(_In_ WpdBaseDriver* pBaseDriver); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedProperties(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetPropertyValues(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetAllPropertyValues(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnSetPropertyValues(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetPropertyAttributes(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnDeleteProperties(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - VOID SetSensorReading(LONGLONG llNewReading); - - LONGLONG GetSensorReading(); - - VOID SetUpdateInterval(DWORD dwNewInterval); - - DWORD GetUpdateInterval(); - - HRESULT SendUpdateIntervalToDevice(DWORD dwNewInterval); - - BOOL IsValidUpdateInterval(DWORD dwInterval); - -private: - - HRESULT GetPropertyValuesForObject(_In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys, - _In_ IPortableDeviceValues* pValues); - - HRESULT GetPropertyAttributesForObject(_In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes); - - -private: - WpdBaseDriver* m_pBaseDriver; - - // This critical section protects the sensor reading from concurrent access - // by the application (which reads it) and the read request callback (which updates it) - CComAutoCriticalSection m_SensorReadingCriticalSection; - LONGLONG m_llSensorReading; - - // A critical section is not needed for the update interval because it is accessed - // by the client application, and set/get requests from the application arrive serially - // through the sequential WDF queue. - DWORD m_dwUpdateInterval; -}; diff --git a/wpd/WpdBasicHardwareDriver/firmware/compass_wpd_enabled.bs2 b/wpd/WpdBasicHardwareDriver/firmware/compass_wpd_enabled.bs2 deleted file mode 100644 index 335d2c7e..00000000 --- a/wpd/WpdBasicHardwareDriver/firmware/compass_wpd_enabled.bs2 +++ /dev/null @@ -1,94 +0,0 @@ -' Compass_wpd_enabled.bs2 -' -' Displays x (N/S) and y (W/E) axis measurements along with the direction the -' Compass Module is pointing, measured in degrees clockwise from north. -' -' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF -' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO -' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A -' PARTICULAR PURPOSE. -' -' Copyright (c) Microsoft Corporation. All rights reserved -' -' {$STAMP BS2} -' {$PBASIC 2.5} -' ============================================================================ - -' -----[ Pins/Constants/Variables ]------------------------------------------- -DinDout PIN 6 ' P6 transceives to/from Din/Dout -Clk PIN 5 ' P5 sends pulses to HM55B's Clk -En PIN 4 ' P4 controls HM55B's /EN(ABLE) - -Reset CON %0000 ' Reset command for HM55B -Measure CON %1000 ' Start measurement command -Report CON %1100 ' Get status/axis values command -Ready CON %1100 ' 11 -> Done, 00 -> no errors -NegMask CON %1111100000000000 ' For 11-bit negative to 16-bits - -x VAR Word ' x-axis data -y VAR Word ' y-axis data -status VAR Nib ' Status flags -angle VAR Word ' Store angle measurement - -SensorID VAR Byte 'Sensor identifier = 5 for PIR -ElementSize VAR Byte 'Size (in bytes) of each element -ElementCount VAR Byte 'Count of elements in packet -Padding VAR Byte 'Padding for the 8-byte element - -SensorID = 1 -ElementSize = 1 -ElementCount = 3 '3-bytes for compass data; - -NewInterval VAR Word 'New interval requested by user -Interval VAR Word 'Interval value utlized by firmware - -LFD CON $10 'Linefeed character - -Interval = 200 '.20 of a second interval -NewInterval = 200 - -' -----[ Main Routine ]------------------------------------------------------- - -Main: - GOSUB PollSensor 'Was motion detected? - GOSUB RetrieveInterval 'Retrieve units data - -' -----[ Subroutines ]-------------------------------------------------------- - -Timeout: - SEROUT 16, 16468, [DEC1 SensorID, DEC1 ElementSize, DEC1 ElementCount, DEC3 angle, DEC5 Interval,LFD] - GOTO Main - -PollSensor: ' Compass module subroutine - - HIGH En: LOW En ' Send reset command to HM55B - SHIFTOUT DinDout,clk,MSBFIRST,[Reset\4] - - HIGH En: LOW En ' HM55B start measurement command - SHIFTOUT DinDout,clk,MSBFIRST,[Measure\4] - status = 0 ' Clear previous status flags - - DO ' Status flag checking loop - HIGH En: LOW En ' Measurement status command - SHIFTOUT DinDout,clk,MSBFIRST,[Report\4] - SHIFTIN DinDout,clk,MSBPOST,[Status\4] ' Get Status - LOOP UNTIL status = Ready ' Exit loop when status is ready - - SHIFTIN DinDout,clk,MSBPOST,[x\11,y\11] ' Get x & y axis values - HIGH En ' Disable module - - IF (y.BIT10 = 1) THEN y = y | NegMask ' Store 11-bits as signed word - IF (x.BIT10 = 1) THEN x = x | NegMask ' Repeat for other axis - - angle = x ATN -y ' Convert x and y to brads - angle = angle */ 360 ' Convert brads to degrees - - RETURN - - -RetrieveInterval: - SERIN 16, 16468, Interval, Timeout, [DEC NewInterval] 'Retrieve interval - IF NewInterval >= 10 AND NewInterval <= 60000 THEN - Interval = NewInterval - ENDIF - RETURN
\ No newline at end of file diff --git a/wpd/WpdBasicHardwareDriver/firmware/flex_force_wpd_enabled.bs2 b/wpd/WpdBasicHardwareDriver/firmware/flex_force_wpd_enabled.bs2 deleted file mode 100644 index 9b9e5b2c..00000000 --- a/wpd/WpdBasicHardwareDriver/firmware/flex_force_wpd_enabled.bs2 +++ /dev/null @@ -1,60 +0,0 @@ -' Flex_force_wpd_enabled.bs2 -' -' Displays R/C Discharge Time in BASIC Stamp DEBUG Window -' -' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF -' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO -' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A -' PARTICULAR PURPOSE. -' -' Copyright (c) Microsoft Corporation. All rights reserved -' -' {$STAMP BS2} -' {$PBASIC 2.5} -' ========================================================================= - -' -----[ Declarations ]---------------------------------------------------- - -rawForce VAR Word ' Stores raw output -sensorPin CON 15 ' Flexiforce sensor circuit - -' -----[ Main Routine ]---------------------------------------------------- - -SensorID VAR Byte 'Sensor identifier = 5 for PIR -ElementSize VAR Byte 'Size (in bytes) of each element -ElementCount VAR Byte 'Count of elements in packet -Padding VAR Byte 'Padding for the 8-byte element - -SensorID = 3 -ElementSize = 1 -ElementCount = 5 '4-bytes for pressure data; 5 for interval - -NewInterval VAR Word 'New interval requested by user -Interval VAR Word 'Interval value utlized by firmware - -Interval = 200 -NewInterval = 200 - -LFD CON $10 'Linefeed character - -Main: - - GOSUB PollSensor 'Was motion detected? - GOSUB RetrieveInterval 'Retrieve units data - -Timeout: - SEROUT 16, 16468, [DEC1 SensorID, DEC1 ElementSize, DEC1 ElementCount, DEC5 rawForce, DEC5 Interval, LFD] - GOTO Main - -PollSensor: - HIGH sensorPin ' Discharge the capacitor - PAUSE 2 - RCTIME sensorPin,1,rawForce ' Measure RC charge time - RETURN - -RetrieveInterval: - SERIN 16, 16468, Interval, Timeout, [DEC NewInterval] 'Retrieve interval - IF NewInterval >= 10 AND NewInterval <= 60000 THEN - Interval = NewInterval - ENDIF - RETURN diff --git a/wpd/WpdBasicHardwareDriver/firmware/h48c_3-axis_wpd_enabled.bs2 b/wpd/WpdBasicHardwareDriver/firmware/h48c_3-axis_wpd_enabled.bs2 deleted file mode 100644 index daba0fc9..00000000 --- a/wpd/WpdBasicHardwareDriver/firmware/h48c_3-axis_wpd_enabled.bs2 +++ /dev/null @@ -1,175 +0,0 @@ -' h48c_3-axis_wpd_enabled.bs2 -' -' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF -' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO -' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A -' PARTICULAR PURPOSE. -' -' Copyright (c) Microsoft Corporation. All rights reserved -' -' {$STAMP BS2} -' {$PBASIC 2.5} -' -' ========================================================================= - -' -----[ Program Description ]--------------------------------------------- -' -' Test program for the H48C 3-Axis Accelerometer module. -' -' Connections: -' -' +------------+ -' | * | -' CLK | o o | Vdd (+5v) -' | +--+ | -' DIO [ o | | o | CS\ -' | +--+ | -' Vss | o o | 0G (free-fall indication) -' | | -' +------------+ -' -' How it Works: -' -' An onboard MCP3204 12-bit ADC is used to read the VRef, X-, Y-, and -' Z-axis outputs from the Hitachi H48C accelerometer. The reference -' voltage output from H48C is 1.65 volts (3.3 / 2). -' -' After reading the reference voltage and an output channel the g-force -' for the channel is calculated with this formula: -' -' axis - vref 3.3 -' G = ----------- x ------ -' 4095 0.3663 -' -' For use in the program the forumla can be simplified to: -' -' G = (axis - vref) x 0.0022 -' -' To allow the display of fractional g-force in the integer system of the -' BASIC Stamp we multiply 0.0022 by 100 -- this will allow us to display -' g-force in 0.01g units. - - - -' -----[ I/O Definitions ]------------------------------------------------- - -Dio PIN 15 ' data to/from module -Clk PIN 14 ' clock output -CS PIN 13 ' active-low chip select - - -' -----[ Constants ]------------------------------------------------------- - -XAxis CON 0 ' adc channels -YAxis CON 1 -ZAxis CON 2 -VRef CON 3 - -Cnt2Mv CON $CE4C ' counts to millivolts - ' 0.80586 with ** -GfCnv CON $3852 ' g-force conversion - ' 0.22 with ** - -' -----[ Variables ]------------------------------------------------------- - -axis VAR Nib ' axis selection -rvCount VAR Word ' ref voltage adc counts -axCount VAR Word ' axis voltage adc counts -mVolts VAR Word ' millivolts -Gforce VAR Word ' axis g-force - -xGforce VAR Word ' x-axis force -yGforce VAR Word ' y-axis force -zGforce VAR Word ' z-axis force - -dValue VAR Word ' display value -dPad VAR Nib ' display pad - -' Below lines are WPD additions - -SensorID VAR Byte 'Sensor identifier = 9 for Hitachi -ElementCount VAR Byte 'Count of elements in packet -ElementSize VAR Byte 'Size (in bytes) of each element - - -NewInterval VAR Word 'New interval requested by user -Interval VAR Word 'Interval value utlized by firmware - -SensorID = 9 -ElementSize = 4 'Each element contains a sign byte, followed by a G-force integer value, followed by a G-force fraction (in hundredths). -ElementCount = 3 'Each element corresponds to one of the three axis (X, Y, and Z) - -Interval = 2000 -NewInterval = 2000 - - -' -----[ EEPROM Data ]----------------------------------------------------- - - -' -----[ Initialization ]-------------------------------------------------- - -Reset: - HIGH CS ' deselect module - -' -----[ Program Code ]---------------------------------------------------- - -Main: - GOSUB GetGforces 'Retrieves G-forces along 3 axis - GOSUB RetrieveInterval 'Retrieves event-interval data - - Timeout: - SEROUT 16, 16780, [DEC1 SensorID, DEC1 ElementSize, DEC1 ElementCount, DEC1(xGforce.BIT15), DEC1(ABS xGforce/100),DEC2(ABS xGforce),DEC1(yGforce.BIT15),DEC1(ABS yGforce/100),DEC2(ABS yGforce),DEC1(zGforce.BIT15),DEC1(ABS zGforce/100),DEC2(ABS zGforce),DEC5 Interval ] - GOTO Main - - GOTO Main - - -' -----[ Subroutines ]----------------------------------------------------- - -' Retrieves the event-interval property from the WPD driver -RetrieveInterval: - SERIN 16, 16780, Interval, Timeout, [DEC NewInterval] 'Retrieve interval - IF NewInterval >= 10 AND NewInterval <= 60000 THEN - Interval = NewInterval - ENDIF - -' Retrieves G forces along all three axis -GetGforces: - FOR axis = XAxis TO ZAxis ' loop through each axis - GOSUB Get_H48C ' read vRef & axis counts - ' calculate g-force - ' -- "Gforce" is signed word - IF (axCount >= rvCount) THEN - Gforce = (axCount - rvCount) ** GfCnv ' positive g-force - ELSE - Gforce = -((rvCount - axCount) ** GfCnv) ' negative g-force - ENDIF - IF (axis = XAxis) THEN - xGforce = Gforce - ENDIF - IF (axis = YAxis) THEN - yGforce = Gforce - ENDIF - IF (axis = ZAxis) THEN - zGforce = Gforce - ENDIF - NEXT - RETURN - -' Reads VRef and selected H48C axis through an MCP3204 ADC -' -- pass axis (0 - 2) in "axis" -' -- returns reference voltage counts in "rvCount" -' -- returns axis voltage counts in "axCounts" - -Get_H48C: - LOW CS - SHIFTOUT Dio, Clk, MSBFIRST, [%11\2, VRef\3] ' select vref register - SHIFTIN Dio, Clk, MSBPOST, [rvCount\13] ' read ref voltage counts - HIGH CS - PAUSE 1 - LOW CS - SHIFTOUT Dio, Clk, MSBFIRST, [%11\2, axis\3] ' select axis - SHIFTIN Dio, Clk, MSBPOST, [axCount\13] ' read axis voltage counts - HIGH CS - RETURN - diff --git a/wpd/WpdBasicHardwareDriver/firmware/memsic2125_wpd_enabled.bs2 b/wpd/WpdBasicHardwareDriver/firmware/memsic2125_wpd_enabled.bs2 deleted file mode 100644 index 80449357..00000000 --- a/wpd/WpdBasicHardwareDriver/firmware/memsic2125_wpd_enabled.bs2 +++ /dev/null @@ -1,107 +0,0 @@ -' memsic2125_wpd_enabled.bs2 -' -' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF -' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO -' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A -' PARTICULAR PURPOSE. -' -' Copyright (c) Microsoft Corporation. All rights reserved -' -' {$STAMP BS2} -' {$PBASIC 2.5} -' -' ========================================================================= - -' -----[ Program Description ]--------------------------------------------- -' -' Read the pulse outputs from a Memsic 2125 accelerometer and converts to -' G-force -' -' g = ((t1 / 10 ms) - 0.5) / 12.5% -' -' www.memsic.com - - -' -----[ Revision History ]------------------------------------------------ - - -' -----[ I/O Definitions ]------------------------------------------------- - -Xin PIN 8 ' X input from Memsic 2125 -Yin PIN 9 ' Y input from Memsic 2125 - - -' -----[ Constants ]------------------------------------------------------- - -' Set scale factor for PULSIN - -#SELECT $STAMP - #CASE BS2, BS2E - Scale CON $200 ' 2.0 us per unit - #CASE BS2SX - Scale CON $0CC ' 0.8 us per unit - #CASE BS2P - Scale CON $0C0 ' 0.75 us per unit - #CASE BS2PE - Scale CON $1E1 ' 1.88 us per unit -#ENDSELECT - -HiPulse CON 1 ' measure high-going pulse -LoPulse CON 0 - -' -----[ Variables ]------------------------------------------------------- - -xRaw VAR Word ' pulse from Memsic 2125 -xmG VAR Word ' g force (1000ths) - -yRaw VAR Word -ymG VAR Word - -'disp VAR Byte ' displacement (0.0 - 0.99) - - -' Below lines are WPD additions - -SensorID VAR Byte 'Sensor identifier = 1 for memsic -ElementSize VAR Byte 'Size (in bytes) of each element -ElementCount VAR Byte 'Count of elements in packet - -NewInterval VAR Word 'New interval requested by user -Interval VAR Word 'Interval value utlized by firmware - -SensorID = 6 -ElementSize = 1 -ElementCount = 6 '6-bytes for g-force - -LFD CON $10 'Linefeed character - -Interval = 100 '.10 of a second interval -NewInterval = 100 - -' -----[ Program Code ]---------------------------------------------------- - -Main: - GOSUB Read_G_Force 'reads G-force - GOSUB RetrieveInterval 'Retrieve units data - - Timeout: - SEROUT 16, 16468, [DEC1 SensorID, DEC1 ElementSize, DEC1 ElementCount, DEC1(xmG.BIT15), DEC1(ABS xmG/1000),DEC1(ABS xmG/10),DEC1(ymG.BIT15),DEC1(ABS ymG/1000),DEC1(ABS ymG/10),DEC5 Interval,LFD] - GOTO Main - - - RetrieveInterval: - SERIN 16, 16468, Interval, Timeout, [DEC NewInterval] 'Retrieve interval - IF NewInterval >= 10 AND NewInterval <= 60000 THEN - Interval = NewInterval - ENDIF - -' -----[ Subroutines ]----------------------------------------------------- - -Read_G_Force: - PULSIN Xin, HiPulse, xRaw ' read pulse output - xRaw = xRaw */ Scale ' convert to uSecs - xmG = ((xRaw / 10) - 500) * 8 ' calc 1/1000 g - PULSIN Yin, HiPulse, yRaw - yRaw = yRaw */ Scale - ymG = ((yRaw / 10) - 500) * 8 - RETURN
\ No newline at end of file diff --git a/wpd/WpdBasicHardwareDriver/firmware/piezo_wpd_enabled.bs2 b/wpd/WpdBasicHardwareDriver/firmware/piezo_wpd_enabled.bs2 deleted file mode 100644 index ff5a7b55..00000000 --- a/wpd/WpdBasicHardwareDriver/firmware/piezo_wpd_enabled.bs2 +++ /dev/null @@ -1,55 +0,0 @@ -' Piezo_wpd_enabled.bs2 -' -' This program demonstrates using the LDT0 as a switch/trigger -' -' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF -' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO -' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A -' PARTICULAR PURPOSE. -' -' Copyright (c) Microsoft Corporation. All rights reserved -' -' {$STAMP BS2} -' {$PBASIC 2.5} -' ========================================================================= - -SensorID VAR Byte 'Sensor identifier = 8 for piezo -ElementSize VAR Byte 'Size (in bytes) of each element -ElementCount VAR Byte 'Count of elements in packet -bVibration VAR Byte 'Vibration-detection variable (single element for PIR) -Padding VAR Byte 'Padding for the 8-byte element - -SensorID = 8 -ElementSize = 1 -ElementCount = 1 '1-byte for motion data; 5 for interval - -NewInterval VAR Word 'New interval requested by user -Interval VAR Word 'Interval value utlized by firmware - -Interval = 500 -NewInterval = 500 - -LFD CON $10 'Linefeed character - - -' -----[ Program Code ]---------------------------------------------------- - -Main: - - GOSUB PollSensor 'Was motion detected? - GOSUB RetrieveInterval 'Retrieve units data - -Timeout: - SEROUT 16, 16468, [DEC1 SensorID, DEC1 ElementSize, DEC1 ElementCount, DEC1 bVibration, DEC5 Interval, LFD] - GOTO Main - -PollSensor: - bVibration = IN0 ' Assign status of P0 to bMotion - RETURN - -RetrieveInterval: - SERIN 16, 16468, Interval, Timeout, [DEC NewInterval] 'Retrieve interval - IF NewInterval >= 10 AND NewInterval <= 60000 THEN - Interval = NewInterval - ENDIF - RETURN diff --git a/wpd/WpdBasicHardwareDriver/firmware/ping_wpd_enabled.bs2 b/wpd/WpdBasicHardwareDriver/firmware/ping_wpd_enabled.bs2 deleted file mode 100644 index e2af29a7..00000000 --- a/wpd/WpdBasicHardwareDriver/firmware/ping_wpd_enabled.bs2 +++ /dev/null @@ -1,57 +0,0 @@ -' Ping_wpd_enabled.bs2 -' -' Measure distance with Ping))) sensor and display in both in & cm -' -' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF -' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO -' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A -' PARTICULAR PURPOSE. -' -' Copyright (c) Microsoft Corporation. All rights reserved -' -' {$STAMP BS2} -' {$PBASIC 2.5} -' ========================================================================= - -' Conversion constants for room temperature measurements. -CmConstant CON 2260 -cmDistance VAR Word -time VAR Word -SensorID VAR Byte 'Sensor identifier = 5 for PIR -ElementSize VAR Byte 'Size (in bytes) of each element -ElementCount VAR Byte 'Count of elements in packet -Padding VAR Byte 'Padding for the 8-byte element - -SensorID = 4 -ElementSize = 1 -ElementCount = 5 '4-bytes for pressure data; 5 for interval - -NewInterval VAR Word 'New interval requested by user -Interval VAR Word 'Interval value utlized by firmware - - -LFD CON $10 'Linefeed character - -Interval = 200 '.20 of a second interval -NewInterval = 200 - -Main: - GOSUB PollSensor 'Was motion detected? - GOSUB RetrieveInterval 'Retrieve units data - -Timeout: - SEROUT 16, 16468, [DEC1 SensorID, DEC1 ElementSize, DEC1 ElementCount, DEC5 cmDistance, DEC5 Interval,LFD] -GOTO Main - -PollSensor: - PULSOUT 0, 5 - PULSIN 0, 1, time - cmDistance = cmConstant ** time -RETURN - -RetrieveInterval: - SERIN 16, 16468, Interval, Timeout, [DEC NewInterval] 'Retrieve interval - IF NewInterval >= 10 AND NewInterval <= 60000 THEN - Interval = NewInterval - ENDIF -RETURN
\ No newline at end of file diff --git a/wpd/WpdBasicHardwareDriver/firmware/pir_wpd_enabled.bs2 b/wpd/WpdBasicHardwareDriver/firmware/pir_wpd_enabled.bs2 deleted file mode 100644 index 259c5025..00000000 --- a/wpd/WpdBasicHardwareDriver/firmware/pir_wpd_enabled.bs2 +++ /dev/null @@ -1,50 +0,0 @@ -' Pir_wpd_enabled.bs2 -' -' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF -' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO -' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A -' PARTICULAR PURPOSE. -' -' Copyright (c) Microsoft Corporation. All rights reserved -' -' {$STAMP BS2} -' {$PBASIC 2.5} -' ========================================================================= - -SensorID VAR Byte 'Sensor identifier = 5 for PIR -ElementSize VAR Byte 'Size (in bytes) of each element -ElementCount VAR Byte 'Count of elements in packet -bMotion VAR Byte 'Motion-detection variable (single element for PIR) -Padding VAR Byte 'Padding for the 8-byte element - -SensorID = 5 -ElementSize = 1 -ElementCount = 1 '1-byte for motion data; 5 for interval - -NewInterval VAR Word 'New interval requested by user -Interval VAR Word 'Interval value utlized by firmware - -LFD CON $10 'Linefeed character - -Interval = 500 '.500 of a second interval -NewInterval = 500 - -Main: - - GOSUB PollSensor 'Was motion detected? - GOSUB RetrieveInterval 'Retrieve units data - -Timeout: - SEROUT 16, 16468, [DEC1 SensorID, DEC1 ElementSize, DEC1 ElementCount, DEC1 bMotion, DEC5 Interval,LFD] - GOTO Main - -PollSensor: - bMotion = IN0 ' Assign status of P0 to bMotion - RETURN - -RetrieveInterval: - SERIN 16, 16468, Interval, Timeout, [DEC NewInterval] 'Retrieve interval - IF NewInterval >= 10 AND NewInterval <= 60000 THEN - Interval = NewInterval - ENDIF - RETURN
\ No newline at end of file diff --git a/wpd/WpdBasicHardwareDriver/firmware/qti_wpd_enabled.bs2 b/wpd/WpdBasicHardwareDriver/firmware/qti_wpd_enabled.bs2 deleted file mode 100644 index fdfdff7c..00000000 --- a/wpd/WpdBasicHardwareDriver/firmware/qti_wpd_enabled.bs2 +++ /dev/null @@ -1,63 +0,0 @@ -' Qti_wpd_enabled.bs2 -' -' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF -' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO -' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A -' PARTICULAR PURPOSE. -' -' Copyright (c) Microsoft Corporation. All rights reserved -' -' {$STAMP BS2} -' {$PBASIC 2.5} -' ========================================================================= - -' -----[ I/O Definitions ]------------------------------------------------------ -LineSnsrPwr CON 10 ' line sensor power -LineSnsrIn CON 9 ' line sensor input - -' -----[ Constants ]------------------------------------------------------------ -'CLREOL CON 11 ' clear to end of line (DEBUG) - -' -----[ Variables ]------------------------------------------------------------ -Sense VAR Word ' sensor raw reading - -SensorID VAR Byte 'Sensor identifier = 5 for PIR -ElementSize VAR Byte 'Size (in bytes) of each element -ElementCount VAR Byte 'Count of elements in packet -Padding VAR Byte 'Padding for the 8-byte element -NewInterval VAR Word 'New interval requested by user -Interval VAR Word 'Interval value utlized by firmware - -SensorID = 7 -ElementSize = 1 -ElementCount = 4 '4-bytes for sensor data -Interval = 200 -NewInterval = 200 - -LFD CON $10 'Linefeed character - -' -----[ Main Code ]------------------------------------------------------------ -Main: - - GOSUB PollSensor 'Retrieve sensor value - GOSUB RetrieveInterval 'Retrieve units data - -Timeout: - SEROUT 16, 16468, [DEC1 SensorID, DEC1 ElementSize, DEC1 ElementCount, DEC4 Sense, DEC5 Interval, LFD] - GOTO Main - -PollSensor: - HIGH LineSnsrPwr ' activate sensor - HIGH LineSnsrIn ' discharge QTI cap - PAUSE 1 - RCTIME LineSnsrIn, 1, Sense ' read sensor value - LOW LineSnsrPwr ' deactivate sensor -RETURN - -RetrieveInterval: - SERIN 16, 16468, Interval, Timeout, [DEC NewInterval] 'Retrieve interval - IF NewInterval >= 10 AND NewInterval <= 60000 THEN - Interval = NewInterval - ENDIF - RETURN - diff --git a/wpd/WpdBasicHardwareDriver/firmware/temp_humidity_wpd_enabled.bs2 b/wpd/WpdBasicHardwareDriver/firmware/temp_humidity_wpd_enabled.bs2 deleted file mode 100644 index bc2982f7..00000000 --- a/wpd/WpdBasicHardwareDriver/firmware/temp_humidity_wpd_enabled.bs2 +++ /dev/null @@ -1,225 +0,0 @@ -' Temp_humidity_wpd_enabled.BS2 -' This program demonstrates the interface and conversion of SHT11/15 data -' to usable program values. This program uses advanced math features of -' PBASIC, specifically the ** operator. -' -' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF -' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO -' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A -' PARTICULAR PURPOSE. -' -' Copyright (c) Microsoft Corporation. All rights reserved -' -' {$STAMP BS2} -' {$PBASIC 2.5} - -' -' ========================================================================= -' ------------------------------------------------------------------------- -' I/O Definitions -' ------------------------------------------------------------------------- -ShtData PIN 1 ' bi-directional data -Clock PIN 0 -' ------------------------------------------------------------------------- -' Constants -' ------------------------------------------------------------------------- -ShtTemp CON %00011 ' read temperature -ShtHumi CON %00101 ' read humidity -ShtStatW CON %00110 ' status register write -ShtStatR CON %00111 ' status register read -ShtReset CON %11110 ' soft reset -Ack CON 0 -NoAck CON 1 -No CON 0 -Yes CON 1 -DegSym CON 186 ' degrees symbol for DEBUG -' ------------------------------------------------------------------------- -' Variables -' ------------------------------------------------------------------------- -ioByte VAR Byte ' data from/to SHT11 -ackBit VAR Bit ' ack/nak from/to SHT11 -toDelay VAR Byte ' timeout delay timer -timeOut VAR Bit ' timeout status -soT VAR Word ' temp counts from SHT11 -tC VAR Word ' temp - Celcius -tF VAR Word ' temp - Fahrenheit -soRH VAR Word ' humidity counts -rhLin VAR Word ' humidity; linearized -rhTrue VAR Word ' humidity; compensated -status VAR Byte ' status byte - -'------------------------------------------------------------------------- -' WPD Variables -'------------------------------------------------------------------------- -SensorID VAR Byte 'Sensor identifier = 2 for Sensiron Temp/Humidity -ElementSize VAR Byte 'Size (in bytes) of each element -ElementCount VAR Byte 'Count of elements in packet -Padding VAR Byte 'Padding for the 8-byte element - -SensorID = 2 -ElementSize = 1 -ElementCount = 7 '4-bytes for temp, 3-bytes for relative humidity - -NewInterval VAR Word 'New interval requested by user -Interval VAR Word 'Interval value utlized by firmware - -LFD CON $10 'Linefeed character - -Interval = 2000 -NewInterval = 2000 - -' ------------------------------------------------------------------------- -' EEPROM Data -' ------------------------------------------------------------------------- -' ------------------------------------------------------------------------- -' Initialization -' ------------------------------------------------------------------------- -Initialize: -GOSUB SHT_Connection_Reset ' reset device connection -' ------------------------------------------------------------------------- -' Program Code -' ------------------------------------------------------------------------- -Main: - GOSUB SHT_Measure_Temp 'Retrieve temperature - GOSUB SHT_Measure_Humidity 'Retrieve humidity - GOSUB RetrieveInterval 'Retrieve interval data - -SendData: - SEROUT 16, 16468, [DEC1 SensorID, DEC1 ElementSize, DEC1 ElementCount, DEC4 (tF), DEC3 (rhTrue), DEC5 Interval, LFD] - GOTO Main - -RetrieveInterval: - SERIN 16, 16468, Interval, SendData, [DEC NewInterval] 'Retrieve interval - IF NewInterval >= 10 AND NewInterval <= 60000 THEN - Interval = NewInterval - ENDIF -RETURN - -' ------------------------------------------------------------------------- -' Subroutines -' ------------------------------------------------------------------------- -' connection reset: 9 clock cyles with ShtData high, then start sequence -' -SHT_Connection_Reset: -SHIFTOUT ShtData, Clock, LSBFIRST, [$FFF\9] -' generates SHT11 "start" sequence -' _____ _____ -' ShtData |_______| -' ___ ___ -' Clock ___| |___| |___ -' -SHT_Start: -INPUT ShtData ' let pull-up take high -LOW Clock -HIGH Clock -LOW ShtData -LOW Clock -HIGH Clock -INPUT ShtData -LOW Clock -RETURN -' measure temperature -' -- celcius = raw * 0.01 - 40 -' -- fahrenheit = raw * 0.018 - 40 -' -SHT_Measure_Temp: -GOSUB SHT_Start ' alert device -ioByte = ShtTemp ' temperature command -GOSUB SHT_Write_Byte ' send command -GOSUB SHT_Wait ' wait for measurement -ackBit = Ack ' another read follows -GOSUB SHT_Read_Byte ' get MSB -soT.HIGHBYTE = ioByte -ackBit = NoAck ' last read -GOSUB SHT_Read_Byte ' get LSB -soT.LOWBYTE = ioByte -' Note: Conversion factors are multiplied by 10 to return the -' temperature values in tenths of degrees -tC = soT ** $1999 - 400 ' convert to tenths C -tF = soT ** $2E14 - 400 ' convert to tenths F -RETURN -' measure humidity -' -SHT_Measure_Humidity: -GOSUB SHT_Start ' alert device -ioByte = ShtHumi ' humidity command -GOSUB SHT_Write_Byte ' send command -GOSUB SHT_Wait ' wait for measurement -ackBit = Ack ' another read follows -GOSUB SHT_Read_Byte ' get MSB -soRH.HIGHBYTE = ioByte -ackBit = NoAck ' last read -GOSUB SHT_Read_Byte ' get LSB -soRH.LOWBYTE = ioByte -' linearize humidity -' rhLin = (soRH * 0.0405) - (soRH^2 * 0.0000028) - 4 -' -' for the BASIC Stamp: -' rhLin = (soRH * 0.0405) - (soRH * 0.002 * soRH * 0.0014) - 4 -' -' Conversion factors are multiplied by 10 to return tenths -' -rhLin = (soRH ** $67AE) - (soRH ** $83 * soRH ** $5B) - 40 -' temperature compensated humidity -' rhTrue = (tc - 25) * (soRH * 0.00008 + 0.01) + rhLin -' -' Conversion factors are multiplied by 10 to return tenths -' -- simplified -' -rhTrue = (tC - 250) * (soRH ** $34) + rhLin -RETURN -' sends "status" -' -SHT_Write_Status: -GOSUB SHT_Start ' alert device -ioByte = ShtStatW ' write to status reg cmd -GOSUB SHT_Write_Byte ' send command -ioByte = status -GOSUB SHT_Write_Byte -RETURN -' returns "status" -' -SHT_Read_Status: -GOSUB SHT_Start ' alert device -ioByte = ShtStatW ' write to status reg cmd -GOSUB SHT_Read_Byte ' send command -ackBit = NoAck ' only one byte to read -GOSUB SHT_Read_Byte -RETURN -' sends "ioByte" -' returns "ackBit" -' -SHT_Write_Byte: -SHIFTOUT ShtData, Clock, MSBFIRST, [ioByte] ' send byte -SHIFTIN ShtData, Clock, LSBPRE, [ackBit\1] ' get ack bit -RETURN -' returns "ioByte" -' sends "ackBit" -' -SHT_Read_Byte: -SHIFTIN ShtData, Clock, MSBPRE, [ioByte] ' get byte -SHIFTOUT ShtData, Clock, LSBFIRST, [ackBit\1] ' send ack bit -INPUT ShtData ' release data line -RETURN -' wait for device to finish measurement (pulls data line low) -' -- timeout after ~1/4 second -' -SHT_Wait: -INPUT ShtData ' data line is input -timeOut = No ' assume no timeout -FOR toDelay = 1 TO 250 ' wait ~1/4 second -IF (ShtData = 0) THEN EXIT -PAUSE 1 -NEXT -IF (toDelay = 250) THEN timeOut = Yes ' loop completed = timeout -RETURN - -' reset SHT11/15 with soft reset -' -SHT_Soft_Reset: -GOSUB SHT_Connection_Reset ' reset the connection -ioByte = ShtReset ' reset command -ackBit = NoAck ' only one byte to send -GOSUB SHT_Write_Byte ' send it -PAUSE 11 ' wait at least 11 ms -RETURN
\ No newline at end of file diff --git a/wpd/WpdBasicHardwareDriver/resource.h b/wpd/WpdBasicHardwareDriver/resource.h deleted file mode 100644 index 21979556..00000000 --- a/wpd/WpdBasicHardwareDriver/resource.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -#define IDR_WpdBasicHardwareDriver 101 - diff --git a/wpd/WpdBasicHardwareDriver/stdafx.h b/wpd/WpdBasicHardwareDriver/stdafx.h deleted file mode 100644 index 56150a64..00000000 --- a/wpd/WpdBasicHardwareDriver/stdafx.h +++ /dev/null @@ -1,320 +0,0 @@ -#pragma once - -#include "resource.h" -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#define STRSAFE_NO_DEPRECATE - -#include <stdio.h> -#include <tchar.h> - -#include <atlbase.h> -#include <atlcom.h> -#include <atlcoll.h> -#include <atlstr.h> -#include <strsafe.h> - -// This driver is entirely user-mode -_Analysis_mode_(_Analysis_code_type_user_code_); - -// -// Driver specific tracing #defines - -// -// TODO: Change these values to be appropriate for your driver. -// -#define MYDRIVER_TRACING_ID L"Microsoft\\WPD\\BasicHardwareDriver" - -// -// TODO: Choose a different trace control GUID -// - -#define WPP_CONTROL_GUIDS \ - WPP_DEFINE_CONTROL_GUID(BasicHardwareDriverCtlGuid,(80068de5,197d,4db6,b77c,29ee3cca4537), \ - WPP_DEFINE_BIT(TRACE_FLAG_ALL) \ - WPP_DEFINE_BIT(TRACE_FLAG_DEVICE) \ - WPP_DEFINE_BIT(TRACE_FLAG_DRIVER) \ - WPP_DEFINE_BIT(TRACE_FLAG_QUEUE) \ - ) - -#define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) \ - WPP_LEVEL_LOGGER(flags) - -#define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) \ - (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= lvl) - -// -// This comment block is scanned by the trace preprocessor to define our -// TraceEvents function. -// -// begin_wpp config -// FUNC Trace{FLAG=TRACE_FLAG_ALL}(LEVEL, MSG, ...); -// FUNC TraceEvents(LEVEL, FLAGS, MSG, ...); -// end_wpp - -// -// This comment block is scanned by the trace preprocessor to define our -// CHECK_HR function. -// -// -// begin_wpp config -// USEPREFIX (CHECK_HR,"%!STDPREFIX!"); -// FUNC CHECK_HR{FLAG=TRACE_FLAG_ALL}(hrCheck, MSG, ...); -// USESUFFIX (CHECK_HR, " hr= %!HRESULT!", hrCheck); -// end_wpp - -// -// PRE macro: The name of the macro includes the condition arguments FLAGS and EXP -// define in FUNC above -// -#define WPP_FLAG_hrCheck_PRE(FLAGS, hrCheck) {if(hrCheck != S_OK) { - -// -// POST macro -// The name of the macro includes the condition arguments FLAGS and EXP -// define in FUNC above -#define WPP_FLAG_hrCheck_POST(FLAGS, hrCheck) ; } } - -// -// The two macros below are for checking if the event should be logged and for -// choosing the logger handle to use when calling the ETW trace API -// -#define WPP_FLAG_hrCheck_ENABLED(FLAGS, hrCheck) WPP_FLAG_ENABLED(FLAGS) -#define WPP_FLAG_hrCheck_LOGGER(FLAGS, hrCheck) WPP_FLAG_LOGGER(FLAGS) - - -#include <PortableDevice.h> -#include <PortableDeviceTypes.h> -#include <PortableDeviceClassExtension.h> - -#include <initguid.h> // Required to access the DEFINE_GUID macro -#include <propkeydef.h> // Required to access the DEFINE_PROPERTYKEY macro - -// {CDD18979-A7B0-4D5E-9EB2-0A826805CBBD} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT, 0xCDD18979, 0xA7B0, 0x4D5E, 0x9E, 0xB2, 0x0A, 0x82, 0x68, 0x05, 0xCB, 0xBD, 2); -// {9BD949E5-59CF-41AE-90A9-BE1D044F578F} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT, 0x9BD949E5, 0x59CF, 0x41AE, 0x90, 0xA9, 0xBE, 0x1D, 0x04, 0x4F, 0x57, 0x8F, 2); -// {4DF6C8C7-2CE5-457C-9F53-EFCECAA95C04} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, 0x4DF6C8C7, 0x2CE5, 0x457C, 0x9F, 0x53, 0xEF, 0xCE, 0xCA, 0xA9, 0x5C, 0x04, 2); - -/**************************************************************************** -* This section defines the Functional Category associated with the sensor object -****************************************************************************/ - -// -// FUNCTIONAL_CATEGORY_SENSOR_SAMPLE -// Indicates this object encapsulates sensor functionality on the device -DEFINE_GUID (FUNCTIONAL_CATEGORY_SENSOR_SAMPLE, 0x09b93609, 0xd5c1,0x497b,0xb2, 0x52, 0xb4, 0x92, 0xcb, 0x5e, 0xfe, 0x52); - - -/**************************************************************************** -* This section defines all Commands, Parameters and Options associated with: -* SENSOR_PROPERTIES_V1 -* -* This category is for properties common to all sensor objects. -****************************************************************************/ -DEFINE_GUID (SENSOR_PROPERTIES_V1, 0xa7ef4367, 0x6550, 0x4055, 0xb6, 0x6f, 0xbe, 0x6f, 0xda, 0xcf, 0x4e, 0x9f); - -// -// SENSOR_READING -// [ VT_UI4 ] Indicates the sensor reading in degrees Kelvin. -DEFINE_PROPERTYKEY(SENSOR_READING, 0xa7ef4367, 0x6550, 0x4055, 0xb6, 0x6f, 0xbe, 0x6f, 0xda, 0xcf, 0x4e, 0x9f, 2); -// -// SENSOR_UPDATE_INTERVAL -// [ VT_UI4 ] Indicates the sensor update interval in milliseconds. -DEFINE_PROPERTYKEY(SENSOR_UPDATE_INTERVAL, 0xa7ef4367, 0x6550, 0x4055, 0xb6, 0x6f, 0xbe, 0x6f, 0xda, 0xcf, 0x4e, 0x9f, 3); - -/**************************************************************************** -* This section defines all Events associated with the sensor object -****************************************************************************/ -// -// EVENT_SENSOR_READING_UPDATED -// This event is sent after a new sensor reading is available on the device. -DEFINE_GUID (EVENT_SENSOR_READING_UPDATED, 0xada23b0b, 0xce13, 0x4e11, 0x9d, 0x2f, 0x15, 0xfe, 0x10, 0xd6, 0x63, 0x37); - - -// -// Macro Definitions -// - -#ifndef SAFE_RELEASE - #define SAFE_RELEASE(p) if( NULL != p ) { ( p )->Release(); p = NULL; } -#endif - -class ContextMap : public IUnknown -{ -public: - ContextMap() : - m_cRef(1) - { - - } - - ~ContextMap() - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - - IUnknown* pUnk = NULL; - POSITION elementPosition = NULL; - - elementPosition = m_Map.GetStartPosition(); - while(elementPosition != NULL) - { - pUnk = m_Map.GetNextValue(elementPosition); - if(pUnk != NULL) - { - pUnk->Release(); - } - } - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - return hr; - } - - -public: // Context accessor methods - - // If successful, this method AddRef's the context and returns - // a context key - HRESULT Add( - _In_ IUnknown* pContext, - _Out_ CAtlStringW& key) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - HRESULT hr = S_OK; - GUID guidContext = GUID_NULL; - CComBSTR bstrContext; - key = L""; - - // Create a unique context key - hr = CoCreateGuid(&guidContext); - if (hr == S_OK) - { - bstrContext = guidContext; - if(bstrContext.Length() > 0) - { - key = bstrContext; - } - else - { - hr = E_OUTOFMEMORY; - } - } - - if (hr == S_OK) - { - // Insert this into the map - POSITION elementPosition = m_Map.SetAt(key, pContext); - if(elementPosition != NULL) - { - // AddRef since we are holding onto it - pContext->AddRef(); - } - else - { - hr = E_OUTOFMEMORY; - } - } - return hr; - } - - void Remove( - _In_ const CAtlStringW& key) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - // Get the element - IUnknown* pContext = NULL; - - if (m_Map.Lookup(key, pContext) == true) - { - // Remove the entry for it - m_Map.RemoveKey(key); - - // Release it - pContext->Release(); - } - } - - // Returns the context pointer. If not found, return value is NULL. - // If non-NULL, caller is responsible for Releasing when it is done, - // since this method will AddRef the context. - IUnknown* GetContext( - _In_ const CAtlStringW& key) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - // Get the element - IUnknown* pContext = NULL; - - if (m_Map.Lookup(key, pContext) == true) - { - // AddRef - pContext->AddRef(); - } - return pContext; - } - -private: - CComAutoCriticalSection m_CriticalSection; - CAtlMap<CAtlStringW, IUnknown*> m_Map; - DWORD m_cRef; -}; - -HRESULT UpdateDeviceFriendlyName( - _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension, - _In_ LPCWSTR wszDeviceFriendlyName); - - -// Forward declaration of WpdBaseDriver as it is accessed by other classes -class WpdBaseDriver; - -#include "WpdBasicHardwareDriver.h" -#include "RS232Connection.h" -#include "RS232Target.h" -#include "WpdObjectEnum.h" -#include "WpdObjectProperties.h" -#include "WpdCapabilities.h" -#include "WpdBaseDriver.h" -#include "Device.h" -#include "Driver.h" -#include "Queue.h" - -extern HINSTANCE g_hInstance; - diff --git a/wpd/WpdHelloWorldDriver/Device.cpp b/wpd/WpdHelloWorldDriver/Device.cpp deleted file mode 100644 index 98b887e1..00000000 --- a/wpd/WpdHelloWorldDriver/Device.cpp +++ /dev/null @@ -1,443 +0,0 @@ -#include "stdafx.h" -#include "Device.h" -#include "WpdHelloWorldDriver_i.c" - -#include "Device.tmh" - -STDMETHODIMP_(HRESULT) -CDevice::OnD0Entry(_In_ IWDFDevice* /*pDevice*/, - WDF_POWER_DEVICE_STATE /*previousState*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnD0Exit(_In_ IWDFDevice* /*pDevice*/, - WDF_POWER_DEVICE_STATE /*newState*/) -{ - return S_OK; -} - -STDMETHODIMP_(VOID) -CDevice::OnSurpriseRemoval(_In_ IWDFDevice* /*pDevice*/) -{ - return; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnQueryRemove(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnQueryStop(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(VOID) -CDevice::OnSelfManagedIoCleanup(_In_ IWDFDevice* /*pDevice*/) -{ - return; -} - -STDMETHODIMP_(VOID) -CDevice::OnSelfManagedIoFlush(_In_ IWDFDevice* /*pDevice*/) -{ - return; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoInit(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoSuspend(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoRestart(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoStop(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnPrepareHardware(_In_ IWDFDevice* pDevice) -{ - HRESULT hr = S_OK; - - if (m_pWpdBaseDriver != NULL) - { - hr = m_pWpdBaseDriver->Initialize(); - CHECK_HR(hr, "Failed to Initialize the driver class"); - } - - // Initialize the WPD Class Extension. This will enable the appropriate WPD interface GUID, - // as well as do any additional initialization (e.g. enabling Legacy Compatibility layers for those drivers - // which requested support in their INF). - if (hr == S_OK && m_pPortableDeviceClassExtension == NULL) - { - CComPtr<IPortableDeviceValues> pOptions; - CComPtr<IPortableDevicePropVariantCollection> pContentTypes; - - hr = CoCreateInstance(CLSID_PortableDeviceClassExtension, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceClassExtension, - (VOID**)&m_pPortableDeviceClassExtension); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceClassExtension"); - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pOptions); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - - if (hr == S_OK) - { - // Get supported content types - if (hr == S_OK) - { - hr = GetSupportedContentTypes(&pContentTypes); - CHECK_HR(hr, "Failed to get supported content types"); - } - - // Add the supported types to the options - if (hr == S_OK) - { - hr = pOptions->SetIPortableDevicePropVariantCollectionValue(WPD_CLASS_EXTENSION_OPTIONS_SUPPORTED_CONTENT_TYPES, pContentTypes); - CHECK_HR(hr, "Failed to set WPD_CLASS_EXTENSION_OPTIONS_SUPPORTED_CONTENT_TYPES"); - } - - // Initialize the PortableDeviceClassExtension with a list of supported content types for the - // connected device. This will ensure that the correct application compatibility settings will - // be applied for your device. - if (hr == S_OK) - { - hr = m_pPortableDeviceClassExtension->Initialize(pDevice, pOptions); - CHECK_HR(hr, "Failed to Initialize portable device class extension object"); - } - - // Since users commonly have the abiltity to customize their device even when it is not - // connected to the PC, we need to make sure the PC is current when the driver loads. - // - // Send the latest device friendly name to the PortableDeviceClassExtension component - // so the system is always updated with the current device name. - // - // This call should also be made after a successful property set operation of - // WPD_DEVICE_FRIENDLY_NAME. - - LPWSTR wszDeviceFriendlyName = NULL; - - if (hr == S_OK) - { - hr = GetDeviceFriendlyName(&wszDeviceFriendlyName); - CHECK_HR(hr, "Failed to get device's friendly name"); - } - - if (hr == S_OK && wszDeviceFriendlyName != NULL) - { - hr = UpdateDeviceFriendlyName(m_pPortableDeviceClassExtension, wszDeviceFriendlyName); - CHECK_HR(hr, "Failed to update device's friendly name"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszDeviceFriendlyName); - } - } - } - - return hr; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnReleaseHardware(_In_ IWDFDevice* /*pDevice*/) -{ - if (m_pWpdBaseDriver != NULL) - { - m_pWpdBaseDriver->Uninitialize(); - } - - if (m_pPortableDeviceClassExtension != NULL) - { - m_pPortableDeviceClassExtension = NULL; - } - - return S_OK; -} - -HRESULT CDevice::GetSupportedContentTypes( - _Outptr_ IPortableDevicePropVariantCollection** ppContentTypes) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - - if (ppContentTypes == NULL) - { - hr = E_INVALIDARG; - return hr; - } - - *ppContentTypes = NULL; - - // CoCreate a collection to store the WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES command parameters. - if(SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES command results. - if(SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Set the params - if(SUCCEEDED(hr)) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - if(SUCCEEDED(hr)) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - if(SUCCEEDED(hr)) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY, WPD_FUNCTIONAL_CATEGORY_ALL); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY")); - } - - // Make the call - if(SUCCEEDED(hr)) - { - hr = m_pWpdBaseDriver->DispatchWpdMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to dispatch message to get supported content types")); - } - - // Get the results - if(SUCCEEDED(hr)) - { - hr = pResults->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES, ppContentTypes); - CHECK_HR(hr, ("Failed to get WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES")); - } - - return hr; -} - -HRESULT CDevice::GetDeviceFriendlyName( - _Outptr_result_maybenull_ LPWSTR* pwszDeviceFriendlyName) -{ - HRESULT hr = S_OK; - - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<IPortableDeviceKeyCollection> pKeys; - CComPtr<IPortableDeviceValues> pValues; - - if (pwszDeviceFriendlyName == NULL) - { - hr = E_INVALIDARG; - return hr; - } - - *pwszDeviceFriendlyName = NULL; - - // CoCreate a collection to store the WPD_COMMAND_OBJECT_PROPERTIES_GET command parameters. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the WPD_COMMAND_OBJECT_PROPERTIES_GET command results. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the requested property keys. In our case, we are requesting just the device friendly name - // (WPD_DEVICE_FRIENDLY_NAME) - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**)&pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection for results"); - } - - // Set the params - if (hr == S_OK) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_OBJECT_PROPERTIES_GET.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - - if (hr == S_OK) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_OBJECT_PROPERTIES_GET.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - - if (hr == S_OK) - { - hr = pParams->SetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID")); - } - - if (hr == S_OK) - { - hr = pKeys->Add(WPD_DEVICE_FRIENDLY_NAME); - CHECK_HR(hr, ("Failed to add WPD_DEVICE_FRIENDLY_NAME to key collection")); - } - - if (hr == S_OK) - { - hr = pParams->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, pKeys); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS")); - } - - // Make the call - if (hr == S_OK) - { - hr = m_pWpdBaseDriver->DispatchWpdMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to dispatch message to get supported content types")); - } - - // Get the results - if (hr == S_OK) - { - hr = pResults->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, &pValues); - CHECK_HR(hr, ("Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES")); - } - - if (hr == S_OK) - { - hr = pValues->GetStringValue(WPD_DEVICE_FRIENDLY_NAME, pwszDeviceFriendlyName); - CHECK_HR(hr, ("Failed to get WPD_DEVICE_FRIENDLY_NAME")); - } - - return hr; -} - -HRESULT UpdateDeviceFriendlyName( - _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension, - _In_ LPCWSTR wszDeviceFriendlyName) -{ - HRESULT hr = S_OK; - - // If we were passed NULL parameters we have nothing to do, return S_OK. - if ((pPortableDeviceClassExtension == NULL) || - (wszDeviceFriendlyName == NULL)) - { - return S_OK; - } - - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<IPortableDeviceValues> pValues; - - // Prepare to make a call to set the device information - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues for results"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues for results"); - } - - // Get the information values to update and set them in WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES - if (hr == S_OK) - { - hr = pValues->SetStringValue(WPD_DEVICE_FRIENDLY_NAME, wszDeviceFriendlyName); - CHECK_HR(hr, ("Failed to set WPD_DEVICE_FRIENDLY_NAME")); - } - - // Set the params - if (hr == S_OK) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_CLASS_EXTENSION_WRITE_DEVICE_INFORMATION.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - if (hr == S_OK) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_CLASS_EXTENSION_WRITE_DEVICE_INFORMATION.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - if (hr == S_OK) - { - hr = pParams->SetIPortableDeviceValuesValue(WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES, pValues); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES")); - } - - // Make the call - if (hr == S_OK) - { - hr = pPortableDeviceClassExtension->ProcessLibraryMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to process update device information message")); - } - - // A Failed ProcessLibraryMessage operation for updating this value is not considered - // fatal and should return S_OK. - - return S_OK; -} diff --git a/wpd/WpdHelloWorldDriver/Device.h b/wpd/WpdHelloWorldDriver/Device.h deleted file mode 100644 index 8c5a2e99..00000000 --- a/wpd/WpdHelloWorldDriver/Device.h +++ /dev/null @@ -1,91 +0,0 @@ -#pragma once - -#include "resource.h" -#include "WpdHelloWorldDriver.h" - -class ATL_NO_VTABLE CDevice : - public CComObjectRootEx<CComMultiThreadModel>, - public IPnpCallback, - public IPnpCallbackSelfManagedIo, - public IPnpCallbackHardware -{ -public: - CDevice() : - m_pWpdBaseDriver(NULL) - { - } - - DECLARE_NOT_AGGREGATABLE(CDevice) - - BEGIN_COM_MAP(CDevice) - COM_INTERFACE_ENTRY(IPnpCallback) - COM_INTERFACE_ENTRY(IPnpCallbackSelfManagedIo) - COM_INTERFACE_ENTRY(IPnpCallbackHardware) - END_COM_MAP() - -public: - static HRESULT - CreateInstance( - _In_ IWDFDeviceInitialize* pDeviceInit, - _In_ WpdBaseDriver* pWpdBaseDriver, - _COM_Outptr_ IUnknown** ppUnkwn) - { - *ppUnkwn = NULL; - - // - // Set device properties. - // - pDeviceInit->SetLockingConstraint(None); - - CComObject< CDevice> *pMyDevice = NULL; - HRESULT hr = CComObject<CDevice>::CreateInstance( &pMyDevice ); - if( SUCCEEDED (hr) ) - { - pMyDevice->AddRef(); - hr = pMyDevice->QueryInterface( __uuidof(IUnknown),(void **) ppUnkwn); - if (hr == S_OK) - { - pMyDevice->m_pWpdBaseDriver = pWpdBaseDriver; - } - pMyDevice->Release(); - pMyDevice = NULL; - } - - return hr; - } - - // IPnpCallback - // - STDMETHOD_(HRESULT, OnD0Entry) (_In_ IWDFDevice* pDevice, WDF_POWER_DEVICE_STATE previousState); - STDMETHOD_(HRESULT, OnD0Exit) (_In_ IWDFDevice* pDevice, WDF_POWER_DEVICE_STATE newState); - STDMETHOD_(VOID, OnSurpriseRemoval)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnQueryRemove) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnQueryStop) (_In_ IWDFDevice* pDevice); - - // IPnpCallbackSelfManagedIo - // - STDMETHOD_(VOID, OnSelfManagedIoCleanup)(_In_ IWDFDevice* pDevice); - STDMETHOD_(VOID, OnSelfManagedIoFlush) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoInit) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoSuspend)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoRestart)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoStop) (_In_ IWDFDevice* pDevice); - - // IPnpCallbackHardware - // - STDMETHOD_(HRESULT, OnPrepareHardware)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnReleaseHardware)(_In_ IWDFDevice* pDevice); - -private: - HRESULT GetSupportedContentTypes( - _Outptr_ IPortableDevicePropVariantCollection** ppContentTypes); - - HRESULT GetDeviceFriendlyName( - _Outptr_result_maybenull_ LPWSTR* pwszDeviceFriendlyName); - -private: - - WpdBaseDriver* m_pWpdBaseDriver; - CComPtr<IPortableDeviceClassExtension> m_pPortableDeviceClassExtension; -}; - diff --git a/wpd/WpdHelloWorldDriver/Driver.cpp b/wpd/WpdHelloWorldDriver/Driver.cpp deleted file mode 100644 index 12473bf6..00000000 --- a/wpd/WpdHelloWorldDriver/Driver.cpp +++ /dev/null @@ -1,192 +0,0 @@ -#include "stdafx.h" -#include "Driver.h" -#include "Device.h" -#include "Queue.h" - -CDriver::CDriver() -{ -} - -HRESULT -CDriver::OnDeviceAdd( - _In_ IWDFDriver* pDriver, - _In_ IWDFDeviceInitialize* pDeviceInit - ) -/*++ - -Routine Description: - - The framework calls this function when a device is being added to - the driver stack. - -Arguments: - - IWDFDriver - Framework interface. The driver uses this - interface to create device objects. - IWDFDeviceInitialize - Framework interface. The driver uses this - interface to set device parameters before - creating the device obeject. - -Return Value: - - HRESULT S_OK - Device added successfully - ---*/ -{ - HRESULT hr = S_OK; - CComPtr<IUnknown> pDeviceCallback; - - WpdBaseDriver *pWpdBaseDriver = NULL; - - // - // Create the WPD driver object that handles all WPD messages for this device - // - pWpdBaseDriver = new WpdBaseDriver(); - if(pWpdBaseDriver == NULL) - { - hr = E_OUTOFMEMORY; - } - - if(SUCCEEDED(hr)) - { - // - // Create device callback object - // - hr = CDevice::CreateInstance(pDeviceInit, pWpdBaseDriver, &pDeviceCallback); - } - - // - // This driver has no special power management requirements and so - // we set power policy ownership to UMDF to indicate that UMDF should - // handle powermanagement for us. - // - pDeviceInit->SetPowerPolicyOwnership(FALSE); - - // - // Create WDFDevice. - // - CComPtr<IWDFDevice> pIWDFDevice; - if(SUCCEEDED(hr)) - { - hr = pDriver->CreateDevice( - pDeviceInit, - pDeviceCallback, - &pIWDFDevice); - } - - // - // Assign pWpdBaseDriver to the device object. Each UMDF device requires its own instance of - // a WpdBaseDriver to handle WPD messages. - // - if(SUCCEEDED(hr)) - { - hr = pIWDFDevice->AssignContext(this, (void*)pWpdBaseDriver); - if(SUCCEEDED(hr)) - { - // AddRef the WpdBaseDriver object since it is not stored with the - // device context. - pWpdBaseDriver->AddRef(); - } - } - - // - // Create queue callback object - // - CComPtr<IUnknown> pIUnknown; - if(S_OK == hr) - { - hr = CQueue::CreateInstance(&pIUnknown); - } - - // - // Configure the default queue. - // - if(S_OK == hr) - { - CComPtr<IWDFIoQueue> pDefaultQueue; - hr = pIWDFDevice->CreateIoQueue( - pIUnknown, - TRUE, // bDefaultQueue - WdfIoQueueDispatchSequential, - TRUE, // bPowerManaged - FALSE, // bAllowZeroLengthRequests - &pDefaultQueue); - } - - pDeviceCallback = NULL; - pIWDFDevice = NULL; - - // - // It is fine to release the interface on the callback object. - // The framework has its own refcount on this object and will - // provide an interface when calling into the driver. - // - pIUnknown = NULL; - - // Release the WpdBaseDriver object. If it was successfully added to the device context, - // it was already addref'd above. Releasing it here ensures it will be destroyed if - // an error occured and it could not be added to the device context. - SAFE_RELEASE(pWpdBaseDriver); - - return hr; -} - -void -CDriver::OnDeinitialize( - _In_ IWDFDriver* pDriver - ) -/*++ - -Routine Description: - - The framework calls this function just before de-initializing itself. All - WDF framework resources should be released by driver before returning from this call. - -Arguments: - -Return Value: - ---*/ -{ - UNREFERENCED_PARAMETER(pDriver); - return; -} - -HRESULT -CDriver::OnInitialize( - _In_ IWDFDriver* pDriver - ) -/*++ - -Routine Description: - - The framework calls this function just after loading the driver. The driver can - perform any global, device independent intialization in this routine. - -Arguments: - -Return Value: - ---*/ -{ - UNREFERENCED_PARAMETER(pDriver); - return S_OK; -} - -STDMETHODIMP_ (void) -CDriver::OnCleanup( - _In_ IWDFObject* pWdfObject - ) -{ - // Release the base driver object - HRESULT hr = S_OK; - WpdBaseDriver* pWpdBaseDriver = NULL; - - hr = pWdfObject->RetrieveContext((void**)&pWpdBaseDriver); - if((hr == S_OK) && (pWpdBaseDriver != NULL)) - { - pWpdBaseDriver->Release(); - pWpdBaseDriver = NULL; - } -} - diff --git a/wpd/WpdHelloWorldDriver/Driver.h b/wpd/WpdHelloWorldDriver/Driver.h deleted file mode 100644 index 4e126aaa..00000000 --- a/wpd/WpdHelloWorldDriver/Driver.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "resource.h" -#include "WpdHelloWorldDriver.h" - -class ATL_NO_VTABLE CDriver : - public CComObjectRootEx<CComMultiThreadModel>, - public CComCoClass<CDriver, &CLSID_WpdHelloWorldDriver>, - public IDriverEntry, - public IObjectCleanup -{ -public: - CDriver(); - - DECLARE_REGISTRY_RESOURCEID(IDR_WpdHelloWorldDriver) - - DECLARE_NOT_AGGREGATABLE(CDriver) - - BEGIN_COM_MAP(CDriver) - COM_INTERFACE_ENTRY(IDriverEntry) - END_COM_MAP() - -public: - // - // IDriverEntry - // - STDMETHOD (OnInitialize)( - _In_ IWDFDriver* pDriver - ); - STDMETHOD (OnDeviceAdd)( - _In_ IWDFDriver* pDriver, - _In_ IWDFDeviceInitialize* pDeviceInit - ); - STDMETHOD_ (void, OnDeinitialize)( - _In_ IWDFDriver* pDriver - ); - - // - // IObjectCleanup - // - STDMETHOD_ (void, OnCleanup)( - _In_ IWDFObject* pWdfObject - ); -}; - -OBJECT_ENTRY_AUTO(__uuidof(WpdHelloWorldDriver), CDriver) - diff --git a/wpd/WpdHelloWorldDriver/Queue.cpp b/wpd/WpdHelloWorldDriver/Queue.cpp deleted file mode 100644 index 32b0a597..00000000 --- a/wpd/WpdHelloWorldDriver/Queue.cpp +++ /dev/null @@ -1,335 +0,0 @@ -// Queue.cpp : Implementation of CQueue - - -#include "stdafx.h" -#include "Queue.h" -#include <devioctl.h> -#include <initguid.h> - -#include "Queue.tmh" - -// Add table used to lookup the Access required for Wpd Commands -BEGIN_WPD_COMMAND_ACCESS_MAP(g_WpdCommandAccessMap) - DECLARE_WPD_STANDARD_COMMAND_ACCESS_ENTRIES - // Add any custom commands here e.g. - // WPD_COMMAND_ACCESS_ENTRY(MyCustomCommand, WPD_COMMAND_ACCESS_READWRITE) -END_WPD_COMMAND_ACCESS_MAP - -// This enables use to use VERIFY_WPD_COMMAND_ACCESS to check command access function for us. -DECLARE_VERIFY_WPD_COMMAND_ACCESS; - -/****************************************************************************** - * This function calls the WpdBaseDriver to handle the WPD message. In order - * to do this it does the following: - * - * - Deserializes pBuffer into an IPortableDeviceValues which holds the command - * input parameters from the WPD application. - * - Creates an IPortableDeviceValues for the results. - * - Calls the WpdBaseDriver to handle the message. (The results of this - * operation are put into the previously created results IPortableDeviceValues.) - * - The results IPortableDeviceValues is then serialized back into pBuffer, making - * sure that it does not overrun ulOutputBufferLength. - * - *****************************************************************************/ -HRESULT CQueue::ProcessWpdMessage( - ULONG ControlCode, - _In_ ContextMap* pClientContextMap, - _In_ IWDFDevice* pDevice, - _In_reads_bytes_(ulInputBufferLength) PVOID pInBuffer, - ULONG ulInputBufferLength, - _Out_writes_bytes_to_(ulOutputBufferLength, *pdwBytesWritten) PVOID pOutBuffer, - ULONG ulOutputBufferLength, - _Out_ DWORD* pdwBytesWritten) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<WpdBaseDriver> pWpdBaseDriver; - - *pdwBytesWritten = 0; - - if (hr == S_OK) - { - hr = m_pWpdSerializer->GetIPortableDeviceValuesFromBuffer((BYTE*)pInBuffer, - ulInputBufferLength, - &pParams); - CHECK_HR(hr, "Failed to deserialize command parameters from input buffer"); - } - - // Verify that that command was sent with the appropriate access - if (hr == S_OK) - { - hr = VERIFY_WPD_COMMAND_ACCESS(ControlCode, pParams, g_WpdCommandAccessMap); - CHECK_HR(hr, "Wpd Command was sent with incorrect access flags"); - } - - // Create the WPD results collection - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Insert the client context map as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the context map. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, pClientContextMap); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Insert the IWDFDevice interface as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the WUDF Device object. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT, pDevice); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT"); - } - - // Insert the IWpdSerializer interface as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the WPD Serializer object. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT, m_pWpdSerializer); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT"); - } - - // Get the WpdBaseDriver so we can dispatch the message - if (hr == S_OK) - { - hr = GetWpdBaseDriver(pDevice, &pWpdBaseDriver); - CHECK_HR(hr, "Failed to get WpdBaseDriver"); - } - - if (hr == S_OK) - { - hr = pWpdBaseDriver->DispatchWpdMessage(pParams, pResults); - CHECK_HR(hr, "Failed to handle WPD command"); - } - - if (hr == S_OK) - { - hr = m_pWpdSerializer->WriteIPortableDeviceValuesToBuffer(ulOutputBufferLength, - pResults, - (BYTE*)pOutBuffer, - pdwBytesWritten); - CHECK_HR(hr, "Failed to serialize results to output buffer"); - } - - return hr; -} - -/****************************************************************************** - * This method gets the WpdBaseDriver associated with the UMDF device object. - * The caller should Release *ppWpdBaseDriver when it is done. - * - * When this device was created, we assigned the WpdBaseDriver as the context. - * So, in order to retrieve the correct WpdBaseDriver for this device, we simply - * get the device context. - *****************************************************************************/ -HRESULT CQueue::GetWpdBaseDriver( - _In_ IWDFDevice* pDevice, - _Outptr_result_nullonfailure_ WpdBaseDriver** ppWpdBaseDriver) -{ - HRESULT hr = S_OK; - WpdBaseDriver* pContext = NULL; - - if((pDevice == NULL) || (ppWpdBaseDriver == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter for pDevice or ppWpdBaseDriver"); - } - - *ppWpdBaseDriver = NULL; - - if(SUCCEEDED(hr)) - { - hr = pDevice->RetrieveContext((void**)&pContext); - if(SUCCEEDED(hr)) - { - if(pContext != NULL) - { - pContext->AddRef(); - *ppWpdBaseDriver = pContext; - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Device context is NULL"); - } - } - } - - return hr; -} - -// CQueue - -STDMETHODIMP_ (void) -CQueue::OnCreateFile( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - _In_ IWDFFile* pFileObject - ) -{ - UNREFERENCED_PARAMETER(pQueue); - // This critical section protects the section of code where we - // Create the serializer and results interfaces used in handling I/O messages. - // We only need to create them once, then we hang on to them for the lifetime of this - // queue object. - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - HRESULT hr = S_OK; - - // Create the WPD serializer - if ((hr == S_OK) && - (m_pWpdSerializer == NULL)) - { - hr = CoCreateInstance(CLSID_WpdSerializer, - NULL, - CLSCTX_INPROC_SERVER, - IID_IWpdSerializer, - (VOID**)&m_pWpdSerializer); - - CHECK_HR(hr, "Failed to CoCreate CLSID_WpdSerializer"); - } - - // Create the client context map and associate it with the File Object - // so we can obtain it on a per-client basis. - if (hr == S_OK) - { - ContextMap* pClientContextMap = new ContextMap(); - - if(pClientContextMap != NULL) - { - hr = pFileObject->AssignContext(this, (void*)pClientContextMap); - CHECK_HR(hr, "Failed to set client context map"); - - // Release the client context map if we cannot set it - // properly - if(FAILED(hr)) - { - pClientContextMap->Release(); - pClientContextMap = NULL; - } - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to create client context map"); - } - } - - pRequest->Complete(hr); - return; -} - -STDMETHODIMP_ (void) -CQueue::OnDeviceIoControl( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - ULONG ControlCode, - SIZE_T InputBufferSizeInBytes, - SIZE_T OutputBufferSizeInBytes - ) -{ - UNREFERENCED_PARAMETER(InputBufferSizeInBytes); - UNREFERENCED_PARAMETER(OutputBufferSizeInBytes); - HRESULT hr = S_OK; - DWORD dwBytesWritten = 0; - - if(IS_WPD_IOCTL(ControlCode)) - { - BYTE* pInputBuffer = NULL; - SIZE_T cbInputBuffer = 0; - BYTE* pOutputBuffer = NULL; - SIZE_T cbOutputBuffer = 0; - ContextMap* pClientContextMap = NULL; - CComPtr<IWDFMemory> pMemoryIn; - CComPtr<IWDFMemory> pMemoryOut; - CComPtr<IWDFDevice> pDevice; - CComPtr<IWDFFile> pFileObject; - - // - // Get input memory buffer, the memory object is always returned even if the - // underlying buffer is NULL - // - pRequest->GetInputMemory(&pMemoryIn); - pInputBuffer = (BYTE*) pMemoryIn->GetDataBuffer(&cbInputBuffer); - - // - // Get output memory buffer, the memory object is always returned even if the - // underlying buffer is NULL - // - pRequest->GetOutputMemory(&pMemoryOut); - pOutputBuffer = (BYTE*) pMemoryOut->GetDataBuffer(&cbOutputBuffer); - - // Get the Context map for this client - pRequest->GetFileObject(&pFileObject); - if (pFileObject != NULL) - { - hr = pFileObject->RetrieveContext((void**)&pClientContextMap); - CHECK_HR(hr, "Failed to get Contextmap from WDF File Object"); - - if (hr == S_OK) - { - // Get the device object - pQueue->GetDevice(&pDevice ); - hr = ProcessWpdMessage(ControlCode, - pClientContextMap, - pDevice, - pInputBuffer, - (DWORD)cbInputBuffer, - pOutputBuffer, - (DWORD)cbOutputBuffer, - &dwBytesWritten); - } - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "WDF File Object is NULL"); - } - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Received invalid/unsupported IOCTL code '0x%lx'",ControlCode); - } - - // Complete the request - if (hr == S_OK) - { - pRequest->CompleteWithInformation(hr, dwBytesWritten); - } - else - { - pRequest->Complete(hr); - } - - return; -} - -STDMETHODIMP_ (void) -CQueue::OnCleanup( - _In_ IWDFObject* pWdfObject - ) -{ - // Destroy the client context map - HRESULT hr = S_OK; - ContextMap* pClientContextMap = NULL; - - hr = pWdfObject->RetrieveContext((void**)&pClientContextMap); - if((hr == S_OK) && (pClientContextMap != NULL)) - { - pClientContextMap->Release(); - pClientContextMap = NULL; - } -} - diff --git a/wpd/WpdHelloWorldDriver/Queue.h b/wpd/WpdHelloWorldDriver/Queue.h deleted file mode 100644 index a159737a..00000000 --- a/wpd/WpdHelloWorldDriver/Queue.h +++ /dev/null @@ -1,92 +0,0 @@ -// Queue.h : Declaration of the CQueue - -#pragma once -#include "resource.h" // main symbols -#include "WpdHelloWorldDriver.h" - -class ATL_NO_VTABLE CQueue : - public CComObjectRootEx<CComMultiThreadModel>, - public IQueueCallbackDeviceIoControl, - public IQueueCallbackCreate, - public IObjectCleanup -{ -public: - CQueue() - { - - } - - DECLARE_NOT_AGGREGATABLE(CQueue) - - BEGIN_COM_MAP(CQueue) - COM_INTERFACE_ENTRY(IQueueCallbackDeviceIoControl) - COM_INTERFACE_ENTRY(IQueueCallbackCreate) - END_COM_MAP() - -public: - static - HRESULT CreateInstance( - _COM_Outptr_ IUnknown** ppUkwn) - { - *ppUkwn = NULL; - CComObject< CQueue> *pMyQueue = NULL; - HRESULT hr = CComObject<CQueue>::CreateInstance( &pMyQueue ); - if( SUCCEEDED (hr) ) - { - pMyQueue->AddRef(); - hr = pMyQueue->QueryInterface( __uuidof(IUnknown), (void **) ppUkwn ); - pMyQueue->Release(); - pMyQueue = NULL; - } - return hr; - } - - // - // Wdf Callbacks - // - - // IQueueCallbackCreateClose - // - STDMETHOD_ (void, OnCreateFile)( - _In_ IWDFIoQueue *pQueue, - _In_ IWDFIoRequest *pRequest, - _In_ IWDFFile *pFileObject - ); - - // - // IQueueCallbackDeviceIoControl - // - STDMETHOD_ (void, OnDeviceIoControl)( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - ULONG ControlCode, - SIZE_T InputBufferSizeInBytes, - SIZE_T OutputBufferSizeInBytes - ); - - // - // IObjectCleanup - // - STDMETHOD_ (void, OnCleanup)( - _In_ IWDFObject* pWdfObject - ); - -private: - HRESULT ProcessWpdMessage( - ULONG ControlCode, - _In_ ContextMap* pClientContextMap, - _In_ IWDFDevice* pDevice, - _In_reads_bytes_(ulInputBufferLength) PVOID pInBuffer, - ULONG ulInputBufferLength, - _Out_writes_bytes_to_(ulOutputBufferLength, *pdwBytesWritten) PVOID pOutBuffer, - ULONG ulOutputBufferLength, - _Out_ DWORD* pdwBytesWritten); - - HRESULT GetWpdBaseDriver( - _In_ IWDFDevice* pDevice, - _Outptr_result_nullonfailure_ WpdBaseDriver** ppWpdBaseDriver); - - CComPtr<IWpdSerializer> m_pWpdSerializer; - CComAutoCriticalSection m_CriticalSection; -}; - diff --git a/wpd/WpdHelloWorldDriver/README.md b/wpd/WpdHelloWorldDriver/README.md deleted file mode 100644 index 6942f4c6..00000000 --- a/wpd/WpdHelloWorldDriver/README.md +++ /dev/null @@ -1,78 +0,0 @@ ---- -page_type: sample -description: "Supports four objects - a device object, a storage object, a folder object, and a file object." -languages: -- cpp -products: -- windows -- windows-wdk ---- - -# WPDHelloWorld sample driver for portable devices - -The WpdHelloWorld sample driver supports four objects: a device object, a storage object, a folder object, and a file object. Each object supports corresponding properties. These properties are defined in the file WpdObjectProperties.h. - -The sample driver supports a device object that exposes ten read-only properties. These properties, their types, and their values are listed in the following table. - -| Property name | Property type | Value | -| --- | --- | --- | -| DEVICE_PROTOCOL | String | "Hello World Protocol ver 1.00" | -| DEVICE_FIRMWARE_VERSION | String | "1.0.0.0" | -| DEVICE_POWER_LEVEL | Integer | 100 | -| DEVICE_MODEL | String | "Hello World!" | -| DEVICE_MANUFACTURER | String | "Windows Portable Devices Group" | -| DEVICE_FRIENDLY | String | "Hello World!" | -| DEVICE_SERIAL_NUMBER | String | "01234567890123-45676890123456" | -| DEVICE_SUPPORTS_NONCONSUMABLE | Bool | True | -| WPD_DEVICE_TYPE | Integer | WPD_DEVICE_TYPE_GENERIC | -| WPD_FUNCTIONAL_OBJECT_CATEGORY | GUID | WPD_FUNCTIONAL_CATEGORY_STORAGE | - -The driver supports a storage object that exposes seven read-only properties. These properties, their types, and their values are listed in the following table. - -| Property name | Property type | Value | -| --- | --- | --- | -| STORAGE_CAPACITY | 64-bit Integer | 1024 * 1024 | -| STORAGE_FREE_SPACE_IN_BYTES | 64-bit Integer | 1024 * 1024 | -| STORAGE_SERIAL_NUMBER | String | 98765432109876-54321098765432 | -| STORAGE_FILE_SYSTEM_TYPE | String | FAT32 | -| STORAGE_DESCRIPTION | String | Hello World! Memory Storage System | -| WPD_STORAGE_TYPE | Integer | WPD_STORAGE_TYPE_FIXED_ROM | -| WPD_FUNCTIONAL_OBJECT_CATEGORY | GUID | WPD_FUNCTIONAL_CATEGORY_STORAGE | - -The driver supports a folder object that exposes three read-only properties. These properties, their types, and their values are listed in the following table. - -| Property name | Property type | Value | -| --- | --- | --- | -| WPD_OBJECT_DATE_MODIFIED | Date | 2006/6/26 5:0:0.0 | -| WPD_OBJECT_DATE_CREATED | Date | 2006/1/25 12:0:0.0 | -| WPD_OBJECT_ORIGINAL_FILE_NAME_VALUE | String | Documents | - -The driver supports a file object that exposes three read-only properties. These properties, their types, and their values are listed in the following table. - -| Property name | Property type | Value | -| --- | --- | --- | -| WPD_OBJECT_DATE_MODIFIED | Date | 2006/6/26 5:0:0.0 | -| WPD_OBJECT_DATE_CREATED | Date | 2006/1/25 12:0:0.0 | -| WPD_OBJECT_ORIGINAL_FILE_NAME | String | Readme.txt | - -In addition to the above properties, every object (for example, device, storage, folder, or file) also supports seven common WPD object properties. These are read-only properties that contain object-specific values for the most part. These properties, their types, and their values are listed in the following table. - -| Property name | Property type | Value | -| --- | --- | --- | -| WPD_OBJECT_ID | String | Object-specific | -| WPD_OBJECT_PERSISTENT_UNIQUE_ID | String | Object-specific | -| WPD_OBJECT_PARENT_ID | String | Object-specific | -| WPD_OBJECT_NAME | String | Object-specific | -| WPD_OBJECT_FORMAT | GUID | Object-specific | -| WPD_OBJECT_CONTENT_TYPE | GUID | Object-specific | -| WPD_OBJECT_CAN_DELETE | Bool | False | - -For a complete description of this sample and its underlying code and functionality, refer to the [WPD HelloWorld Driver](https://docs.microsoft.com/windows-hardware/drivers/portable/the-sample-driver-architecture) description in the Windows Driver Kit documentation. - -## Related topics - -[WPD Design Guide](https://docs.microsoft.com/windows-hardware/drivers/portable/wpd-design-guide) - -[WPD Driver Development Tools](https://docs.microsoft.com/windows-hardware/drivers/portable/familiarizing-yourself-with-the-sample-driver) - -[WPD Programming Guide](https://docs.microsoft.com/windows-hardware/drivers/portable/wpd-programming-guide) diff --git a/wpd/WpdHelloWorldDriver/Stdafxsrc.cpp b/wpd/WpdHelloWorldDriver/Stdafxsrc.cpp deleted file mode 100644 index 5105a28d..00000000 --- a/wpd/WpdHelloWorldDriver/Stdafxsrc.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Stdafx.h"
\ No newline at end of file diff --git a/wpd/WpdHelloWorldDriver/WpdBaseDriver.cpp b/wpd/WpdHelloWorldDriver/WpdBaseDriver.cpp deleted file mode 100644 index 6d00fc8f..00000000 --- a/wpd/WpdHelloWorldDriver/WpdBaseDriver.cpp +++ /dev/null @@ -1,249 +0,0 @@ -#include "stdafx.h" -#include "WpdBaseDriver.tmh" - -WpdBaseDriver::WpdBaseDriver() : - m_cRef(1) -{ -} - -WpdBaseDriver::~WpdBaseDriver() -{ - -} - -ULONG __stdcall WpdBaseDriver::AddRef() -{ - InterlockedIncrement((long*) &m_cRef); - return m_cRef; -} - -_At_(this, __drv_freesMem(Mem)) -ULONG __stdcall WpdBaseDriver::Release() -{ - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; -} - -HRESULT __stdcall WpdBaseDriver::QueryInterface( - REFIID riid, - void** ppv) -{ - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - return hr; -} - -HRESULT WpdBaseDriver::DispatchWpdMessage(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidCommandCategory = {0}; - DWORD dwCommandID = 0; - PROPERTYKEY CommandKey = WPD_PROPERTY_NULL; - - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, &guidCommandCategory); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_CATEGORY from input parameters"); - } - - if (hr == S_OK) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, &dwCommandID); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_ID from input parameters"); - } - - // If WPD_PROPERTY_COMMON_COMMAND_CATEGORY or WPD_PROPERTY_COMMON_COMMAND_ID could not be extracted - // properly then we should return E_INVALIDARG to the client. - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_CATEGORY or WPD_PROPERTY_COMMON_COMMAND_ID from input parameters"); - } - - if (hr == S_OK) - { - CommandKey.fmtid = guidCommandCategory; - CommandKey.pid = dwCommandID; - - if (CommandKey.fmtid == WPD_CATEGORY_OBJECT_ENUMERATION) - { - hr = m_ObjectEnum.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_OBJECT_PROPERTIES) - { - hr = m_ObjectProperties.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_OBJECT_RESOURCES) - { - hr = m_ObjectResources.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_CAPABILITIES) - { - hr = m_Capabilities.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (IsEqualPropertyKey(CommandKey, WPD_COMMAND_COMMON_GET_OBJECT_IDS_FROM_PERSISTENT_UNIQUE_IDS)) - { - hr = OnGetObjectIDsFromPersistentUniqueIDs(pParams, pResults); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "Unknown command %ws.%d received",CComBSTR(CommandKey.fmtid), CommandKey.pid); - } - } - - HRESULT hrTemp = pResults->SetErrorValue(WPD_PROPERTY_COMMON_HRESULT, hr); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_COMMON_HRESULT")); - - // Set to a success code, to indicate that the message was received. - // the return code for the actual command's results is stored in the - // WPD_PROPERTY_COMMON_HRESULT property. - hr = S_OK; - - return hr; -} - -/** - * This method is called to initialize the driver object. - * This is where the driver would set up it's I/O libraries - * and so on. - */ -HRESULT WpdBaseDriver::Initialize() -{ - return S_OK; -} - -/** - * This method is called to uninitialize the driver object. - * In a real driver, this is where the driver would clean up - * any resources held by this driver. - */ -VOID WpdBaseDriver::Uninitialize() -{ -} - -/** - * This method is called when we receive a WPD_COMMAND_COMMON_GET_OBJECT_IDS_FROM_PERSISTENT_UNIQUE_IDS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS: Contains an IPortableDevicePropVariantCollection of VT_LPWSTR, - * indicating the PersistentUniqueIDs. - * - * The driver should: - * - Iterate through the PersistentUniqueIDs, and convert to a currently valid object id. - * This object ID list should be returned as an IPortableDevicePropVariantCollection of VT_LPWSTR - * in WPD_PROPERTY_COMMON_OBJECT_IDS. - * Order is implicit, i.e. the first element in the Persistent Unique ID list corresponds to the - * to the first element of the ObjectID list and so on. - * - * For those elements where an existing ObjectID could not be found (e.g. the - * object is no longer present on the device), the element will contain the - * empty string (L""). - */ -HRESULT WpdBaseDriver::OnGetObjectIDsFromPersistentUniqueIDs( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - DWORD dwCount = 0; - CComPtr<IPortableDevicePropVariantCollection> pPersistentIDs; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - - if((pParams == NULL) || - (pResults == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Get the list of Persistent IDs - if (hr == S_OK) - { - hr = pParams->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS, &pPersistentIDs); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS"); - } - - // Create the collection to hold the ObjectIDs - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pObjectIDs); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Iterate through the persistent ID list and add the equivalent object ID for each element. - if (hr == S_OK) - { - hr = pPersistentIDs->GetCount(&dwCount); - CHECK_HR(hr, "Failed to get count from persistent ID collection"); - - if (hr == S_OK) - { - DWORD dwIndex = 0; - PROPVARIANT pvPersistentID = {0}; - PROPVARIANT pvObjectID = {0}; - - PropVariantInit(&pvPersistentID); - PropVariantInit(&pvObjectID); - - for(dwIndex = 0; dwIndex < dwCount; dwIndex++) - { - pvObjectID.vt = VT_LPWSTR; - hr = pPersistentIDs->GetAt(dwIndex, &pvPersistentID); - CHECK_HR(hr, "Failed to get persistent ID at index %d", dwIndex); - - // Since our persistent unique identifier are identical to our object - // identifiers, we just return it back to the caller. - if (hr == S_OK) - { - pvObjectID.pwszVal = AtlAllocTaskWideString(pvPersistentID.pwszVal); - } - - if (hr == S_OK) - { - hr = pObjectIDs->Add(&pvObjectID); - CHECK_HR(hr, "Failed to add next Object ID"); - } - - PropVariantClear(&pvPersistentID); - PropVariantClear(&pvObjectID); - - if(FAILED(hr)) - { - break; - } - } - } - } - - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_COMMON_OBJECT_IDS, pObjectIDs); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_COMMON_OBJECT_IDS"); - } - - return hr; -} - diff --git a/wpd/WpdHelloWorldDriver/WpdBaseDriver.h b/wpd/WpdHelloWorldDriver/WpdBaseDriver.h deleted file mode 100644 index 2cfe4ad1..00000000 --- a/wpd/WpdHelloWorldDriver/WpdBaseDriver.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -class WpdBaseDriver : - public IUnknown -{ -public: - WpdBaseDriver(); - virtual ~WpdBaseDriver(); - - HRESULT Initialize(); - VOID Uninitialize(); - - HRESULT DispatchWpdMessage(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - HRESULT OnGetObjectIDsFromPersistentUniqueIDs(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -public: // IUnknown - ULONG __stdcall AddRef(); - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release(); - - HRESULT __stdcall QueryInterface(REFIID riid, void** ppv); - -public: - WpdObjectEnumerator m_ObjectEnum; - WpdObjectProperties m_ObjectProperties; - WpdObjectResources m_ObjectResources; - WpdCapabilities m_Capabilities; - -private: - ULONG m_cRef; -}; - diff --git a/wpd/WpdHelloWorldDriver/WpdCapabilities.cpp b/wpd/WpdHelloWorldDriver/WpdCapabilities.cpp deleted file mode 100644 index 9dd3faed..00000000 --- a/wpd/WpdHelloWorldDriver/WpdCapabilities.cpp +++ /dev/null @@ -1,906 +0,0 @@ -#include "stdafx.h" -#include "WpdCapabilities.tmh" - -const PROPERTYKEY g_SupportedCommands[] = -{ - // WPD_CATEGORY_OBJECT_ENUMERATION - WPD_COMMAND_OBJECT_ENUMERATION_START_FIND, - WPD_COMMAND_OBJECT_ENUMERATION_FIND_NEXT, - WPD_COMMAND_OBJECT_ENUMERATION_END_FIND, - - // WPD_CATEGORY_OBJECT_PROPERTIES - WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED, - WPD_COMMAND_OBJECT_PROPERTIES_GET, - WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL, - WPD_COMMAND_OBJECT_PROPERTIES_SET, - WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES, - WPD_COMMAND_OBJECT_PROPERTIES_DELETE, - - // WPD_CATEGORY_OBJECT_RESOURCES - WPD_COMMAND_OBJECT_RESOURCES_GET_SUPPORTED, - WPD_COMMAND_OBJECT_RESOURCES_OPEN, - WPD_COMMAND_OBJECT_RESOURCES_READ, - WPD_COMMAND_OBJECT_RESOURCES_CLOSE, - WPD_COMMAND_OBJECT_RESOURCES_GET_ATTRIBUTES, - - // WPD_CATEGORY_CAPABILITIES - WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS, - WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS, - WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES, - WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS, - WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES, - WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS, - WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES, - WPD_COMMAND_CAPABILITIES_GET_FIXED_PROPERTY_ATTRIBUTES, -}; - -const GUID g_SupportedFunctionalCategories[] = -{ - WPD_FUNCTIONAL_CATEGORY_DEVICE, - WPD_FUNCTIONAL_CATEGORY_STORAGE, -}; - -WpdCapabilities::WpdCapabilities() -{ - -} - -WpdCapabilities::~WpdCapabilities() -{ - -} - -HRESULT WpdCapabilities::DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (Command.fmtid != WPD_CATEGORY_CAPABILITIES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS)) - { - hr = OnGetSupportedCommands(pParams, pResults); - CHECK_HR(hr, "Failed to get supported commands"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS)) - { - hr = OnGetCommandOptions(pParams, pResults); - CHECK_HR(hr, "Failed to get command options"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES)) - { - hr = OnGetFunctionalCategories(pParams, pResults); - CHECK_HR(hr, "Failed to get functional categories"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS)) - { - hr = OnGetFunctionalObjects(pParams, pResults); - CHECK_HR(hr, "Failed to get functional objects"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES)) - { - hr = OnGetSupportedContentTypes(pParams, pResults); - CHECK_HR(hr, "Failed to get supported content types"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS)) - { - hr = OnGetSupportedFormats(pParams, pResults); - CHECK_HR(hr, "Failed to get supported formats"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES)) - { - hr = OnGetSupportedFormatProperties(pParams, pResults); - CHECK_HR(hr, "Failed to get supported format properties"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_FIXED_PROPERTY_ATTRIBUTES)) - { - hr = OnGetFixedPropertyAttributes(pParams, pResults); - CHECK_HR(hr, "Failed to get fixed property attributes"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_EVENTS)) - { - hr = OnGetSupportedEvents(pParams, pResults); - CHECK_HR(hr, "Failed to get supported events"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_EVENT_OPTIONS)) - { - hr = OnGetEventOptions(pParams, pResults); - CHECK_HR(hr, "Failed to get event options"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return all commands supported by this driver as an - * IPortableDeviceKeyCollection in WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS. - * This includes custom commands, if any. - * - * Note that certain commands require a "command target" to function correctly. - * (e.g. delete object command) It is understood that not all objects are necessarily - * valid targets (e.g. you cannot delete the device object). - */ -HRESULT WpdCapabilities::OnGetSupportedCommands( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pCommands; - UNREFERENCED_PARAMETER(pParams); - - // CoCreate a collection to store the supported commands. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pCommands); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // Add the supported commands to the collection. - if (hr == S_OK) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedCommands); dwIndex++) - { - hr = pCommands->Add(g_SupportedCommands[dwIndex]); - CHECK_HR(hr, "Failed to add supported command at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS, pCommands); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_COMMAND: a collection of property keys containing a single value, - * which identifies the specific command options are requested to return. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS, containing - * the relevant options. If no options are available for this command, the driver should - * return an IPortableDeviceValues with no elements in it. - */ -HRESULT WpdCapabilities::OnGetCommandOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - PROPERTYKEY Command = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pOptions; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the command whose options have been requested - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_CAPABILITIES_COMMAND, &Command); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_COMMAND"); - } - - // CoCreate a collection to store the command options. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pOptions); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Add command options to the collection - if (hr == S_OK) - { - // If your driver supports command options, then they should be added here - // to the command options collection 'pOptions'. - if (IsEqualPropertyKey(WPD_COMMAND_OBJECT_RESOURCES_READ, Command)) - { - // For better read performance, tell the API not to provide the input buffer parameter - // when issuing a WPD_COMMAND_OBJECT_RESOURCES_READ command. - hr = pOptions->SetBoolValue(WPD_OPTION_OBJECT_RESOURCES_NO_INPUT_BUFFER_ON_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_OPTION_OBJECT_RESOURCES_NO_INPUT_BUFFER_ON_READ"); - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS, pOptions); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_CLSID) in - * WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES, containing - * the supported functional categories for this device. - */ -HRESULT WpdCapabilities::OnGetFunctionalCategories( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDevicePropVariantCollection> pFunctionalCategories; - - UNREFERENCED_PARAMETER(pParams); - - // CoCreate a collection to store the supported functional categories. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFunctionalCategories); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported functional categories to the collection. - if (hr == S_OK) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedFunctionalCategories); dwIndex++) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - // Don't call PropVariantClear, since we did not allocate the memory for these GUIDs - - pv.vt = VT_CLSID; - pv.puuid = (GUID*) &g_SupportedFunctionalCategories[dwIndex]; - - hr = pFunctionalCategories->Add(&pv); - CHECK_HR(hr, "Failed to add supported functional category at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES, pFunctionalCategories); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS - * command. It is sent when the caller is interesting in finding the object IDs for all - * functional objects belonging to the specified functional category. - * Note: the number of functional objects is expected to be very small (less than 8 for the - * whole device). - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY - a GUID value containing the category - * the caller is looking for. If the value is WPD_FUNCTIONAL_CATEGORY_ALL, then the driver - * must return all functional objects, no matter which category they belong to. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_LPWSTR) in - * WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS, containing - * the ids of the functional objects who belong to the specified functional category. - * If there are no objects in the specified category, the driver should return an - * empty collection. - */ -HRESULT WpdCapabilities::OnGetFunctionalObjects( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidFunctionalCategory = GUID_NULL; - CComPtr<IPortableDevicePropVariantCollection> pFunctionalObjects; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the functional category whose functional object identifiers have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY, &guidFunctionalCategory); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY"); - } - - // CoCreate a collection to store the supported functional object identifiers. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFunctionalObjects); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported functional object identifiers for the specified functional - // category to the collection. - if (hr == S_OK) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - // Don't call PropVariantClear, since we did not allocate the memory for these object identifiers - - // Add WPD_DEVICE_OBJECT_ID to the functional object identifiers collection - if (hr == S_OK) - { - if ((guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_DEVICE) || - (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_ALL)) - { - pv.vt = VT_LPWSTR; - pv.pwszVal = WPD_DEVICE_OBJECT_ID; - hr = pFunctionalObjects->Add(&pv); - CHECK_HR(hr, "Failed to add device object ID"); - } - } - - // Add STORAGE_OBJECT_ID to the functional object identifiers collection - if (hr == S_OK) - { - if ((guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_STORAGE) || - (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_ALL)) - { - pv.vt = VT_LPWSTR; - pv.pwszVal = STORAGE_OBJECT_ID; - hr = pFunctionalObjects->Add(&pv); - CHECK_HR(hr, "Failed to add storage object ID"); - } - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS, pFunctionalObjects); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES - * command. This message is sent when the client needs to know the possible content types supported - * by the specified functional category. - * If the driver has multiple functional objects that may support different content types, - * the driver should simply merge them together and report all possible types in one list here. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY - a GUID value containing the functional category - * whose content types the caller is interested in. If the value is WPD_FUNCTIONAL_CATEGORY_ALL, then the driver - * must return a list of all content types supported by the device. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_CLSID) in - * WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES, containing - * the content types supported by the specified functional category. - * If there are no objects in the specified category, the driver should return an - * empty collection. - */ -HRESULT WpdCapabilities::OnGetSupportedContentTypes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidFunctionalCategory = GUID_NULL; - CComPtr<IPortableDevicePropVariantCollection> pContentTypes; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the functional category whose supported content types have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY, &guidFunctionalCategory); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY"); - } - - // CoCreate a collection to store the supported content types. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pContentTypes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported content types for the specified functional - // category to the collection. - if (hr == S_OK) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - // Don't call PropVariantClear, since we did not allocate the memory for these GUIDs - - // Add supported content types for known functional categories - if (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_STORAGE) - { - // Add WPD_CONTENT_TYPE_DOCUMENT to the supported content type collection - pv.vt = VT_CLSID; - pv.puuid = (CLSID*)&WPD_CONTENT_TYPE_DOCUMENT; - hr = pContentTypes->Add(&pv); - CHECK_HR(hr, "Failed to add WPD_CONTENT_TYPE_DOCUMENT"); - - if (hr == S_OK) - { - // Add WPD_CONTENT_TYPE_FOLDER to the supported content type collection - pv.vt = VT_CLSID; - pv.puuid = (CLSID*)&WPD_CONTENT_TYPE_FOLDER; - hr = pContentTypes->Add(&pv); - CHECK_HR(hr, "Failed to add WPD_CONTENT_TYPE_FOLDER"); - } - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES, pContentTypes); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS - * command. This message is sent when the client needs to know the possible formats supported - * by the specified content type (e.g. for image objects, the driver may choose to support JPEG and BMP files). - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_CONTENT_TYPE - a GUID value containing the content type - * whose formats the caller is interested in. If the value is WPD_CONTENT_TYPE_ALL, then the driver - * must return a list of all formats supported by the device. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_CLSID) in - * WPD_PROPERTY_CAPABILITIES_FORMATS, indicating the formats supported by the - * specified content type. - * If there are no formats supported by the specified content type, the driver should return an - * empty collection. - */ -HRESULT WpdCapabilities::OnGetSupportedFormats( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidContentType = GUID_NULL; - CComPtr<IPortableDevicePropVariantCollection> pFormats; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the content type whose supported formats have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_CONTENT_TYPE, &guidContentType); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_CONTENT_TYPE"); - } - - // CoCreate a collection to store the supported formats. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFormats); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported formats for the specified content type to the collection. - if (hr == S_OK) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - // Don't call PropVariantClear, since we did not allocate the memory for these GUIDs - - if ((guidContentType == WPD_CONTENT_TYPE_DOCUMENT) || - ((guidContentType == WPD_CONTENT_TYPE_ALL))) - { - // Add WPD_OBJECT_FORMAT_TEXT to the supported formats collection - pv.vt = VT_CLSID; - pv.puuid = (CLSID*)&WPD_OBJECT_FORMAT_TEXT; - hr = pFormats->Add(&pv); - CHECK_HR(hr, "Failed to add WPD_OBJECT_FORMAT_TEXT"); - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_FORMATS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_FORMATS, pFormats); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_FORMATS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES - * command. This message is sent when the client needs to know the typical properties for objects of - * a given format. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FORMAT - a GUID value specifying the format the caller is interested in. - * - * The driver should: - * - Return an IPortableDeviceKeyCollection in WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS, - * containing the property keys. - */ -HRESULT WpdCapabilities::OnGetSupportedFormatProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidObjectFormat = GUID_NULL; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object format whose supported properties have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FORMAT, &guidObjectFormat); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FORMAT"); - } - - // CoCreate a collection to store the supported properties. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // Add the supported properties for the specified object format to the collection. - if (hr == S_OK) - { - hr = AddSupportedPropertyKeys(guidObjectFormat, pKeys); - CHECK_HR(hr, "Failed to get supported properties for a format"); - } - - // Set the WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS, pKeys); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_FIXED_PROPERTY_ATTRIBUTES - * command. This message is sent when the client needs to know the property attributes that - * are the same for all objects of the given format. - * - * Typically, a driver treats objects of a given format the same. Many properties therefore will - * have attributes that are identical across all objects of that format. - * These can be returned here. There are some attributes which may be differ per object instance, - * which are not returned here. - * See WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FORMAT - a GUID value specifying the format the caller is interested in. - * - WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS - a collection of property keys containing a single value, - * which is the key identifying the specific property attributes we are requested to return. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES - * containing the fixed property attributes. - */ -HRESULT WpdCapabilities::OnGetFixedPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidObjectFormat = GUID_NULL; - PROPERTYKEY key = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pAttributes; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object format whose fixed property attributes have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FORMAT, &guidObjectFormat); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FORMAT"); - } - - // Get the property whose fixed property attributes have been requested - if(hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS, &key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS"); - } - - // CoCreate a collection to store the fixed property attributes. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Add the fixed property attributes for the specified object format and property - if (hr == S_OK) - { - hr = GetFixedPropertyAttributesForFormat(guidObjectFormat, key, pAttributes); - CHECK_HR(hr, "Failed to get fixed property attributes"); - } - - // Set the WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES, pAttributes); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_EVENTS - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return all events supported by this driver should be returned as an - * IPortableDeviceKeyCollection in WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS. - * That includes custom commands, if any. - */ -HRESULT WpdCapabilities::OnGetSupportedEvents( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDevicePropVariantCollection> pEvents; - UNREFERENCED_PARAMETER(pParams); - - // CoCreate a collection to store the supported events. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pEvents); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported events to the collection. - if (hr == S_OK) - { - // If your driver supports events, then they should be added here - // to the supported events collection 'pEvents'. - } - - // Set the WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS, pEvents); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_EVENT_OPTIONS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_EVENT: a GUID value indicating the Event whose options should be returned. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS, containing - * the relevant options. - */ -HRESULT WpdCapabilities::OnGetEventOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID Event = GUID_NULL; - CComPtr<IPortableDeviceValues> pOptions; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the event whose options have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_EVENT, &Event); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_EVENT"); - } - - // CoCreate a collection to store the event options. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pOptions); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Add event options to the collection - if (hr == S_OK) - { - // If your driver supports event options, then they should be added here - // to the event options collection 'pOptions'. - } - - // Set the WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS, pOptions); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS"); - } - - return hr; -} - -/** - * This method is called to populate supported PROPERTYKEYs for the - * specified object format. - * - * The parameters sent to us are: - * guidObjectFormat - object format whose supported properties are being requested. - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add supported PROPERTYKEYs pertaining to the specified object format. - */ -HRESULT WpdCapabilities::AddSupportedPropertyKeys( - _In_ REFGUID guidObjectFormat, - _In_ IPortableDeviceKeyCollection* pKeys) -{ - HRESULT hr = S_OK; - - if (pKeys == NULL) - { - hr = E_INVALIDARG; - return hr; - } - - if (guidObjectFormat == WPD_OBJECT_FORMAT_TEXT) - { - AddCommonPropertyKeys(pKeys); - AddFilePropertyKeys(pKeys); - } - else if (guidObjectFormat == WPD_OBJECT_FORMAT_ALL) - { - AddCommonPropertyKeys(pKeys); - } - - return hr; -} - -/** - * This method is called to populate fixed property attributes - * - * The parameters sent to us are: - * guidObjectFormat - the object format whose property attributes are being requested. - * Key - the property whose attributes are being requested - * pAttributes - an IPortableDeviceValues which will contain the resulting property attributes - * - * The driver should: - * Read the property attributes for the specified property for the specified object format and - * populate pAttributes with the results. - */ -HRESULT WpdCapabilities::GetFixedPropertyAttributesForFormat( - _In_ REFGUID guidObjectFormat, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if (pAttributes == NULL) - { - hr = E_INVALIDARG; - return hr; - } - - UNREFERENCED_PARAMETER(guidObjectFormat); - UNREFERENCED_PARAMETER(Key); - - // - // Since ALL of our properties have the same attributes, we are ignoring the - // passed in guidObjectFormat and Key parameters. These parameters allow you to - // customize fixed property attributes for properties for specific formats. - // - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_DELETE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_READ"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_WRITE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_WRITE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_FORM, WPD_PROPERTY_ATTRIBUTE_FORM_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FORM"); - } - - return hr; -} - diff --git a/wpd/WpdHelloWorldDriver/WpdCapabilities.h b/wpd/WpdHelloWorldDriver/WpdCapabilities.h deleted file mode 100644 index ef2902ef..00000000 --- a/wpd/WpdHelloWorldDriver/WpdCapabilities.h +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once - -class WpdCapabilities -{ -public: - WpdCapabilities(); - virtual ~WpdCapabilities(); - - HRESULT Initialize(); - - HRESULT DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedCommands( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetCommandOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFunctionalCategories( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFunctionalObjects( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedContentTypes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedFormats( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedFormatProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFixedPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedEvents( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetEventOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - HRESULT AddSupportedPropertyKeys(_In_ REFGUID guidObjectFormat, - _In_ IPortableDeviceKeyCollection* pKeys); - - HRESULT GetFixedPropertyAttributesForFormat(_In_ REFGUID guidObjectFormat, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes); -}; - diff --git a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.cpp b/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.cpp deleted file mode 100644 index 71a8830c..00000000 --- a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "stdafx.h" -#include "resource.h" -#include "WpdHelloWorldDriver.h" - -#include "WpdHelloWorldDriver.tmh" - -HINSTANCE g_hInstance = NULL; - -class CWpdHelloWorldDriverModule : public CAtlDllModuleT< CWpdHelloWorldDriverModule > -{ -public : - DECLARE_REGISTRY_APPID_RESOURCEID(IDR_WpdHelloWorldDriver, "{021AD204-6411-4698-8CFB-C1A72B581733}") - DECLARE_LIBID(LIBID_WpdHelloWorldDriverLib) -}; - -CWpdHelloWorldDriverModule _AtlModule; - -// DLL Entry Point -extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) -{ - if(dwReason == DLL_PROCESS_ATTACH) - { - g_hInstance = hInstance; - - // Initialize tracing. - WPP_INIT_TRACING(MYDRIVER_TRACING_ID); - } - else if (dwReason == DLL_PROCESS_DETACH) - { - // Cleanup tracing. - WPP_CLEANUP(); - } - - return _AtlModule.DllMain(dwReason, lpReserved); -} - -// Used to determine whether the DLL can be unloaded by OLE -STDAPI DllCanUnloadNow(void) -{ - return _AtlModule.DllCanUnloadNow(); -} - -// Returns a class factory to create an object of the requested type -STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID* ppv) -{ - return _AtlModule.DllGetClassObject(rclsid, riid, ppv); -} - -// DllRegisterServer - Adds entries to the system registry -STDAPI DllRegisterServer(void) -{ - // registers object, typelib and all interfaces in typelib - HRESULT hr = _AtlModule.DllRegisterServer(); - return hr; -} - -// DllUnregisterServer - Removes entries from the system registry -STDAPI DllUnregisterServer(void) -{ - HRESULT hr = _AtlModule.DllUnregisterServer(); - return hr; -} diff --git a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.def b/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.def deleted file mode 100644 index efcd3224..00000000 --- a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.def +++ /dev/null @@ -1,9 +0,0 @@ -; WpdHelloWorldDriver.def : Declares the module parameters. - -LIBRARY "WpdHelloWorldDriver.DLL" - -EXPORTS - DllCanUnloadNow PRIVATE - DllGetClassObject PRIVATE - DllRegisterServer PRIVATE - DllUnregisterServer PRIVATE diff --git a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.idl b/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.idl deleted file mode 100644 index 663b99a8..00000000 --- a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.idl +++ /dev/null @@ -1,24 +0,0 @@ - -import "oaidl.idl"; -import "ocidl.idl"; - -import "wudfddi.idl"; - -[ - uuid(69A9B934-73F0-45AF-B3C5-1D5BC7BC982B), - version(1.0), - helpstring("Windows Portable Device Hello World Sample Driver Type Library") -] -library WpdHelloWorldDriverLib -{ - importlib("stdole2.tlb"); - [ - uuid(EC7445EE-BC00-4CED-AFE7-A52849F10239), - helpstring("WpdHelloWorldDriver Class") - ] - coclass WpdHelloWorldDriver - { - [default] interface IDriverEntry; - }; -}; - diff --git a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.inx b/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.inx deleted file mode 100644 index f79d7810..00000000 --- a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.inx +++ /dev/null @@ -1,83 +0,0 @@ -; -; WpdHelloWorldDriver.inf -; - -[Version] -Signature="$Windows NT$" -Class=WPD -ClassGuid={EEC5AD98-8080-425f-922A-DABF3DE3F69A} -Provider=%Provider% -CatalogFile=WpdHelloWorldDriver.cat -DriverVer=01/24/2005,1.1.1.1 - -[Manufacturer] -%Mfg%=Standard,NT$ARCH$ - -[Standard.NT$ARCH$] -%BasicDeviceName%=Basic_Install,WUDF\WpdHelloWorld - -[SourceDisksFiles] -WudfUpdate_$UMDFCOINSTALLERVERSION$.dll=1 -WpdHelloWorldDriver.dll=1 - -[SourceDisksNames] -1 = %MediaDescription% - -; =================== WPD Sample Device ================================== - -[Basic_Install] -CopyFiles=System32Copy - -[Basic_Install.hw] -AddReg=Device_AddReg - -[Basic_Install.Services] -AddService=WUDFRd,0x000001fa,WUDFRD_ServiceInstall - -[Basic_Install.CoInstallers] -AddReg=Basic_Install.CoInstallers_AddReg -CopyFiles = CoInstallers_CopyFiles - -[Basic_Install.CoInstallers_AddReg] -HKR,,CoInstallers32,0x00010000,"WudfUpdate_$UMDFCOINSTALLERVERSION$.dll" - -[Basic_Install.Wdf] -UmdfService=WpdHelloWorldDriver, WpdHelloWorldDriver_Install -UmdfServiceOrder=WpdHelloWorldDriver - -[CoInstallers_CopyFiles] -WudfUpdate_$UMDFCOINSTALLERVERSION$.dll - -[WpdHelloWorldDriver_Install] -UmdfLibraryVersion=$UMDFVERSION$ -DriverCLSID="{EC7445EE-BC00-4CED-AFE7-A52849F10239}" -ServiceBinary=%12%\UMDF\WpdHelloWorldDriver.dll - -[Device_AddReg] -; Enable WIA support for legacy WIA applications -HKR,,"EnableLegacySupport",0x10001,1 - -; Enable default AutoPlay support -HKR,,"EnableDefaultAutoPlaySupport",0x10001,1 - -[WUDFRD_ServiceInstall] -ServiceType=1 -StartType=3 -ErrorControl=1 -ServiceBinary=%12%\WUDFRd.sys - -[DestinationDirs] -System32Copy=12,UMDF ; copy to system32\drivers\umdf -CoInstallers_CopyFiles= 11 - -[System32Copy] -WpdHelloWorldDriver.dll - - -; =================== Generic ================================== - -[Strings] -Provider="TODO-Set-Provider" -Mfg="Windows Portable Devices" -MediaDescription="Windows Portable Device Hello World Sample Driver Installation Media" -BasicDeviceName="Windows Portable Device Hello World Sample Driver" diff --git a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.rc b/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.rc deleted file mode 100644 index 782e4316..00000000 --- a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.rc +++ /dev/null @@ -1,15 +0,0 @@ -#include "resource.h" -#include <windows.h> -#include <ntverp.h> - -#define VER_FILETYPE VFT_DLL -#define VER_FILESUBTYPE VFT2_UNKNOWN -#define VER_FILEDESCRIPTION_STR "Windows Portable Device Hello World Sample Driver" -#define VER_INTERNALNAME_STR "WpdHelloWorldDriver.dll" - -#include <common.ver> - -1 TYPELIB "WpdHelloWorldDriver.tlb" - -IDR_WpdHelloWorldDriver REGISTRY "WpdHelloWorldDriver.rgs" - diff --git a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.rgs b/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.rgs deleted file mode 100644 index 76c52153..00000000 --- a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.rgs +++ /dev/null @@ -1,26 +0,0 @@ -HKCR -{ - WpdHelloWorldDriver.WpdHelloWorldDriver.1 = s 'WpdHelloWorldDriver Class' - { - CLSID = s '{EC7445EE-BC00-4CED-AFE7-A52849F10239}' - } - WpdHelloWorldDriver.WpdHelloWorldDriver = s 'WpdHelloWorldDriver Class' - { - CLSID = s '{EC7445EE-BC00-4CED-AFE7-A52849F10239}' - CurVer = s 'WpdHelloWorldDriver.WpdHelloWorldDriver.1' - } - NoRemove CLSID - { - ForceRemove {EC7445EE-BC00-4CED-AFE7-A52849F10239} = s 'WpdHelloWorldDriver Class' - { - ProgID = s 'WpdHelloWorldDriver.WpdHelloWorldDriver.1' - VersionIndependentProgID = s 'WpdHelloWorldDriver.WpdHelloWorldDriver.1' - InprocServer32 = s '%MODULE%' - { - val ThreadingModel = s 'Free' - } - 'TypeLib' = s '{69A9B934-73F0-45AF-B3C5-1D5BC7BC982B}' - } - } -} - diff --git a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.sln b/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.sln deleted file mode 100644 index 5122ac08..00000000 --- a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.sln +++ /dev/null @@ -1,28 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0 -MinimumVisualStudioVersion = 12.0 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WpdHelloWorldDriver", "WpdHelloWorldDriver.vcxproj", "{2E055339-8E93-4083-B3EC-54D452A23264}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - Debug|x64 = Debug|x64 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2E055339-8E93-4083-B3EC-54D452A23264}.Debug|Win32.ActiveCfg = Debug|Win32 - {2E055339-8E93-4083-B3EC-54D452A23264}.Debug|Win32.Build.0 = Debug|Win32 - {2E055339-8E93-4083-B3EC-54D452A23264}.Release|Win32.ActiveCfg = Release|Win32 - {2E055339-8E93-4083-B3EC-54D452A23264}.Release|Win32.Build.0 = Release|Win32 - {2E055339-8E93-4083-B3EC-54D452A23264}.Debug|x64.ActiveCfg = Debug|x64 - {2E055339-8E93-4083-B3EC-54D452A23264}.Debug|x64.Build.0 = Debug|x64 - {2E055339-8E93-4083-B3EC-54D452A23264}.Release|x64.ActiveCfg = Release|x64 - {2E055339-8E93-4083-B3EC-54D452A23264}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.vcxproj b/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.vcxproj deleted file mode 100644 index f1b1acf4..00000000 --- a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.vcxproj +++ /dev/null @@ -1,355 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup Label="ProjectConfigurations"> - <ProjectConfiguration Include="Debug|Win32"> - <Configuration>Debug</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|Win32"> - <Configuration>Release</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Debug|x64"> - <Configuration>Debug</Configuration> - <Platform>x64</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|x64"> - <Configuration>Release</Configuration> - <Platform>x64</Platform> - </ProjectConfiguration> - </ItemGroup> - <PropertyGroup Label="Globals"> - <ProjectGuid>{2E055339-8E93-4083-B3EC-54D452A23264}</ProjectGuid> - <RootNamespace>$(MSBuildProjectName)</RootNamespace> - <UMDF_VERSION_MAJOR>1</UMDF_VERSION_MAJOR> - <KMDF_VERSION_MAJOR>1</KMDF_VERSION_MAJOR> - <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration> - <Platform Condition="'$(Platform)' == ''">Win32</Platform> - <SampleGuid>{1A94F496-32AD-4A33-B0C0-84612D54FF44}</SampleGuid> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>False</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>True</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>False</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>True</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> - <PropertyGroup> - <OutDir>$(IntDir)</OutDir> - </PropertyGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ItemGroup Label="WrappedTaskItems"> - <ClCompile Include="WpdHelloWorldDriver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Driver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Device.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Queue.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdBaseDriver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectEnum.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectProperties.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectResources.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdCapabilities.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <Inf Include="WpdHelloWorldDriver.inx"> - <Architecture>$(InfArch)</Architecture> - <SpecifyArchitecture>true</SpecifyArchitecture> - <CopyOutput>.\$(IntDir)\WpdHelloWorldDriver.inf</CopyOutput> - </Inf> - <OtherWpp Include="WpdHelloWorldDriver.rc; WpdHelloWorldDriver.idl"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - </OtherWpp> - </ItemGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <TargetName>WpdHelloWorldDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <TargetName>WpdHelloWorldDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <TargetName>WpdHelloWorldDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <TargetName>WpdHelloWorldDriver</TargetName> - </PropertyGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Link> - <ModuleDefinitionFile>WpdHelloWorldDriver.def</ModuleDefinitionFile> - </Link> - <ClCompile> - <ExceptionHandling> - </ExceptionHandling> - </ClCompile> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Link> - <ModuleDefinitionFile>WpdHelloWorldDriver.def</ModuleDefinitionFile> - </Link> - <ClCompile> - <ExceptionHandling> - </ExceptionHandling> - </ClCompile> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Link> - <ModuleDefinitionFile>WpdHelloWorldDriver.def</ModuleDefinitionFile> - </Link> - <ClCompile> - <ExceptionHandling> - </ExceptionHandling> - </ClCompile> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Link> - <ModuleDefinitionFile>WpdHelloWorldDriver.def</ModuleDefinitionFile> - </Link> - <ClCompile> - <ExceptionHandling> - </ExceptionHandling> - </ClCompile> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemGroup> - <ClCompile Include="Stdafxsrc.cpp"> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Create</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <Midl Include="WpdHelloWorldDriver.idl" /> - <ResourceCompile Include="WpdHelloWorldDriver.rc" /> - </ItemGroup> - <ItemGroup> - <Inf Exclude="@(Inf)" Include="*.inf" /> - <FilesToPackage Include="$(TargetPath)" Condition="'$(ConfigurationType)'=='Driver' or '$(ConfigurationType)'=='DynamicLibrary'" /> - </ItemGroup> - <ItemGroup> - <None Exclude="@(None)" Include="*.txt;*.htm;*.html" /> - <None Exclude="@(None)" Include="*.ico;*.cur;*.bmp;*.dlg;*.rct;*.gif;*.jpg;*.jpeg;*.wav;*.jpe;*.tiff;*.tif;*.png;*.rc2" /> - <None Exclude="@(None)" Include="*.def;*.bat;*.hpj;*.asmx" /> - </ItemGroup> - <ItemGroup> - <ClInclude Exclude="@(ClInclude)" Include="*.h;*.hpp;*.hxx;*.hm;*.inl;*.xsd" /> - </ItemGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> -</Project>
\ No newline at end of file diff --git a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.vcxproj.Filters b/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.vcxproj.Filters deleted file mode 100644 index 28e35f3a..00000000 --- a/wpd/WpdHelloWorldDriver/WpdHelloWorldDriver.vcxproj.Filters +++ /dev/null @@ -1,74 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup> - <Filter Include="Source Files"> - <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;*</Extensions> - <UniqueIdentifier>{6AE4DF50-A6FB-49DE-AD18-864D7BB2A242}</UniqueIdentifier> - </Filter> - <Filter Include="Header Files"> - <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> - <UniqueIdentifier>{691F3E46-F252-48EE-B388-82D467B05AD5}</UniqueIdentifier> - </Filter> - <Filter Include="Resource Files"> - <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml</Extensions> - <UniqueIdentifier>{B225BE81-47D2-4027-A2E3-3CF3879E8D01}</UniqueIdentifier> - </Filter> - <Filter Include="Driver Files"> - <Extensions>inf;inv;inx;mof;mc;</Extensions> - <UniqueIdentifier>{4B9391AA-ED51-4F32-B1A8-F547EC157EA2}</UniqueIdentifier> - </Filter> - </ItemGroup> - <ItemGroup> - <ClCompile Include="Device.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Driver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Queue.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Stdafxsrc.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdBaseDriver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdCapabilities.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdHelloWorldDriver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectEnum.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectProperties.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectResources.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <Midl Include="WpdHelloWorldDriver.idl"> - <Filter>Source Files</Filter> - </Midl> - <None Include="WpdHelloWorldDriver.def"> - <Filter>Source Files</Filter> - </None> - </ItemGroup> - <ItemGroup> - <Inf Include="WpdHelloWorldDriver.inx"> - <Filter>Driver Files</Filter> - </Inf> - </ItemGroup> - <ItemGroup> - <ResourceCompile Include="WpdHelloWorldDriver.rc"> - <Filter>Resource Files</Filter> - </ResourceCompile> - </ItemGroup> - <ItemGroup> - <ClInclude Include="WpdObjectResources.h"> - <Filter>Header Files</Filter> - </ClInclude> - </ItemGroup> -</Project>
\ No newline at end of file diff --git a/wpd/WpdHelloWorldDriver/WpdObjectEnum.cpp b/wpd/WpdHelloWorldDriver/WpdObjectEnum.cpp deleted file mode 100644 index 450aa42a..00000000 --- a/wpd/WpdHelloWorldDriver/WpdObjectEnum.cpp +++ /dev/null @@ -1,418 +0,0 @@ -#include "stdafx.h" -#include "WpdObjectEnum.tmh" - -WpdObjectEnumerator::WpdObjectEnumerator() -{ - -} - -WpdObjectEnumerator::~WpdObjectEnumerator() -{ - -} - -HRESULT WpdObjectEnumerator::DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (Command.fmtid != WPD_CATEGORY_OBJECT_ENUMERATION) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - - if (hr == S_OK) - { - if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_START_FIND.pid) - { - hr = OnStartFind(pParams, pResults); - CHECK_HR(hr, "Failed to begin enumeration"); - } - else if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_FIND_NEXT.pid) - { - hr = OnFindNext(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to find next object"); - } - } - else if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_END_FIND.pid) - { - hr = OnEndFind(pParams, pResults); - CHECK_HR(hr, "Failed to end enumeration"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_ENUMERATION_START_FIND - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID: the parent where we should start - * the enumeration. - * - WPD_PROPERTY_OBJECT_ENUMERATION_FILTER: the filter to use when doing - * enumeration. Since this parameter is optional, it may not exist. - * This driver currently ignores the filter parameter. - * - * The driver should: - * - Create a new context for this enumeration. - * - Set the string identifier in WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT for the newly created enumeration context. - * This value will be passed back during OnFindNext and OnEndFind. - */ -HRESULT WpdObjectEnumerator::OnStartFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszParentID = NULL; - ContextMap* pContextMap = NULL; - CAtlStringW strEnumContext; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier of the parent where the enumeration is starting from. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID, &wszParentID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID"); - } - - // Get the client context map so we can store an enumeration context for this enumeration - // operation. - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Create and initialize a new enumeration context. - // Add the new enumertion context to the client context map. This context is used to - // keep track of this particular enumeration operation. - if (hr == S_OK) - { - WpdObjectEnumeratorContext* pEnumeratorContext = new WpdObjectEnumeratorContext(); - if (pEnumeratorContext != NULL) - { - // Initialize the enumeration context - InitializeEnumerationContext(pEnumeratorContext, wszParentID); - - // Add the enumeration context to the client context map. - pContextMap->Add(pEnumeratorContext, strEnumContext); - - // Release the enumerator context because it has been AddRef'ed during Add() - SAFE_RELEASE(pEnumeratorContext); - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate enumeration context"); - } - } - - // Set the WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT value in the results. - // This context identifier will be passed back during OnFindNext and OnEndFind to allow the driver to access it. - if (hr == S_OK) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, strEnumContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszParentID); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -HRESULT WpdObjectEnumerator::OnFindNext(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszEnumContext = NULL; - DWORD dwNumObjectsRequested = 0; - ContextMap* pContextMap = NULL; - WpdObjectEnumeratorContext* pEnumeratorContext = NULL; - DWORD NumObjectsEnumerated = 0; - - CComPtr<IPortableDevicePropVariantCollection> pObjectIDCollection; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the enumeration context identifier for this enumeration operation. - // The enumeration context identifier is needed to lookup the specific - // enumeration context in the client context map for this enumeration operation. - // NOTE that more than one enumeration may be in progress. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, &wszEnumContext); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - // Get the number of objects requested for this enumeration call. - // The driver should always attempt to meet this requested value. - // If there are fewer children than requested, the driver should return the remaining - // children and a return code of S_FALSE. - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_ENUMERATION_NUM_OBJECTS_REQUESTED, &dwNumObjectsRequested); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_NUM_OBJECTS_REQUESTED"); - } - - // Get the client context map so we can retrieve the enumeration context for this enumeration - // operation. - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (hr == S_OK) - { - pEnumeratorContext = (WpdObjectEnumeratorContext*)pContextMap->GetContext(wszEnumContext); - if (pEnumeratorContext == NULL) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing enumeration context"); - } - } - - // CoCreate a collection to store the object identifiers being returned for this enumeration call. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pObjectIDCollection); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // If the enumeration context reports that their are more objects to return, then continue, if not, - // return an empty results set. - if ((hr == S_OK) && (pEnumeratorContext != NULL) && pEnumeratorContext->HasMoreChildrenToEnumerate()) - { - if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(L"") == 0) - { - // We are being asked for the WPD_DEVICE_OBJECT_ID - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to add 'DEVICE' object ID to enumeration collection"); - - // Update the the number of children we are returning for this enumeration call - NumObjectsEnumerated++; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(WPD_DEVICE_OBJECT_ID) == 0) - { - // We are being asked for direct children of the WPD_DEVICE_OBJECT_ID - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, STORAGE_OBJECT_ID); - CHECK_HR(hr, "Failed to add storage object ID to enumeration collection"); - - // Update the the number of children we are returning for this enumeration call - NumObjectsEnumerated++; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(STORAGE_OBJECT_ID) == 0) - { - // We are being asked for direct children of the STORAGE_OBJECT_ID - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, DOCUMENTS_FOLDER_OBJECT_ID); - CHECK_HR(hr, "Failed to add documents folder object ID to enumeration collection"); - - // Update the the number of children we are returning for this enumeration call - NumObjectsEnumerated++; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(DOCUMENTS_FOLDER_OBJECT_ID) == 0) - { - // We are being asked for direct children of the DOCUMENTS_FOLDER_OBJECT_ID - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, README_FILE_OBJECT_ID); - CHECK_HR(hr, "Failed to add documents readme text file object ID to enumeration collection"); - - // Update the the number of children we are returning for this enumeration call - NumObjectsEnumerated++; - } - } - - // Set the collection of object identifiers enumerated in the results - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_ENUMERATION_OBJECT_IDS, pObjectIDCollection); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_ENUMERATION_OBJECT_IDS"); - } - - // If the enumeration context reports that their are no more objects to return then return S_FALSE indicating to the - // caller that we are finished. - if (hr == S_OK) - { - if (pEnumeratorContext != NULL) - { - // Update the number of children we have enumerated and returned to the caller - pEnumeratorContext->m_ChildrenEnumerated += NumObjectsEnumerated; - - // Check the number requested against the number enumerated and set the HRESULT - // accordingly. - if (NumObjectsEnumerated < dwNumObjectsRequested) - { - // We returned less than the number of objects requested to the caller - hr = S_FALSE; - } - else - { - // We returned exactly the number of objects requested to the caller - hr = S_OK; - } - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszEnumContext); - - SAFE_RELEASE(pContextMap); - SAFE_RELEASE(pEnumeratorContext); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_ENUMERATION_END_FIND - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT: the context the driver returned to - * the client in OnStartFind. - * - * The driver should: - * - Destroy any data associated with this context. - */ -HRESULT WpdObjectEnumerator::OnEndFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszEnumContext = NULL; - ContextMap* pContextMap = NULL; - - UNREFERENCED_PARAMETER(pResults); - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the enumeration context identifier for this enumeration operation. We will - // need this to lookup the specific enumeration context in the client context map. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, &wszEnumContext); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - // Get the client context map so we can retrieve the enumeration context for this enumeration - // operation using the WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT property value obtained above. - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Destroy any data allocated/associated with the enumeration context and then remove it from the context map. - // We no longer need to keep this context around because the enumeration has been ended. - if (hr == S_OK) - { - pContextMap->Remove(wszEnumContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszEnumContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -// Initialize the enumeration context -VOID WpdObjectEnumerator::InitializeEnumerationContext( - _In_ WpdObjectEnumeratorContext* pEnumeratorContext, - _In_ LPCWSTR wszParentObjectID) -{ - if (pEnumeratorContext == NULL) - { - return; - } - - // Initialize the enumeration context with the parent object identifier - pEnumeratorContext->m_strParentObjectID = wszParentObjectID; - - // Our sample driver has a very simple object structure where we know - // how many children are under each parent. - // The eumeration context is initialized below with this information. - if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(L"") == 0) - { - // Clients passing an 'empty' string for the parent are asking for the - // 'DEVICE' object. We should return 1 child in this case. - pEnumeratorContext->m_TotalChildren = 1; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(WPD_DEVICE_OBJECT_ID) == 0) - { - // The device object contains 1 child (the storage object). - pEnumeratorContext->m_TotalChildren = 1; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(STORAGE_OBJECT_ID) == 0) - { - // The storage object contains 1 child (the documents folder object). - pEnumeratorContext->m_TotalChildren = 1; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(DOCUMENTS_FOLDER_OBJECT_ID) == 0) - { - // The documents folder object contains 1 child (the readme text file object). - pEnumeratorContext->m_TotalChildren = 1; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(README_FILE_OBJECT_ID) == 0) - { - // The readme text file object contains no children. - pEnumeratorContext->m_TotalChildren = 0; - } - else - { - // Invalid, or non-existing objects contain no children. - pEnumeratorContext->m_TotalChildren = 0; - } -} - -HRESULT WpdObjectEnumerator::AddStringValueToPropVariantCollection( - _In_ IPortableDevicePropVariantCollection* pCollection, - _In_ LPCWSTR wszValue) -{ - HRESULT hr = S_OK; - - if ((pCollection == NULL) || - (wszValue == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - - pv.vt = VT_LPWSTR; - pv.pwszVal = (LPWSTR)wszValue; - - // The wszValue will be copied into the collection, keeping the ownership - // of the string belonging to the caller. - // Don't call PropVariantClear, since we did not allocate the memory for these string values - - hr = pCollection->Add(&pv); - - return hr; -} - diff --git a/wpd/WpdHelloWorldDriver/WpdObjectEnum.h b/wpd/WpdHelloWorldDriver/WpdObjectEnum.h deleted file mode 100644 index 8d38526b..00000000 --- a/wpd/WpdHelloWorldDriver/WpdObjectEnum.h +++ /dev/null @@ -1,103 +0,0 @@ -#pragma once - -// This class is used to store the context for a specific enumeration. -class WpdObjectEnumeratorContext : public IUnknown -{ -public: - WpdObjectEnumeratorContext() : - m_cRef(1), - m_TotalChildren(0), - m_ChildrenEnumerated(0) - { - - } - - ~WpdObjectEnumeratorContext() - { - - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -private: - DWORD m_cRef; - -public: - bool HasMoreChildrenToEnumerate() - { - return ((m_TotalChildren - m_ChildrenEnumerated) > 0); - } - -// WpdObjectEnumeratorContext specific data -public: - CAtlStringW m_strParentObjectID; // object identifier of the object whose children are being enumerated - DWORD m_TotalChildren; // number of bytes transferred from the resource to the caller - DWORD m_ChildrenEnumerated; // number of children returned during the enumeration operation -}; - -class WpdObjectEnumerator -{ -public: - WpdObjectEnumerator(); - virtual ~WpdObjectEnumerator(); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnStartFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnFindNext(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnEndFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - VOID InitializeEnumerationContext( - _In_ WpdObjectEnumeratorContext* pEnumeratorContext, - _In_ LPCWSTR wszParentObjectID); - - HRESULT AddStringValueToPropVariantCollection( - _In_ IPortableDevicePropVariantCollection* pCollection, - _In_ LPCWSTR wszValue); -}; diff --git a/wpd/WpdHelloWorldDriver/WpdObjectProperties.cpp b/wpd/WpdHelloWorldDriver/WpdObjectProperties.cpp deleted file mode 100644 index 79dc00b4..00000000 --- a/wpd/WpdHelloWorldDriver/WpdObjectProperties.cpp +++ /dev/null @@ -1,1421 +0,0 @@ -#include "stdafx.h" -#include "WpdObjectProperties.tmh" - -const PROPERTYKEY g_SupportedCommonProperties[] = -{ - WPD_OBJECT_ID, - WPD_OBJECT_PERSISTENT_UNIQUE_ID, - WPD_OBJECT_PARENT_ID, - WPD_OBJECT_NAME, - WPD_OBJECT_FORMAT, - WPD_OBJECT_CONTENT_TYPE, - WPD_OBJECT_CAN_DELETE, -}; - -const PROPERTYKEY g_SupportedDeviceProperties[] = -{ - WPD_DEVICE_FIRMWARE_VERSION, - WPD_DEVICE_POWER_LEVEL, - WPD_DEVICE_POWER_SOURCE, - WPD_DEVICE_PROTOCOL, - WPD_DEVICE_MODEL, - WPD_DEVICE_SERIAL_NUMBER, - WPD_DEVICE_SUPPORTS_NON_CONSUMABLE, - WPD_DEVICE_MANUFACTURER, - WPD_DEVICE_FRIENDLY_NAME, - WPD_DEVICE_TYPE, - WPD_FUNCTIONAL_OBJECT_CATEGORY, -}; - -const PROPERTYKEY g_SupportedStorageProperties[] = -{ - WPD_STORAGE_TYPE, - WPD_STORAGE_FILE_SYSTEM_TYPE, - WPD_STORAGE_CAPACITY, - WPD_STORAGE_FREE_SPACE_IN_BYTES, - WPD_STORAGE_SERIAL_NUMBER, - WPD_STORAGE_DESCRIPTION, - WPD_FUNCTIONAL_OBJECT_CATEGORY, -}; - -const PROPERTYKEY g_SupportedCommonFileProperties[] = -{ - WPD_OBJECT_ORIGINAL_FILE_NAME, - WPD_OBJECT_SIZE, - WPD_OBJECT_DATE_MODIFIED, - WPD_OBJECT_DATE_CREATED, -}; - -const PROPERTYKEY g_SupportedCommonFolderProperties[] = -{ - WPD_OBJECT_ORIGINAL_FILE_NAME, - WPD_OBJECT_DATE_MODIFIED, - WPD_OBJECT_DATE_CREATED, -}; - -WpdObjectProperties::WpdObjectProperties() -{ - -} - -WpdObjectProperties::~WpdObjectProperties() -{ - -} - -HRESULT WpdObjectProperties::DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (Command.fmtid != WPD_CATEGORY_OBJECT_PROPERTIES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED)) - { - hr = OnGetSupportedProperties(pParams, pResults); - CHECK_HR(hr, "Failed to get supported properties"); - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET)) - { - hr = OnGetPropertyValues(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to get properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL)) - { - hr = OnGetAllPropertyValues(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to get all properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_SET)) - { - hr = OnSetPropertyValues(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to set properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES)) - { - hr = OnGetPropertyAttributes(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to get property attributes"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_DELETE)) - { - hr = OnDeleteProperties(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to delete properties"); - } - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose supported properties have - * been requested. - * - * - WPD_PROPERTY_OBJECT_PROPERTIES_FILTER: the filter to use when returning supported properties. - * Since this parameter is optional, it may not exist. - * ! This driver currently ignores the filter parameter. ! - * - * The driver should: - * - Return supported property keys for the specified object in WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS - */ -HRESULT WpdObjectProperties::OnGetSupportedProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose supported properties have been requested - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing string value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // CoCreate a collection to store the supported property keys. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // Add supported property keys for the specified object to the collection - if (hr == S_OK) - { - hr = AddSupportedPropertyKeys(wszObjectID, pKeys); - CHECK_HR(hr, "Failed to add supported property keys for object '%ws'", wszObjectID); - } - - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, pKeys); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values have been requested. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys, identifying which - * specific property values we are requested to return. - * - * The driver should: - * - Return all requested property values in WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES. If any property read failed, the corresponding value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were read successfully. - * - S_FALSE should be returned if any property read failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property values have been requested - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // Get the list of property keys for the property values the caller wants to retrieve from the specified object - if (hr == S_OK) - { - hr = pParams->GetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, &pKeys); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - // CoCreate a collection to store the property values. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Read the specified properties on the specified object and add the property values to the collection. - if (hr == S_OK) - { - hr = GetPropertyValuesForObject(wszObjectID, pKeys, pValues); - CHECK_HR(hr, "Failed to get property values for object '%ws'", wszObjectID); - } - - // S_OK or S_FALSE can be returned from GetPropertyValuesForObject( ). - // S_FALSE means that 1 or more property values could not be retrieved successfully. - // The value for the specified property should be set to an error HRESULT of - // the reason why the property could not be read. - // (e.g. If the property being requested is not supported on the object then an error of - // HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) should be set as the value. - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES value in the results. - HRESULT hrTemp = S_OK; - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, pValues); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values have been requested. - * - * The driver should: - * - Return all property values in WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES. If any property read failed, the corresponding value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were read successfully. - * - S_FALSE should be returned if any property read failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetAllPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property values have been requested - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // CoCreate a collection to store the property values. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the property keys we are going to use - // to request the property values of. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // First we make a request for ALL supported property keys for the specified object. - // Next, we delegate to our helper function GetPropertyValuesForObject( ) passing - // the entire property key collection. This will reuse existing implementation - // in our driver to perform the GetAllPropertyValues operation. - if (hr == S_OK) - { - hr = AddSupportedPropertyKeys(wszObjectID, pKeys); - CHECK_HR(hr, "Failed to get ALL supported properties for object '%ws'", wszObjectID); - if (hr == S_OK) - { - hr = GetPropertyValuesForObject(wszObjectID, pKeys, pValues); - CHECK_HR(hr, "Failed to get property values for object '%ws'", wszObjectID); - } - } - - // S_OK or S_FALSE can be returned from GetPropertyValuesForObject( ). - // S_FALSE means that 1 or more property values could not be retrieved successfully. - // The value for the specified property key should be set to the error HRESULT of - // the reason why the property could not be read. - // (i.e. an error of HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) if a property value was - // requested and is not supported by the specified object.) - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES value in the results - HRESULT hrTemp = S_OK; - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, pValues); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_SET - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values we want to return. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES: an IPortableDeviceValues of values, identifying which - * specific property values we are requested to write. - * - * The driver should: - * - Write all requested property values. For each property, a write result should be returned in the - * write result property store. - * - If any property write failed, the corresponding write result value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were written successfully. - * - S_FALSE should be returned if any property write failed. - * - Any error return indicates that the driver did not write any results, and the caller will - * not attempt to unpack any property write results. - */ -HRESULT WpdObjectProperties::OnSetPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - DWORD cValues = 0; - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceValues> pWriteResults; - CComPtr<IPortableDeviceValues> pEventParams; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property values are being set - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // Get the caller-supplied property values requested to be set on the object - if (hr == S_OK) - { - hr = pParams->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, &pValues); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES"); - } - - // CoCreate a collection to store the property set operation results. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pWriteResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Set the property values on the specified object - if (hr == S_OK) - { - // Since this driver does not support setting any properties, all property set operation - // results will be set to E_ACCESSDENIED. - if (hr == S_OK) - { - hr = pValues->GetCount(&cValues); - CHECK_HR(hr, "Failed to get total number of values"); - } - - if (hr == S_OK) - { - for (DWORD dwIndex = 0; dwIndex < cValues; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - hr = pValues->GetAt(dwIndex, &Key, NULL); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d", dwIndex); - - if (hr == S_OK) - { - hr = pWriteResults->SetErrorValue(Key, E_ACCESSDENIED); - CHECK_HR(hr, "Failed to set error result value at index %d", dwIndex); - } - } - } - - // Since we have set failures for the property set operations we must let the application - // know by returning S_FALSE. This will instruct the application to look at the - // property set operation results for failure values. - if (hr == S_OK) - { - hr = S_FALSE; - } - } - - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_WRITE_RESULTS value in the results - HRESULT hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_WRITE_RESULTS, pWriteResults); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_WRITE_RESULTS")); - - if (FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property attributes we want to return. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys containing a single value, - * which is the key identifying the specific property attributes we are requested to return. - * - * The driver should: - * - Return the requested property attributes. If any property attributes failed to be retrieved, - * the corresponding value should be set to type VT_ERROR with the 'scode' member holding the - * HRESULT reason for the failure. - * - S_OK should be returned if all property attributes were read successfully. - * - S_FALSE should be returned if any property attribute failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - PROPERTYKEY Key = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pAttributes; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property attributes have been requested - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // Get the list of property keys whose attributes are being requested - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, &Key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - // CoCreate a collection to store the property attributes. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Get the attributes for the specified properties on the specified object and add them - // to the collection. - if (hr == S_OK) - { - hr = GetPropertyAttributesForObject(wszObjectID, Key, pAttributes); - CHECK_HR(hr, "Failed to get property attributes"); - } - - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_ATTRIBUTES value in the results - HRESULT hrTemp = S_OK; - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_ATTRIBUTES, pAttributes); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_ATTRIBUTES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_DELETE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose properties should be deleted. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys indicating which - * properties to delete. - * - * The driver should: - * - Delete the specified properties from the object. - * - S_OK should be returned if all specified properties were successfully deleted. - * - E_ACCESSDENIED should be returned if the client attempts to delete a property which is not deletable (i.e. - * WPD_PROPERTY_ATTRIBUTE_CAN_DELETE is FALSE for that property.) - */ -HRESULT WpdObjectProperties::OnDeleteProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = E_ACCESSDENIED; - - UNREFERENCED_PARAMETER(pParams); - UNREFERENCED_PARAMETER(pResults); - - // This driver has no properties which can be deleted. - - return hr; -} - -/** - * This method is called to populate supported PROPERTYKEYs found on objects. - * - * The parameters sent to us are: - * wszObjectID - the object whose supported property keys are being requested - * pKeys - An IPortableDeviceKeyCollection to be populated with supported PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the specified object. - */ -HRESULT AddSupportedPropertyKeys( - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys) -{ - HRESULT hr = S_OK; - CAtlStringW strObjectID = wszObjectID; - - // Add Common PROPERTYKEYs for ALL WPD objects - AddCommonPropertyKeys(pKeys); - - if (strObjectID.CompareNoCase(WPD_DEVICE_OBJECT_ID) == 0) - { - // Add the PROPERTYKEYs for the 'DEVICE' object - AddDevicePropertyKeys(pKeys); - } - - if (strObjectID.CompareNoCase(STORAGE_OBJECT_ID) == 0) - { - // Add the PROPERTYKEYs for the storage object - AddStoragePropertyKeys(pKeys); - } - - if (strObjectID.CompareNoCase(README_FILE_OBJECT_ID) == 0) - { - // Add the PROPERTYKEYs for the file object - AddFilePropertyKeys(pKeys); - } - - if (strObjectID.CompareNoCase(DOCUMENTS_FOLDER_OBJECT_ID) == 0) - { - // Add the PROPERTYKEYs for the folder object - AddFolderPropertyKeys(pKeys); - } - - // Add other PROPERTYKEYs for other supported objects... - - return hr; -} - -/** - * This method is called to populate common PROPERTYKEYs found on ALL objects. - * - * The parameters sent to us are: - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the ALL objects. - */ -VOID AddCommonPropertyKeys( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - if (pKeys != NULL) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedCommonProperties); dwIndex++) - { - HRESULT hr = S_OK; - hr = pKeys->Add(g_SupportedCommonProperties[dwIndex] ); - CHECK_HR(hr, "Failed to add common property"); - } - } -} - -/** - * This method is called to populate common PROPERTYKEYs found on the DEVICE object. - * - * The parameters sent to us are: - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the DEVICE object. - */ -VOID AddDevicePropertyKeys( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - if (pKeys != NULL) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedDeviceProperties); dwIndex++) - { - HRESULT hr = S_OK; - hr = pKeys->Add(g_SupportedDeviceProperties[dwIndex] ); - CHECK_HR(hr, "Failed to add device property"); - } - } -} - -/** - * This method is called to populate common PROPERTYKEYs found on storage objects. - * - * The parameters sent to us are: - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the storage objects. - */ -VOID AddStoragePropertyKeys( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - if (pKeys != NULL) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedStorageProperties); dwIndex++) - { - HRESULT hr = S_OK; - hr = pKeys->Add(g_SupportedStorageProperties[dwIndex] ); - CHECK_HR(hr, "Failed to add storage property"); - } - } -} - -/** - * This method is called to populate common PROPERTYKEYs found on file objects. - * - * The parameters sent to us are: - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the file objects. - */ -VOID AddFilePropertyKeys( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - if (pKeys != NULL) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedCommonFileProperties); dwIndex++) - { - HRESULT hr = S_OK; - hr = pKeys->Add(g_SupportedCommonFileProperties[dwIndex] ); - CHECK_HR(hr, "Failed to add common file property"); - } - } -} - -/** - * This method is called to populate common PROPERTYKEYs found on folder objects. - * - * The parameters sent to us are: - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the file objects. - */ -VOID AddFolderPropertyKeys( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - if (pKeys != NULL) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedCommonFolderProperties); dwIndex++) - { - HRESULT hr = S_OK; - hr = pKeys->Add(g_SupportedCommonFolderProperties[dwIndex] ); - CHECK_HR(hr, "Failed to add common folder property"); - } - } -} - -/** - * This method is called to populate property values for the object specified. - * - * The parameters sent to us are: - * wszObjectID - the object whose properties are being requested. - * pKeys - the list of property keys of the properties to request from the object - * pValues - an IPortableDeviceValues which will contain the property values retreived from the object - * - * The driver should: - * Read the specified properties for the specified object and populate pValues with the - * results. - */ -HRESULT WpdObjectProperties::GetPropertyValuesForObject( - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys, - _In_ IPortableDeviceValues* pValues) -{ - HRESULT hr = S_OK; - CAtlStringW strObjectID = wszObjectID; - DWORD cKeys = 0; - - if ((wszObjectID == NULL) || - (pKeys == NULL) || - (pValues == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - hr = pKeys->GetCount(&cKeys); - CHECK_HR(hr, "Failed to number of PROPERTYKEYs in collection"); - - if (hr == S_OK) - { - // Get values for the DEVICE object - if (strObjectID.CompareNoCase(WPD_DEVICE_OBJECT_ID) == 0) - { - for (DWORD dwIndex = 0; dwIndex < cKeys; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - hr = pKeys->GetAt(dwIndex, &Key); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d in collection", dwIndex); - - if (hr == S_OK) - { - // Preset the property value to 'error not supported'. The actual value - // will replace this value, if read from the device. - pValues->SetErrorValue(Key, HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)); - - // Set DEVICE object properties - if (IsEqualPropertyKey(Key, WPD_DEVICE_FIRMWARE_VERSION)) - { - hr = pValues->SetStringValue(WPD_DEVICE_FIRMWARE_VERSION, DEVICE_FIRMWARE_VERSION_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_FIRMWARE_VERSION"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_POWER_LEVEL)) - { - hr = pValues->SetUnsignedIntegerValue(WPD_DEVICE_POWER_LEVEL, DEVICE_POWER_LEVEL_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_POWER_LEVEL"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_POWER_SOURCE)) - { - hr = pValues->SetUnsignedIntegerValue(WPD_DEVICE_POWER_SOURCE, WPD_POWER_SOURCE_EXTERNAL); - CHECK_HR(hr, "Failed to set WPD_DEVICE_POWER_SOURCE"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_PROTOCOL)) - { - hr = pValues->SetStringValue(WPD_DEVICE_PROTOCOL, DEVICE_PROTOCOL_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_PROTOCOL"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_MODEL)) - { - hr = pValues->SetStringValue(WPD_DEVICE_MODEL, DEVICE_MODEL_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_MODEL"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_SERIAL_NUMBER)) - { - hr = pValues->SetStringValue(WPD_DEVICE_SERIAL_NUMBER, DEVICE_SERIAL_NUMBER_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_SERIAL_NUMBER"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_SUPPORTS_NON_CONSUMABLE)) - { - hr = pValues->SetBoolValue(WPD_DEVICE_SUPPORTS_NON_CONSUMABLE, DEVICE_SUPPORTS_NONCONSUMABLE_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_SUPPORTS_NON_CONSUMABLE"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_MANUFACTURER)) - { - hr = pValues->SetStringValue(WPD_DEVICE_MANUFACTURER, DEVICE_MANUFACTURER_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_MANUFACTURER"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_FRIENDLY_NAME)) - { - hr = pValues->SetStringValue(WPD_DEVICE_FRIENDLY_NAME, DEVICE_FRIENDLY_NAME_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_FRIENDLY_NAME"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_TYPE)) - { - hr = pValues->SetUnsignedIntegerValue(WPD_DEVICE_TYPE, WPD_DEVICE_TYPE_GENERIC); - CHECK_HR(hr, "Failed to set WPD_DEVICE_TYPE"); - } - - // Set general properties for DEVICE - if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ID, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - hr = pValues->SetStringValue(WPD_OBJECT_NAME, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PARENT_ID, L""); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PARENT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_FORMAT, WPD_OBJECT_FORMAT_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CONTENT_TYPE"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - hr = pValues->SetBoolValue(WPD_OBJECT_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CAN_DELETE"); - } - - if (IsEqualPropertyKey(Key, WPD_FUNCTIONAL_OBJECT_CATEGORY)) - { - hr = pValues->SetGuidValue(WPD_FUNCTIONAL_OBJECT_CATEGORY, WPD_FUNCTIONAL_CATEGORY_DEVICE); - CHECK_HR(hr, "Failed to set WPD_FUNCTIONAL_OBJECT_CATEGORY"); - } - } - } - } - else if (strObjectID.CompareNoCase(STORAGE_OBJECT_ID) == 0) - { - for (DWORD dwIndex = 0; dwIndex < cKeys; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - hr = pKeys->GetAt(dwIndex, &Key); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d in collection", dwIndex); - - if (hr == S_OK) - { - // Preset the property value to 'error not supported'. The actual value - // will replace this value, if read from the device. - pValues->SetErrorValue(Key, HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)); - - // Set storage object properties - if (IsEqualPropertyKey(Key, WPD_STORAGE_SERIAL_NUMBER)) - { - hr = pValues->SetStringValue(WPD_STORAGE_SERIAL_NUMBER, STORAGE_SERIAL_NUMBER_VALUE); - CHECK_HR(hr, "Failed to set WPD_STORAGE_SERIAL_NUMBER"); - } - - if (IsEqualPropertyKey(Key, WPD_STORAGE_FREE_SPACE_IN_BYTES)) - { - hr = pValues->SetUnsignedLargeIntegerValue(WPD_STORAGE_FREE_SPACE_IN_BYTES, (STORAGE_FREE_SPACE_IN_BYTES_VALUE - GetObjectSize(README_FILE_OBJECT_ID))); - CHECK_HR(hr, "Failed to set WPD_STORAGE_FREE_SPACE_IN_BYTES"); - } - - if (IsEqualPropertyKey(Key, WPD_STORAGE_CAPACITY)) - { - hr = pValues->SetUnsignedLargeIntegerValue(WPD_STORAGE_CAPACITY, STORAGE_CAPACITY_VALUE); - CHECK_HR(hr, "Failed to set WPD_STORAGE_CAPACITY"); - } - - if (IsEqualPropertyKey(Key, WPD_STORAGE_TYPE)) - { - hr = pValues->SetUnsignedIntegerValue(WPD_STORAGE_TYPE, WPD_STORAGE_TYPE_FIXED_ROM); - CHECK_HR(hr, "Failed to set WPD_STORAGE_TYPE"); - } - - // Set general properties for storage - if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ID, STORAGE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - hr = pValues->SetStringValue(WPD_OBJECT_NAME, STORAGE_OBJECT_NAME_VALUE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, STORAGE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PARENT_ID, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PARENT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_FORMAT, WPD_OBJECT_FORMAT_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CONTENT_TYPE"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - hr = pValues->SetBoolValue(WPD_OBJECT_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CAN_DELETE"); - } - - if (IsEqualPropertyKey(Key, WPD_FUNCTIONAL_OBJECT_CATEGORY)) - { - hr = pValues->SetGuidValue(WPD_FUNCTIONAL_OBJECT_CATEGORY, WPD_FUNCTIONAL_CATEGORY_STORAGE); - CHECK_HR(hr, "Failed to set WPD_FUNCTIONAL_OBJECT_CATEGORY"); - } - - if (IsEqualPropertyKey(Key, WPD_STORAGE_FILE_SYSTEM_TYPE)) - { - hr = pValues->SetStringValue(WPD_STORAGE_FILE_SYSTEM_TYPE, STORAGE_FILE_SYSTEM_TYPE_VALUE); - CHECK_HR(hr, "Failed to set WPD_STORAGE_FILE_SYSTEM_TYPE"); - } - - if (IsEqualPropertyKey(Key, WPD_STORAGE_DESCRIPTION)) - { - hr = pValues->SetStringValue(WPD_STORAGE_DESCRIPTION, STORAGE_DESCRIPTION_VALUE); - CHECK_HR(hr, "Failed to set WPD_STORAGE_DESCRIPTION"); - } - } - } - } - else if (strObjectID.CompareNoCase(DOCUMENTS_FOLDER_OBJECT_ID) == 0) - { - for (DWORD dwIndex = 0; dwIndex < cKeys; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - hr = pKeys->GetAt(dwIndex, &Key); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d in collection", dwIndex); - - if (hr == S_OK) - { - // Preset the property value to 'error not supported'. The actual value - // will replace this value, if read from the device. - pValues->SetErrorValue(Key, HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)); - - // Set general properties for the folder object - if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ID, DOCUMENTS_FOLDER_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, DOCUMENTS_FOLDER_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PARENT_ID, STORAGE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PARENT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - hr = pValues->SetStringValue(WPD_OBJECT_NAME, DOCUMENTS_FOLDER_OBJECT_NAME_VALUE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_ORIGINAL_FILE_NAME)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, DOCUMENTS_FOLDER_OBJECT_ORIGINAL_FILE_NAME_VALUE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_FORMAT, WPD_OBJECT_FORMAT_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, WPD_CONTENT_TYPE_FOLDER); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CONTENT_TYPE"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - hr = pValues->SetBoolValue(WPD_OBJECT_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CAN_DELETE"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_DATE_MODIFIED)) - { - PROPVARIANT pvDateModified = {0}; - SYSTEMTIME systemtime = {0}; - - systemtime.wMonth = 6; - systemtime.wDay = 26; - systemtime.wYear = 2006; - systemtime.wHour = 5; - - // Initialize the Date Modified PROPVARIANT value - PropVariantInit(&pvDateModified); - - pvDateModified.vt = VT_DATE; - if (SystemTimeToVariantTime(&systemtime, &pvDateModified.date) == TRUE) - { - hr = pValues->SetValue(WPD_OBJECT_DATE_MODIFIED, &pvDateModified); - CHECK_HR(hr, "Failed to set WPD_OBJECT_DATE_MODIFIED"); - } - else - { - LONG lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - - PropVariantClear(&pvDateModified); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_DATE_CREATED)) - { - PROPVARIANT pvDateCreated = {0}; - SYSTEMTIME systemtime = {0}; - - systemtime.wMonth = 1; - systemtime.wDay = 24; - systemtime.wYear = 2006; - systemtime.wHour = 12; - - // Initialize the Date Created PROPVARIANT value - PropVariantInit(&pvDateCreated); - - pvDateCreated.vt = VT_DATE; - if (SystemTimeToVariantTime(&systemtime, &pvDateCreated.date) == TRUE) - { - hr = pValues->SetValue(WPD_OBJECT_DATE_CREATED, &pvDateCreated); - CHECK_HR(hr, "Failed to set WPD_OBJECT_DATE_CREATED"); - } - else - { - LONG lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - - PropVariantClear(&pvDateCreated); - } - } - } - } - else if (strObjectID.CompareNoCase(README_FILE_OBJECT_ID) == 0) - { - for (DWORD dwIndex = 0; dwIndex < cKeys; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - hr = pKeys->GetAt(dwIndex, &Key); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d in collection", dwIndex); - - if (hr == S_OK) - { - // Preset the property value to 'error not supported'. The actual value - // will replace this value, if read from the device. - pValues->SetErrorValue(Key, HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)); - - if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ID, README_FILE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, README_FILE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PARENT_ID, DOCUMENTS_FOLDER_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PARENT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - hr = pValues->SetStringValue(WPD_OBJECT_NAME, README_FILE_OBJECT_NAME_VALUE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_ORIGINAL_FILE_NAME)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, README_FILE_OBJECT_ORIGINAL_FILE_NAME_VALUE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_FORMAT, GetObjectFormat(strObjectID)); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, GetObjectContentType(strObjectID)); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CONTENT_TYPE"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - hr = pValues->SetBoolValue(WPD_OBJECT_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CAN_DELETE"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_SIZE)) - { - hr = pValues->SetUnsignedLargeIntegerValue(WPD_OBJECT_SIZE, GetObjectSize(strObjectID)); - CHECK_HR(hr, "Failed to set WPD_OBJECT_SIZE"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_DATE_MODIFIED)) - { - PROPVARIANT pvDateModified = {0}; - SYSTEMTIME systemtime = {0}; - - systemtime.wMonth = 6; - systemtime.wDay = 26; - systemtime.wYear = 2006; - systemtime.wHour = 5; - - // Initialize the Date Modified PROPVARIANT value - PropVariantInit(&pvDateModified); - - pvDateModified.vt = VT_DATE; - if (SystemTimeToVariantTime(&systemtime, &pvDateModified.date) == TRUE) - { - hr = pValues->SetValue(WPD_OBJECT_DATE_MODIFIED, &pvDateModified); - CHECK_HR(hr, "Failed to set WPD_OBJECT_DATE_MODIFIED"); - } - else - { - LONG lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - - PropVariantClear(&pvDateModified); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_DATE_CREATED)) - { - PROPVARIANT pvDateCreated = {0}; - SYSTEMTIME systemtime = {0}; - - systemtime.wMonth = 1; - systemtime.wDay = 24; - systemtime.wYear = 2006; - systemtime.wHour = 12; - - // Initialize the Date Created PROPVARIANT value - PropVariantInit(&pvDateCreated); - - pvDateCreated.vt = VT_DATE; - if (SystemTimeToVariantTime(&systemtime, &pvDateCreated.date) == TRUE) - { - hr = pValues->SetValue(WPD_OBJECT_DATE_CREATED, &pvDateCreated); - CHECK_HR(hr, "Failed to set WPD_OBJECT_DATE_CREATED"); - } - else - { - LONG lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - - PropVariantClear(&pvDateCreated); - } - } - } - } - } - - return hr; -} - -/** - * This method is called to populate property attributes for the object and property specified. - * - * The parameters sent to us are: - * wszObjectID - the object whose property attributes are being requested. - * Key - the property whose attributes are being requested - * pAttributes - an IPortableDeviceValues which will contain the resulting property attributes - * - * The driver should: - * Read the property attributes for the specified property on the specified object and - * populate pAttributes with the results. - */ -HRESULT WpdObjectProperties::GetPropertyAttributesForObject( - _In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if ((wszObjectID == NULL) || - (pAttributes == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - UNREFERENCED_PARAMETER(wszObjectID); - UNREFERENCED_PARAMETER(Key); - - // - // Since ALL of our properties have the same attributes, we are ignoring the - // passed in wszObjectID and Key parameters. These parameters allow you to - // customize attributes for properties on specific objects. (i.e. WPD_OBJECT_ORIGINAL_FILE_NAME - // may be READ/WRITE on some objects and READONLY on others. ) - // - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_DELETE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_READ"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_WRITE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_WRITE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_FORM, WPD_PROPERTY_ATTRIBUTE_FORM_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FORM"); - } - - return hr; -} - -/** - * This method is called to return the total size of the specified object - * - * The parameters sent to us are: - * strObjectID - the object whose total size is being requested. - * - * The driver should: - * Calculate or read the total size of the object and return it to the caller. - */ -ULONGLONG GetObjectSize(_In_ LPCWSTR wszObjectID) -{ - ULONGLONG FileObjectSize = 0; - - if (_wcsicmp(wszObjectID, README_FILE_OBJECT_ID) == 0) - { - size_t cbFileObjectContents = 0; - if (SUCCEEDED(StringCbLengthA(README_FILE_OBJECT_CONTENTS, STRSAFE_MAX_CCH*sizeof(CHAR), &cbFileObjectContents))) - { - // StringCbLength() returns the size of the string excluding the null terminator, - // so we will account for it in our size calculation. - FileObjectSize = cbFileObjectContents + sizeof(CHAR); - } - } - - return FileObjectSize; -} - -/** - * This method is called to return the WPD format of the specified object - * - * The parameters sent to us are: - * strObjectID - the object whose WPD format is being requested. - * - * The driver should: - * Read the native format of the object and return a WPD format to the caller. - */ -GUID GetObjectFormat(_In_ LPCWSTR wszObjectID) -{ - GUID FileObjectFormat = WPD_OBJECT_FORMAT_UNSPECIFIED; - - if (_wcsicmp(wszObjectID, README_FILE_OBJECT_ID) == 0) - { - FileObjectFormat = WPD_OBJECT_FORMAT_TEXT; - } - - return FileObjectFormat; -} - -/** - * This method is called to return the WPD content type of the specified object - * - * The parameters sent to us are: - * strObjectID - the object whose WPD content type is being requested. - * - * The driver should: - * Read the native content type of the object and return a WPD content type to the caller. - */ -GUID GetObjectContentType(_In_ LPCWSTR wszObjectID) -{ - GUID FileObjectFormat = WPD_CONTENT_TYPE_UNSPECIFIED; - - if (_wcsicmp(wszObjectID, README_FILE_OBJECT_ID) == 0) - { - FileObjectFormat = WPD_CONTENT_TYPE_DOCUMENT; - } - - return FileObjectFormat; -} diff --git a/wpd/WpdHelloWorldDriver/WpdObjectProperties.h b/wpd/WpdHelloWorldDriver/WpdObjectProperties.h deleted file mode 100644 index 43048a34..00000000 --- a/wpd/WpdHelloWorldDriver/WpdObjectProperties.h +++ /dev/null @@ -1,80 +0,0 @@ -#pragma once - -#define DEVICE_PROTOCOL_VALUE L"Hello World Protocol ver 1.00" -#define DEVICE_FIRMWARE_VERSION_VALUE L"1.0.0.0" -#define DEVICE_POWER_LEVEL_VALUE 100 -#define DEVICE_MODEL_VALUE L"Hello World!" -#define DEVICE_FRIENDLY_NAME_VALUE L"Hello World!" -#define DEVICE_MANUFACTURER_VALUE L"Windows Portable Devices Group" -#define DEVICE_SERIAL_NUMBER_VALUE L"01234567890123-45676890123456" -#define DEVICE_SUPPORTS_NONCONSUMABLE_VALUE TRUE - -#define STORAGE_OBJECT_ID L"123ABC" -#define STORAGE_CAPACITY_VALUE 1024 * 1024 -#define STORAGE_FREE_SPACE_IN_BYTES_VALUE STORAGE_CAPACITY_VALUE -#define STORAGE_SERIAL_NUMBER_VALUE L"98765432109876-54321098765432" -#define STORAGE_OBJECT_NAME_VALUE L"Internal Memory" -#define STORAGE_FILE_SYSTEM_TYPE_VALUE L"FAT32" -#define STORAGE_DESCRIPTION_VALUE L"Hello World! Memory Storage System" - -#define DOCUMENTS_FOLDER_OBJECT_ID L"XYZ456" -#define DOCUMENTS_FOLDER_OBJECT_NAME_VALUE L"Documents Folder" -#define DOCUMENTS_FOLDER_OBJECT_ORIGINAL_FILE_NAME_VALUE L"Documents" - -#define README_FILE_OBJECT_ID L"6543210" -#define README_FILE_OBJECT_NAME_VALUE L"Sample ReadMe Text File" -#define README_FILE_OBJECT_ORIGINAL_FILE_NAME_VALUE L"ReadMe.txt" -#define README_FILE_OBJECT_CONTENTS "Hello World!\r\nThis is a text file transferred from the WPD Hello World sample driver.\r\n" - -ULONGLONG GetObjectSize(_In_ LPCWSTR wszObjectID); -GUID GetObjectFormat(_In_ LPCWSTR wszObjectID); -GUID GetObjectContentType(_In_ LPCWSTR wszObjectID); -HRESULT AddSupportedPropertyKeys(_In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys); - -VOID AddCommonPropertyKeys(_In_ IPortableDeviceKeyCollection* pKeys); -VOID AddDevicePropertyKeys(_In_ IPortableDeviceKeyCollection* pKeys); -VOID AddStoragePropertyKeys(_In_ IPortableDeviceKeyCollection* pKeys); -VOID AddFilePropertyKeys(_In_ IPortableDeviceKeyCollection* pKeys); -VOID AddFolderPropertyKeys(_In_ IPortableDeviceKeyCollection* pKeys); - -class WpdObjectProperties -{ -public: - WpdObjectProperties(); - virtual ~WpdObjectProperties(); - - HRESULT Initialize(); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedProperties(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetPropertyValues(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetAllPropertyValues(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnSetPropertyValues(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetPropertyAttributes(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnDeleteProperties(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - - HRESULT GetPropertyValuesForObject(_In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys, - _In_ IPortableDeviceValues* pValues); - - HRESULT GetPropertyAttributesForObject(_In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes); -}; diff --git a/wpd/WpdHelloWorldDriver/WpdObjectResources.cpp b/wpd/WpdHelloWorldDriver/WpdObjectResources.cpp deleted file mode 100644 index f0876d25..00000000 --- a/wpd/WpdHelloWorldDriver/WpdObjectResources.cpp +++ /dev/null @@ -1,676 +0,0 @@ -#include "stdafx.h" -#include "wpdobjectresources.tmh" - -WpdObjectResources::WpdObjectResources() -{ - -} - -WpdObjectResources::~WpdObjectResources() -{ - -} - -HRESULT WpdObjectResources::DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (Command.fmtid != WPD_CATEGORY_OBJECT_RESOURCES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_GET_SUPPORTED)) - { - hr = OnGetSupportedResources(pParams, pResults); - CHECK_HR(hr, "Failed to get supported resources"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_OPEN)) - { - hr = OnOpenResource(pParams, pResults); - CHECK_HR(hr, "Failed to open resource"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_READ)) - { - hr = OnReadResource(pParams, pResults); - CHECK_HR(hr, "Failed to read resource"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_CLOSE)) - { - hr = OnCloseResource(pParams, pResults); - CHECK_HR(hr, "Failed to close resource"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_GET_ATTRIBUTES)) - { - hr = OnGetResourceAttributes(pParams, pResults); - CHECK_HR(hr, "Failed to get resource attributes"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_GET_SUPPORTED - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID: identifies the object whose resources we want to return. - * - * The driver should: - * - Return all resources for this object in WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS. - */ -HRESULT WpdObjectResources::OnGetSupportedResources( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // Get the Object ID - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID, &wszObjectID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID"); - } - - // Create the collection to hold the resource keys - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - if (hr == S_OK) - { - hr = GetSupportedResourcesForObject(wszObjectID, pKeys); - CHECK_HR(hr, "Failed to get supported resources for object '%ws'", wszObjectID); - } - - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS, pKeys); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_GET_ATTRIBUTES - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID: identifies the object whose resource attributes we want to return. - * - WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS: a collection of property keys containing a single value, - * which is the key identifying the specific resource we are requested to return attributes for. - * - * The driver should: - * - Return the requested property attributes in WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_ATTRIBUTES. - * If any resource attributes failed to be retrieved, - * the corresponding value should be set to type VT_ERROR with the 'scode' member holding the - * HRESULT reason for the failure. - * - S_OK should be returned if all resource attributes were read successfully. - * - S_FALSE should be returned if any resource attribute failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - * - */ -HRESULT WpdObjectResources::OnGetResourceAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - PROPERTYKEY Key = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pAttributes; - - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID"); - } - - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS, &Key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = GetResourceAttributesForObject(wszObjectID, Key, pAttributes); - CHECK_HR(hr, "Failed to get resource attributes"); - } - - if (SUCCEEDED(hr)) - { - HRESULT hrTemp = S_OK; - - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_ATTRIBUTES, pAttributes); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_ATTRIBUTES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_OPEN - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID: the object identifier of the - * object which contains the specified resource - * - * - WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS: the specified resource - * to open - * - * - WPD_PROPERTY_OBJECT_RESOURCES_ACCESS_MODE: the access mode to which to - * open the specified resource - * - * The driver should: - * - Create a new context for this resource operation. - * - Return an identifier for the context in WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT. - * - Set the optimal transfer size in WPD_PROPERTY_OBJECT_RESOURCES_OPTIMAL_TRANSFER_BUFFER_SIZE - * - */ -HRESULT WpdObjectResources::OnOpenResource( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - PROPERTYKEY Key = WPD_PROPERTY_NULL; - DWORD dwMode = STGM_READ; - CAtlStringW strStrObjectID; - CAtlStringW strResourceContext; - ContextMap* pContextMap = NULL; - - // Get the Object identifier of the object which contains the specified resource - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID, &wszObjectID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID"); - } - - // Get the resource key - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS, &Key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS"); - } - - // Get the access mode - if (hr == S_OK) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_ACCESS_MODE, &dwMode); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_ACCESS_MODE"); - } - - // Validate whether the params given to us are correct. In this case, we need to check that the object - // supports the resource requested, and can be opened in the requested access mode. - if (hr == S_OK) - { - // In this sample, we only have one object (README_FILE_OBJECT_ID) which supports a - // resource (WPD_RESOURCE_DEFAULT) for reading only. - // So if any other Object ID or any other resource is specified, it must be invalid. - strStrObjectID = wszObjectID; - if(strStrObjectID.CompareNoCase(README_FILE_OBJECT_ID) != 0) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Object [%ws] does not support resources", wszObjectID); - } - if (hr == S_OK) - { - if (!IsEqualPropertyKey(Key, WPD_RESOURCE_DEFAULT)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Only WPD_RESOURCE_DEFAULT is supported in this sample driver"); - } - } - if (hr == S_OK) - { - if ((dwMode & STGM_WRITE) != 0) - { - hr = E_ACCESSDENIED; - CHECK_HR(hr, "This resource is not available for write access"); - } - } - } - - // Get the context map which the driver stored in pParams for convenience - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Create a new resource operation context, initialize it, and add it to the client context map. - if (hr == S_OK) - { - WpdObjectResourceContext* pResourceContext = new WpdObjectResourceContext(); - if (pResourceContext != NULL) - { - // Initialize the resource context with ... - pResourceContext->m_strObjectID = wszObjectID; - pResourceContext->m_Resource = Key; - pResourceContext->m_BytesTransferred = 0; - pResourceContext->m_BytesTotal = GetObjectSize(wszObjectID); - - // Add the resource context to the context map - pContextMap->Add(pResourceContext, strResourceContext); - - // Release the resource context because it has been AddRef'ed during Add() - SAFE_RELEASE(pResourceContext); - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate resource context"); - } - } - - if (hr == S_OK) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, strResourceContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Set the optimal buffer size - if (hr == S_OK) - { - hr = pResults->SetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_OPTIMAL_TRANSFER_BUFFER_SIZE, FILE_OPTIMAL_READ_BUFFER_SIZE_VALUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_OPTIMAL_TRANSFER_BUFFER_SIZE value"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_READ - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT: the context the driver returned to - * the client in OnOpenResource. - * - WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ: the number of bytes to - * read from the resource. - * - * The driver should: - * - Read data associated with the resource and return it back to the caller in - * WPD_PROPERTY_OBJECT_RESOURCES_DATA. - * - Report the number of bytes actually read from the resource in - * WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_READ. This number may be smaller - * than WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ when reading the last - * chunk of data from the resource. - */ -HRESULT WpdObjectResources::OnReadResource( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszResourceContext = NULL; - DWORD dwNumBytesToRead = 0; - DWORD dwNumBytesRead = 0; - BYTE* pBuffer = NULL; - WpdObjectResourceContext* pResourceContext = NULL; - ContextMap* pContextMap = NULL; - - // Get the enumeration context identifier for this enumeration operation. We will - // need this to lookup the specific enumeration context in the client context map. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, &wszResourceContext); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Get the number of bytes to read - if (hr == S_OK) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ, &dwNumBytesToRead); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ"); - } - - // Allocate the destination buffer - if (hr == S_OK) - { - pBuffer = reinterpret_cast<BYTE *>(CoTaskMemAlloc(dwNumBytesToRead)); - if (pBuffer == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate the destination buffer"); - } - } - - // Get the client context map so we can retrieve the resource context for this resource - // operation using the WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT property value obtained above. - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (hr == S_OK) - { - pResourceContext = (WpdObjectResourceContext*)pContextMap->GetContext(wszResourceContext); - if (pResourceContext == NULL) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing resource context"); - } - } - - // Read the next chunk of data for this request - if (hr == S_OK && pBuffer != NULL) - { - hr = ReadDataFromResource(pResourceContext, pBuffer, dwNumBytesToRead, &dwNumBytesRead); - CHECK_HR(hr, "Failed to read %d bytes from resource", dwNumBytesToRead); - } - - if (hr == S_OK && pBuffer != NULL) - { - hr = pResults->SetBufferValue(WPD_PROPERTY_OBJECT_RESOURCES_DATA, pBuffer, dwNumBytesRead); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_DATA"); - } - - if (hr == S_OK) - { - hr = pResults->SetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_READ, dwNumBytesRead); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_READ"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszResourceContext); - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pBuffer); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_CLOSE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT: the context the driver returned to - * the client in OnOpenResource. - * - * The driver should: - * - Destroy any data associated with this context. - */ -HRESULT WpdObjectResources::OnCloseResource( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszResourceContext = NULL; - ContextMap* pContextMap = NULL; - - UNREFERENCED_PARAMETER(pResults); - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the resource context identifier for this resource operation. We will - // need this to lookup the specific resource context in the client context map. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, &wszResourceContext); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Get the client context map so we can retrieve the resource context for this resource - // operation using the WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT property value obtained above. - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Destroy any data allocated/associated with the resource context and then remove it from the context map. - // We no longer need to keep this context around because the resource operation has been ended. - if (hr == S_OK) - { - pContextMap->Remove(wszResourceContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszResourceContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called to populate PROPERTYKEYs found on objects. - * - * The parameters sent to us are: - * wszObjectID - the object whose supported resource keys are being requested - * pKeys - An IPortableDeviceKeyCollection to be populated with supported PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the specified object. - */ -HRESULT WpdObjectResources::GetSupportedResourcesForObject( - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys) -{ - HRESULT hr = S_OK; - CAtlStringW strObjectID; - - if ((wszObjectID == NULL) || - (pKeys == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - strObjectID = wszObjectID; - - if (strObjectID.CompareNoCase(README_FILE_OBJECT_ID) == 0) - { - hr = pKeys->Add(WPD_RESOURCE_DEFAULT); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_DEFAULT"); - } - - return hr; -} - -/** - * This method is called to populate resource attributes found on a particular object - * resource. - * - * The parameters sent to us are: - * wszObjectID - the object whose resource attributes are being requested - * Key - the resource on the specified object whose attributes are being returned - * pAttributes - An IPortableDeviceValues to be populated with resource attributes. - * - * The driver should: - * Add attributes pertaining to the resource on the specified object. - */ -HRESULT WpdObjectResources::GetResourceAttributesForObject( - _In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - CAtlStringW strObjectID; - - if ((wszObjectID == NULL) || - (pAttributes == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - strObjectID = wszObjectID; - - if ((strObjectID.CompareNoCase(README_FILE_OBJECT_ID) == 0) && (IsEqualPropertyKey(Key, WPD_RESOURCE_DEFAULT))) - { - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_DELETE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedLargeIntegerValue(WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE, GetObjectSize(strObjectID)); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_READ"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_WRITE, FALSE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_WRITE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_DELETE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetGuidValue(WPD_RESOURCE_ATTRIBUTE_FORMAT, GetObjectFormat(strObjectID)); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_FORMAT"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_OPTIMAL_READ_BUFFER_SIZE, FILE_OPTIMAL_READ_BUFFER_SIZE_VALUE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_OPTIMAL_READ_BUFFER_SIZE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_OPTIMAL_WRITE_BUFFER_SIZE, FILE_OPTIMAL_WRITE_BUFFER_SIZE_VALUE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_OPTIMAL_WRITE_BUFFER_SIZE"); - } - } - - return hr; -} - -/** - * This method is called to read data from a particular object - * resource. - * - * The parameters sent to us are: - * pResourceContext - the resource operation context - * pBuffer - the buffer to read the resource data into - * dwNumBytesToRead - number of bytes to read into the resource. This is also - * the total size of the passed in pBuffer. - * pdwNumBytesRead - On return, should contain the actual number of bytes read into pBuffer - * - * The driver should: - * - Read data from the specified resource - * - Update the resource operation context with transfer state information - * - Return the actual number of bytes written in pdwNumBytesRead. - */ -HRESULT WpdObjectResources::ReadDataFromResource( - _In_ WpdObjectResourceContext* pResourceContext, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) -{ - HRESULT hr = S_OK; - - if ((pResourceContext == NULL) || - (pBuffer == NULL) || - (pdwNumBytesRead == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - *pdwNumBytesRead = 0; - ZeroMemory(pBuffer, dwNumBytesToRead * sizeof(BYTE)); - - // If we have data left to transfer, then transfer up to dwNumBytesToRead - // if possible. - if (pResourceContext->m_BytesTotal >= pResourceContext->m_BytesTransferred) - { - dwNumBytesToRead = (DWORD)min((ULONGLONG)dwNumBytesToRead,(pResourceContext->m_BytesTotal - pResourceContext->m_BytesTransferred)); - } - - // Read the data from the resource - if (dwNumBytesToRead > 0) - { - // If we are reading from our single file resource, make sure you read - // from the proper source data contents. - if (pResourceContext->m_strObjectID.CompareNoCase(README_FILE_OBJECT_ID) == 0) - { - hr = StringCbCopyA((LPSTR)pBuffer, dwNumBytesToRead, README_FILE_OBJECT_CONTENTS); - CHECK_HR(hr, "StringCbCopyA failed, dwNumBytesToRead = %ld", dwNumBytesToRead); - } - } - - if (SUCCEEDED(hr)) - { - // update the number of bytes transferred in the resource context - pResourceContext->m_BytesTransferred += dwNumBytesToRead; - - // set the number of bytes actually read into to pBuffer - *pdwNumBytesRead = dwNumBytesToRead; - } - - return hr; -} diff --git a/wpd/WpdHelloWorldDriver/WpdObjectResources.h b/wpd/WpdHelloWorldDriver/WpdObjectResources.h deleted file mode 100644 index e9d4fb63..00000000 --- a/wpd/WpdHelloWorldDriver/WpdObjectResources.h +++ /dev/null @@ -1,111 +0,0 @@ -#pragma once - -#define FILE_OPTIMAL_READ_BUFFER_SIZE_VALUE (2 * 1024 * 1024) -#define FILE_OPTIMAL_WRITE_BUFFER_SIZE_VALUE (2 * 1024 * 1024) - -// This class is used to store the context for a specific resource operation. -class WpdObjectResourceContext : public IUnknown -{ -public: - WpdObjectResourceContext() : - m_cRef(1), - m_Resource(WPD_RESOURCE_DEFAULT), - m_BytesTransferred(0), - m_BytesTotal(0) - { - - } - - ~WpdObjectResourceContext() - { - - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -private: - DWORD m_cRef; - -// WpdObjectResourceContext specific data -public: - CAtlStringW m_strObjectID; // object identifier of the object whose resource is being transferred - PROPERTYKEY m_Resource; // the specific resource being transferred - ULONGLONG m_BytesTransferred; // number of bytes transferred from the resource to the caller - ULONGLONG m_BytesTotal; // total number of bytes of the resource data -}; - -class WpdObjectResources -{ -public: - WpdObjectResources(); - virtual ~WpdObjectResources(); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedResources(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetResourceAttributes(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnOpenResource(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnReadResource(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnCloseResource(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); -private: - HRESULT GetSupportedResourcesForObject(_In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys); - - HRESULT GetResourceAttributesForObject(_In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes); - - HRESULT ReadDataFromResource(_In_ WpdObjectResourceContext* pResourceContext, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead); -}; diff --git a/wpd/WpdHelloWorldDriver/resource.h b/wpd/WpdHelloWorldDriver/resource.h deleted file mode 100644 index 524ad061..00000000 --- a/wpd/WpdHelloWorldDriver/resource.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -#define IDR_WpdHelloWorldDriver 101 - diff --git a/wpd/WpdHelloWorldDriver/stdafx.h b/wpd/WpdHelloWorldDriver/stdafx.h deleted file mode 100644 index 3cf60c84..00000000 --- a/wpd/WpdHelloWorldDriver/stdafx.h +++ /dev/null @@ -1,266 +0,0 @@ -#pragma once - -#include "resource.h" -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#define STRSAFE_NO_DEPRECATE - -#include <stdio.h> -#include <tchar.h> -#include <strsafe.h> - -#include <atlbase.h> -#include <atlcom.h> -#include <atlcoll.h> -#include <atlstr.h> - -#ifndef SAFE_RELEASE - #define SAFE_RELEASE(p) if( NULL != p ) { ( p )->Release(); p = NULL; } -#endif - -#include "WpdHelloWorldDriver.h" -#include "PortableDeviceTypes.h" -#include "PortableDeviceClassExtension.h" -#include "PortableDevice.h" - -#include <initguid.h> -#include <propkeydef.h> - -// {CDD18979-A7B0-4D5E-9EB2-0A826805CBBD} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT, 0xCDD18979, 0xA7B0, 0x4D5E, 0x9E, 0xB2, 0x0A, 0x82, 0x68, 0x05, 0xCB, 0xBD, 2); -// {9BD949E5-59CF-41AE-90A9-BE1D044F578F} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT, 0x9BD949E5, 0x59CF, 0x41AE, 0x90, 0xA9, 0xBE, 0x1D, 0x04, 0x4F, 0x57, 0x8F, 2); -// {4DF6C8C7-2CE5-457C-9F53-EFCECAA95C04} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, 0x4DF6C8C7, 0x2CE5, 0x457C, 0x9F, 0x53, 0xEF, 0xCE, 0xCA, 0xA9, 0x5C, 0x04, 2); - -class ContextMap : public IUnknown -{ -public: - ContextMap() : - m_cRef(1) - { - - } - - ~ContextMap() - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - - IUnknown* pUnk = NULL; - POSITION elementPosition = NULL; - - elementPosition = m_Map.GetStartPosition(); - while(elementPosition != NULL) - { - pUnk = m_Map.GetNextValue(elementPosition); - if(pUnk != NULL) - { - pUnk->Release(); - } - } - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - return hr; - } - - -public: // Context accessor methods - - // If successful, this method AddRef's the context and returns - // a context key - HRESULT Add( - _In_ IUnknown* pContext, - _Out_ CAtlStringW& key) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - HRESULT hr = S_OK; - GUID guidContext = GUID_NULL; - CComBSTR bstrContext; - - key = L""; - - // Create a unique context key - hr = CoCreateGuid(&guidContext); - if (hr == S_OK) - { - bstrContext = guidContext; - if(bstrContext.Length() > 0) - { - key = bstrContext; - } - else - { - hr = E_OUTOFMEMORY; - } - } - - if (hr == S_OK) - { - // Insert this into the map - POSITION elementPosition = m_Map.SetAt(key, pContext); - if(elementPosition != NULL) - { - // AddRef since we are holding onto it - pContext->AddRef(); - } - else - { - hr = E_OUTOFMEMORY; - } - } - return hr; - } - - void Remove( - _In_ const CAtlStringW& key) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - // Get the element - IUnknown* pContext = NULL; - - if (m_Map.Lookup(key, pContext) == true) - { - // Remove the entry for it - m_Map.RemoveKey(key); - - // Release it - pContext->Release(); - } - } - - // Returns the context pointer. If not found, return value is NULL. - // If non-NULL, caller is responsible for Releasing when it is done, - // since this method will AddRef the context. - IUnknown* GetContext( - _In_ const CAtlStringW& key) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - // Get the element - IUnknown* pContext = NULL; - - if (m_Map.Lookup(key, pContext) == true) - { - // AddRef - pContext->AddRef(); - } - return pContext; - } - -private: - CComAutoCriticalSection m_CriticalSection; - CAtlMap<CAtlStringW, IUnknown*> m_Map; - DWORD m_cRef; -}; - -HRESULT UpdateDeviceFriendlyName( - _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension, - _In_ LPCWSTR wszDeviceFriendlyName); - -#include "WpdObjectEnum.h" -#include "WpdObjectProperties.h" -#include "WpdObjectResources.h" -#include "WpdCapabilities.h" -#include "WpdBaseDriver.h" - -extern HINSTANCE g_hInstance; - -// -// Driver specific tracing #defines -// -// TODO: Change these values to be appropriate for your driver. -// -#define MYDRIVER_TRACING_ID L"Microsoft\\WPD\\HelloWorldDriver" - -// -// TODO: Choose a different trace control GUID -// -#define WPP_CONTROL_GUIDS \ - WPP_DEFINE_CONTROL_GUID(HelloWorldDriverCtlGuid,(607517b9,d810,4074,b4c2,cb7d950c2c32), \ - WPP_DEFINE_BIT(TRACE_FLAG_ALL) \ - WPP_DEFINE_BIT(TRACE_FLAG_DEVICE) \ - WPP_DEFINE_BIT(TRACE_FLAG_DRIVER) \ - WPP_DEFINE_BIT(TRACE_FLAG_QUEUE) \ - ) - -#define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) \ - WPP_LEVEL_LOGGER(flags) - -#define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) \ - (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= lvl) - -// -// This comment block is scanned by the trace preprocessor to define our -// TraceEvents function. -// -// begin_wpp config -// FUNC Trace{FLAG=TRACE_FLAG_ALL}(LEVEL, MSG, ...); -// FUNC TraceEvents(LEVEL, FLAGS, MSG, ...); -// end_wpp - -// -// This comment block is scanned by the trace preprocessor to define our -// CHECK_HR function. -// -// -// begin_wpp config -// USEPREFIX (CHECK_HR,"%!STDPREFIX!"); -// FUNC CHECK_HR{FLAG=TRACE_FLAG_ALL}(hrCheck, MSG, ...); -// USESUFFIX (CHECK_HR, " hr= %!HRESULT!", hrCheck); -// end_wpp - -// -// PRE macro: The name of the macro includes the condition arguments FLAGS and EXP -// define in FUNC above -// -#define WPP_FLAG_hrCheck_PRE(FLAGS, hrCheck) {if(hrCheck != S_OK) { - -// -// POST macro -// The name of the macro includes the condition arguments FLAGS and EXP -// define in FUNC above -#define WPP_FLAG_hrCheck_POST(FLAGS, hrCheck) ; } } - -// -// The two macros below are for checking if the event should be logged and for -// choosing the logger handle to use when calling the ETW trace API -// -#define WPP_FLAG_hrCheck_ENABLED(FLAGS, hrCheck) WPP_FLAG_ENABLED(FLAGS) -#define WPP_FLAG_hrCheck_LOGGER(FLAGS, hrCheck) WPP_FLAG_LOGGER(FLAGS) diff --git a/wpd/WpdMultiTransportDriver/Device.cpp b/wpd/WpdMultiTransportDriver/Device.cpp deleted file mode 100644 index 9e1af476..00000000 --- a/wpd/WpdMultiTransportDriver/Device.cpp +++ /dev/null @@ -1,552 +0,0 @@ -#include "stdafx.h" -#include "Device.h" -#include "WpdMultiTransportDriver_i.c" - -#include "Device.tmh" - -STDMETHODIMP_(HRESULT) -CDevice::OnD0Entry(_In_ IWDFDevice* /*pDevice*/, - WDF_POWER_DEVICE_STATE /*previousState*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnD0Exit(_In_ IWDFDevice* /*pDevice*/, - WDF_POWER_DEVICE_STATE /*newState*/) -{ - return S_OK; -} - -STDMETHODIMP_(VOID) -CDevice::OnSurpriseRemoval(_In_ IWDFDevice* /*pDevice*/) -{ - return; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnQueryRemove(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnQueryStop(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(VOID) -CDevice::OnSelfManagedIoCleanup(_In_ IWDFDevice* /*pDevice*/) -{ - return; -} - -STDMETHODIMP_(VOID) -CDevice::OnSelfManagedIoFlush(_In_ IWDFDevice* /*pDevice*/) -{ - return; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoInit(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoSuspend(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoRestart(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoStop(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnPrepareHardware(_In_ IWDFDevice* pDevice) -{ - HRESULT hr = S_OK; - - if (m_pWpdBaseDriver != NULL) - { - hr = m_pWpdBaseDriver->Initialize(); - CHECK_HR(hr, "Failed to Initialize the driver class"); - } - - // Initialize the WPD Class Extension. This will enable the appropriate WPD interface GUID, - // as well as do any additional initialization (e.g. enabling Legacy Compatibility layers for those drivers - // which requested support in their INF). - if (hr == S_OK && m_pPortableDeviceClassExtension == NULL) - { - CComPtr<IPortableDeviceValues> pOptions; - CComPtr<IPortableDevicePropVariantCollection> pContentTypes; - - hr = CoCreateInstance(CLSID_PortableDeviceClassExtension, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceClassExtension, - (VOID**)&m_pPortableDeviceClassExtension); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceClassExtension"); - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pOptions); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - - if (hr == S_OK) - { - CComPtr<IPortableDeviceValues> pIDs; - - // ATTENTION: The following GUID value is provided for illustrative - // purposes only. - // - // Rather than hard-coding a GUID value in your driver, the driver - // must obtain a GUID value from the device. The GUID value on the - // device can be provisioned by the driver (upon first-connect) by - // using CoCreateGUID and setting that value into non-volatile storage - // on the device. The same GUID value will then be reported by each - // of your device's transports. To avoid a provisioning race condition, - // always read the value from the device after provisioning. Only - // provision the GUID once. Thereafter, always use the value provided - // by the device. - GUID guidFUID = { 0x245e5e81, 0x2c17, 0x40a4, { 0x8b, 0x10, 0xe9, 0x43, 0xc5, 0x4c, 0x97, 0xb2 } }; - - // Initialize the PortableDeviceClassExtension with a list of supported content types for the - // connected device. This will ensure that the correct application compatibility settings will - // be applied for your device. - - // Get supported content types - if (hr == S_OK) - { - hr = GetSupportedContentTypes(&pContentTypes); - CHECK_HR(hr, "Failed to get supported content types"); - } - - // Add the supported types to the options - if (hr == S_OK) - { - hr = pOptions->SetIPortableDevicePropVariantCollectionValue(WPD_CLASS_EXTENSION_OPTIONS_SUPPORTED_CONTENT_TYPES, pContentTypes); - CHECK_HR(hr, "Failed to set WPD_CLASS_EXTENSION_OPTIONS_SUPPORTED_CONTENT_TYPES"); - } - - if (hr == S_OK) - { - m_pWpdBaseDriver->m_pQueueCallback = NULL; - - HRESULT hrTemp = m_pPortableDeviceClassExtension->QueryInterface( - __uuidof(IQueueCallbackDeviceIoControl), - (void**)&m_pWpdBaseDriver->m_pQueueCallback - ); - CHECK_HR(hrTemp, "Failed to obtain IQueueCallbackDeviceIoControl interface from class extension"); - - if (hrTemp == S_OK) - { - // Enable the Multi-Transport Mode option - hr = pOptions->SetBoolValue(WPD_CLASS_EXTENSION_OPTIONS_MULTITRANSPORT_MODE, TRUE); - CHECK_HR(hr, "Failed to enable multi-transport mode"); - - // Create a PnP ID value collection - if (hr == S_OK) - { - hr = CreateIDValues(DEVICE_MANUFACTURER_VALUE, - DEVICE_MODEL_VALUE, - DEVICE_FIRMWARE_VERSION_VALUE, - guidFUID, - &pIDs); - CHECK_HR(hr, "Failed to Create the ID value collection"); - } - - // Add the PnP ID value collection to the options - if (hr == S_OK) - { - hr = pOptions->SetIPortableDeviceValuesValue(WPD_CLASS_EXTENSION_OPTIONS_DEVICE_IDENTIFICATION_VALUES, pIDs); - CHECK_HR(hr, "Failed to set WPD_CLASS_EXTENSION_OPTIONS_DEVICE_IDENTIFICATION_VALUES"); - } - - // Add the transport bandwidth (in kilobits per second units) to the options - // (0 indicates bandwidth unknown) - if (hr == S_OK) - { - // Set the transport bandwidth (optional) - hr = pOptions->SetUnsignedIntegerValue(WPD_CLASS_EXTENSION_OPTIONS_TRANSPORT_BANDWIDTH, 0L); - CHECK_HR(hr, "Failed to set WPD_CLASS_EXTENSION_OPTIONS_TRANSPORT_BANDWIDTH"); - } - } - } - - if (hr == S_OK) - { - hr = m_pPortableDeviceClassExtension->Initialize(pDevice, pOptions); - CHECK_HR(hr, "Failed to Initialize portable device class extension object"); - } - - // Since users commonly have the abiltity to customize their device even when it is not - // connected to the PC, we need to make sure the PC is current when the driver loads. - // - // Send the latest device friendly name to the PortableDeviceClassExtension component - // so the system is always updated with the current device name. - // - // This call should also be made after a successful property set operation of - // WPD_DEVICE_FRIENDLY_NAME. - - LPWSTR wszDeviceFriendlyName = NULL; - - if (hr == S_OK) - { - hr = GetDeviceFriendlyName(&wszDeviceFriendlyName); - CHECK_HR(hr, "Failed to get device's friendly name"); - } - - if (hr == S_OK && wszDeviceFriendlyName != NULL) - { - hr = UpdateDeviceFriendlyName(m_pPortableDeviceClassExtension, wszDeviceFriendlyName); - CHECK_HR(hr, "Failed to update device's friendly name"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszDeviceFriendlyName); - } - } - } - - return hr; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnReleaseHardware(_In_ IWDFDevice* /*pDevice*/) -{ - if (m_pWpdBaseDriver != NULL) - { - m_pWpdBaseDriver->Uninitialize(); - } - - if (m_pPortableDeviceClassExtension != NULL) - { - m_pPortableDeviceClassExtension = NULL; - } - - return S_OK; -} - -HRESULT CDevice::GetSupportedContentTypes( - _Outptr_ IPortableDevicePropVariantCollection** ppContentTypes) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - - if (ppContentTypes == NULL) - { - hr = E_INVALIDARG; - return hr; - } - - // CoCreate a collection to store the WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES command parameters. - if(SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES command results. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Set the params - if(SUCCEEDED(hr)) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - if(SUCCEEDED(hr)) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - if(SUCCEEDED(hr)) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY, WPD_FUNCTIONAL_CATEGORY_ALL); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY")); - } - - // Make the call - if(SUCCEEDED(hr)) - { - hr = m_pWpdBaseDriver->DispatchWpdMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to dispatch message to get supported content types")); - } - - // Get the results - if(SUCCEEDED(hr)) - { - hr = pResults->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES, ppContentTypes); - CHECK_HR(hr, ("Failed to get WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES")); - } - - return hr; -} - -HRESULT CDevice::GetDeviceFriendlyName( - _Outptr_result_maybenull_ LPWSTR* pwszDeviceFriendlyName) -{ - HRESULT hr = S_OK; - - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<IPortableDeviceKeyCollection> pKeys; - CComPtr<IPortableDeviceValues> pValues; - - if (pwszDeviceFriendlyName == NULL) - { - hr = E_INVALIDARG; - return hr; - } - - *pwszDeviceFriendlyName = NULL; - - // CoCreate a collection to store the WPD_COMMAND_OBJECT_PROPERTIES_GET command parameters. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the WPD_COMMAND_OBJECT_PROPERTIES_GET command results. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the requested property keys. In our case, we are requesting just the device friendly name - // (WPD_DEVICE_FRIENDLY_NAME) - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**)&pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection for results"); - } - - // Set the params - if (hr == S_OK) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_OBJECT_PROPERTIES_GET.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - - if (hr == S_OK) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_OBJECT_PROPERTIES_GET.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - - if (hr == S_OK) - { - hr = pParams->SetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID")); - } - - if (hr == S_OK) - { - hr = pKeys->Add(WPD_DEVICE_FRIENDLY_NAME); - CHECK_HR(hr, ("Failed to add WPD_DEVICE_FRIENDLY_NAME to key collection")); - } - - if (hr == S_OK) - { - hr = pParams->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, pKeys); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS")); - } - - // Make the call - if (hr == S_OK) - { - hr = m_pWpdBaseDriver->DispatchWpdMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to dispatch message to get supported content types")); - } - - // Get the results - if (hr == S_OK) - { - hr = pResults->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, &pValues); - CHECK_HR(hr, ("Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES")); - } - - if (hr == S_OK) - { - hr = pValues->GetStringValue(WPD_DEVICE_FRIENDLY_NAME, pwszDeviceFriendlyName); - CHECK_HR(hr, ("Failed to get WPD_DEVICE_FRIENDLY_NAME")); - } - - return hr; -} - -HRESULT -CDevice::CreateIDValues( - _In_ LPCWSTR pszManufacturer, - _In_ LPCWSTR pszModel, - _In_opt_ LPCWSTR pszVersion, - _In_ REFGUID guidFUID, - _COM_Outptr_ IPortableDeviceValues** ppValues) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pValues; - - *ppValues = NULL; - - // Create the object to hold the ID values - hr = CoCreateInstance( - CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pValues); - - if (SUCCEEDED(hr)) - { - hr = pValues->SetStringValue(WPD_DEVICE_MANUFACTURER, pszManufacturer); - } - - if (SUCCEEDED(hr)) - { - hr = pValues->SetStringValue(WPD_DEVICE_MODEL, pszModel); - } - - if (SUCCEEDED(hr) && pszVersion) - { - hr = pValues->SetStringValue(WPD_DEVICE_FIRMWARE_VERSION, pszVersion); - } - - if (SUCCEEDED(hr)) - { - hr = pValues->SetGuidValue(WPD_DEVICE_FUNCTIONAL_UNIQUE_ID, guidFUID); - } - - if (SUCCEEDED(hr)) - { - *ppValues = pValues.Detach(); - } - - return hr; -} - -HRESULT UpdateDeviceFriendlyName( - _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension, - _In_ LPCWSTR wszDeviceFriendlyName) -{ - HRESULT hr = S_OK; - - // If we were passed NULL parameters we have nothing to do, return S_OK. - if ((pPortableDeviceClassExtension == NULL) || - (wszDeviceFriendlyName == NULL)) - { - return S_OK; - } - - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<IPortableDeviceValues> pValues; - - // Prepare to make a call to set the device information - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues for results"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues for results"); - } - - // Get the information values to update and set them in WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES - if (hr == S_OK) - { - hr = pValues->SetStringValue(WPD_DEVICE_FRIENDLY_NAME, wszDeviceFriendlyName); - CHECK_HR(hr, ("Failed to set WPD_DEVICE_FRIENDLY_NAME")); - } - - // Set the params - if (hr == S_OK) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_CLASS_EXTENSION_WRITE_DEVICE_INFORMATION.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - if (hr == S_OK) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_CLASS_EXTENSION_WRITE_DEVICE_INFORMATION.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - if (hr == S_OK) - { - hr = pParams->SetIPortableDeviceValuesValue(WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES, pValues); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES")); - } - - // Make the call - if (hr == S_OK) - { - hr = pPortableDeviceClassExtension->ProcessLibraryMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to process update device information message")); - } - - // A Failed ProcessLibraryMessage operation for updating this value is not considered - // fatal and should return S_OK. - - return S_OK; -} diff --git a/wpd/WpdMultiTransportDriver/Device.h b/wpd/WpdMultiTransportDriver/Device.h deleted file mode 100644 index db76d087..00000000 --- a/wpd/WpdMultiTransportDriver/Device.h +++ /dev/null @@ -1,97 +0,0 @@ -#pragma once - -#include "resource.h" -#include "WpdMultiTransportDriver.h" - -class ATL_NO_VTABLE CDevice : - public CComObjectRootEx<CComMultiThreadModel>, - public IPnpCallback, - public IPnpCallbackSelfManagedIo, - public IPnpCallbackHardware -{ -public: - CDevice() : - m_pWpdBaseDriver(NULL) - { - } - - DECLARE_NOT_AGGREGATABLE(CDevice) - - BEGIN_COM_MAP(CDevice) - COM_INTERFACE_ENTRY(IPnpCallback) - COM_INTERFACE_ENTRY(IPnpCallbackSelfManagedIo) - COM_INTERFACE_ENTRY(IPnpCallbackHardware) - END_COM_MAP() - -public: - static HRESULT - CreateInstance( - _In_ IWDFDeviceInitialize* pDeviceInit, - _In_ WpdBaseDriver* pWpdBaseDriver, - _COM_Outptr_ IUnknown** ppUnkwn) - { - *ppUnkwn = NULL; - - // - // Set device properties. - // - pDeviceInit->SetLockingConstraint(None); - - CComObject< CDevice> *pMyDevice = NULL; - HRESULT hr = CComObject<CDevice>::CreateInstance( &pMyDevice ); - if( SUCCEEDED (hr) ) - { - pMyDevice->AddRef(); - hr = pMyDevice->QueryInterface( __uuidof(IUnknown),(void **) ppUnkwn); - if (hr == S_OK) - { - pMyDevice->m_pWpdBaseDriver = pWpdBaseDriver; - } - pMyDevice->Release(); - pMyDevice = NULL; - } - - return hr; - } - - // IPnpCallback - // - STDMETHOD_(HRESULT, OnD0Entry) (_In_ IWDFDevice* pDevice, WDF_POWER_DEVICE_STATE previousState); - STDMETHOD_(HRESULT, OnD0Exit) (_In_ IWDFDevice* pDevice, WDF_POWER_DEVICE_STATE newState); - STDMETHOD_(VOID, OnSurpriseRemoval)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnQueryRemove) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnQueryStop) (_In_ IWDFDevice* pDevice); - - // IPnpCallbackSelfManagedIo - // - STDMETHOD_(VOID, OnSelfManagedIoCleanup)(_In_ IWDFDevice* pDevice); - STDMETHOD_(VOID, OnSelfManagedIoFlush) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoInit) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoSuspend)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoRestart)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoStop) (_In_ IWDFDevice* pDevice); - - // IPnpCallbackHardware - // - STDMETHOD_(HRESULT, OnPrepareHardware)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnReleaseHardware)(_In_ IWDFDevice* pDevice); - -private: - HRESULT GetSupportedContentTypes( - _Outptr_ IPortableDevicePropVariantCollection** ppContentTypes); - - HRESULT GetDeviceFriendlyName( - _Outptr_result_maybenull_ LPWSTR* pwszDeviceFriendlyName); - - HRESULT CreateIDValues( - _In_ LPCWSTR pszManufacturer, - _In_ LPCWSTR pszModel, - _In_opt_ LPCWSTR pszVersion, - _In_ REFGUID guidFUID, - _COM_Outptr_ IPortableDeviceValues** ppValues); - -private: - WpdBaseDriver* m_pWpdBaseDriver; - CComPtr<IPortableDeviceClassExtension> m_pPortableDeviceClassExtension; -}; - diff --git a/wpd/WpdMultiTransportDriver/Driver.cpp b/wpd/WpdMultiTransportDriver/Driver.cpp deleted file mode 100644 index 584297de..00000000 --- a/wpd/WpdMultiTransportDriver/Driver.cpp +++ /dev/null @@ -1,215 +0,0 @@ -#include "stdafx.h" -#include "Driver.h" -#include "Device.h" -#include "Queue.h" - -CDriver::CDriver() -{ -} - -HRESULT -CDriver::OnDeviceAdd( - _In_ IWDFDriver* pDriver, - _In_ IWDFDeviceInitialize* pDeviceInit - ) -/*++ - -Routine Description: - - The framework calls this function when a device is being added to - the driver stack. - -Arguments: - - IWDFDriver - Framework interface. The driver uses this - interface to create device objects. - IWDFDeviceInitialize - Framework interface. The driver uses this - interface to set device parameters before - creating the device obeject. - -Return Value: - - HRESULT S_OK - Device added successfully - ---*/ -{ - HRESULT hr = S_OK; - CComPtr<IUnknown> pDeviceCallback; - - WpdBaseDriver *pWpdBaseDriver = NULL; - - // - // Create the WPD driver object that handles all WPD messages for this device - // - pWpdBaseDriver = new WpdBaseDriver(); - if(pWpdBaseDriver == NULL) - { - hr = E_OUTOFMEMORY; - } - - if(SUCCEEDED(hr)) - { - // - // Create device callback object - // - hr = CDevice::CreateInstance(pDeviceInit, pWpdBaseDriver, &pDeviceCallback); - } - - // - // This driver has no special power management requirements and so - // we set power policy ownership to UMDF to indicate that UMDF should - // handle powermanagement for us. - // - pDeviceInit->SetPowerPolicyOwnership(FALSE); - - // - // Create WDFDevice. - // - CComPtr<IWDFDevice> pIWDFDevice; - if(SUCCEEDED(hr)) - { - hr = pDriver->CreateDevice( - pDeviceInit, - pDeviceCallback, - &pIWDFDevice); - } - - // - // Assign pWpdBaseDriver to the device object. Each UMDF device requires its own instance of - // a WpdBaseDriver to handle WPD messages. - // - if(SUCCEEDED(hr)) - { - hr = pIWDFDevice->AssignContext(this, (void*)pWpdBaseDriver); - if(SUCCEEDED(hr)) - { - // AddRef the WpdBaseDriver object since it is not stored with the - // device context. - pWpdBaseDriver->AddRef(); - } - } - - // - // Create the default queue callback object - // - CComPtr<IUnknown> pIUnknown; - if(S_OK == hr) - { - hr = CDefaultQueue::CreateInstance(&pIUnknown); - } - - // - // Configure the default queue. - // - if(S_OK == hr) - { - CComPtr<IWDFIoQueue> pDefaultQueue; - hr = pIWDFDevice->CreateIoQueue( - pIUnknown, - TRUE, // bDefaultQueue - WdfIoQueueDispatchParallel, - TRUE, // bPowerManaged - FALSE, // bAllowZeroLengthRequests - &pDefaultQueue); - } - pIUnknown = NULL; - - // - // Create the WPD queue callback object - // - if(S_OK == hr) - { - hr = CQueue::CreateInstance(&pIUnknown); - } - - // - // Configure the WPD queue. - // - if(S_OK == hr) - { - hr = pIWDFDevice->CreateIoQueue( - pIUnknown, - FALSE, // bDefaultQueue - WdfIoQueueDispatchSequential, - TRUE, // bPowerManaged - FALSE, // bAllowZeroLengthRequests - &pWpdBaseDriver->m_pWpdQueue); - } - - pDeviceCallback = NULL; - pIWDFDevice = NULL; - - // - // It is fine to release the interface on the callback object. - // The framework has its own refcount on this object and will - // provide an interface when calling into the driver. - // - pIUnknown = NULL; - - // Release the WpdBaseDriver object. If it was successfully added to the device context, - // it was already addref'd above. Releasing it here ensures it will be destroyed if - // an error occured and it could not be added to the device context. - SAFE_RELEASE(pWpdBaseDriver); - - return hr; -} - -void -CDriver::OnDeinitialize( - _In_ IWDFDriver* pDriver - ) -/*++ - -Routine Description: - - The framework calls this function just before de-initializing itself. All - WDF framework resources should be released by driver before returning from this call. - -Arguments: - -Return Value: - ---*/ -{ - UNREFERENCED_PARAMETER(pDriver); - return; -} - -HRESULT -CDriver::OnInitialize( - _In_ IWDFDriver* pDriver - ) -/*++ - -Routine Description: - - The framework calls this function just after loading the driver. The driver can - perform any global, device independent intialization in this routine. - -Arguments: - -Return Value: - ---*/ -{ - UNREFERENCED_PARAMETER(pDriver); - return S_OK; -} - -STDMETHODIMP_ (void) -CDriver::OnCleanup( - _In_ IWDFObject* pWdfObject - ) -{ - // Release the base driver object - HRESULT hr = S_OK; - WpdBaseDriver* pWpdBaseDriver = NULL; - - hr = pWdfObject->RetrieveContext((void**)&pWpdBaseDriver); - if((hr == S_OK) && (pWpdBaseDriver != NULL)) - { - pWpdBaseDriver->Release(); - pWpdBaseDriver = NULL; - } -} - diff --git a/wpd/WpdMultiTransportDriver/Driver.h b/wpd/WpdMultiTransportDriver/Driver.h deleted file mode 100644 index c4c07ad8..00000000 --- a/wpd/WpdMultiTransportDriver/Driver.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "resource.h" -#include "WpdMultiTransportDriver.h" - -class ATL_NO_VTABLE CDriver : - public CComObjectRootEx<CComMultiThreadModel>, - public CComCoClass<CDriver, &CLSID_WpdMultiTransportDriver>, - public IDriverEntry, - public IObjectCleanup -{ -public: - CDriver(); - - DECLARE_REGISTRY_RESOURCEID(IDR_WpdMultiTransportDriver) - - DECLARE_NOT_AGGREGATABLE(CDriver) - - BEGIN_COM_MAP(CDriver) - COM_INTERFACE_ENTRY(IDriverEntry) - END_COM_MAP() - -public: - // - // IDriverEntry - // - STDMETHOD (OnInitialize)( - _In_ IWDFDriver* pDriver - ); - STDMETHOD (OnDeviceAdd)( - _In_ IWDFDriver* pDriver, - _In_ IWDFDeviceInitialize* pDeviceInit - ); - STDMETHOD_ (void, OnDeinitialize)( - _In_ IWDFDriver* pDriver - ); - - // - // IObjectCleanup - // - STDMETHOD_ (void, OnCleanup)( - _In_ IWDFObject* pWdfObject - ); -}; - -OBJECT_ENTRY_AUTO(__uuidof(WpdMultiTransportDriver), CDriver) - diff --git a/wpd/WpdMultiTransportDriver/Queue.cpp b/wpd/WpdMultiTransportDriver/Queue.cpp deleted file mode 100644 index 9d6c4571..00000000 --- a/wpd/WpdMultiTransportDriver/Queue.cpp +++ /dev/null @@ -1,417 +0,0 @@ -// Queue.cpp : Implementation of CQueue - - -#include "stdafx.h" -#include "Queue.h" -#include <devioctl.h> -#include <initguid.h> - -#include "Queue.tmh" - -// Add table used to lookup the Access required for Wpd Commands -BEGIN_WPD_COMMAND_ACCESS_MAP(g_WpdCommandAccessMap) - DECLARE_WPD_STANDARD_COMMAND_ACCESS_ENTRIES - // Add any custom commands here e.g. - // WPD_COMMAND_ACCESS_ENTRY(MyCustomCommand, WPD_COMMAND_ACCESS_READWRITE) -END_WPD_COMMAND_ACCESS_MAP - -// This enables use to use VERIFY_WPD_COMMAND_ACCESS to check command access function for us. -DECLARE_VERIFY_WPD_COMMAND_ACCESS; - -/****************************************************************************** - * This method gets the WpdBaseDriver associated with the UMDF device object. - * The caller should Release *ppWpdBaseDriver when it is done. - * - * When this device was created, we assigned the WpdBaseDriver as the context. - * So, in order to retrieve the correct WpdBaseDriver for this device, we simply - * get the device context. - *****************************************************************************/ -HRESULT GetWpdBaseDriver( - _In_ IWDFDevice* pDevice, - _Outptr_result_nullonfailure_ WpdBaseDriver** ppWpdBaseDriver) -{ - HRESULT hr = S_OK; - WpdBaseDriver* pContext = NULL; - - if((pDevice == NULL) || (ppWpdBaseDriver == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter for pDevice or ppWpdBaseDriver"); - } - - *ppWpdBaseDriver = NULL; - - if(SUCCEEDED(hr)) - { - hr = pDevice->RetrieveContext((void**)&pContext); - if(SUCCEEDED(hr)) - { - if(pContext != NULL) - { - pContext->AddRef(); - *ppWpdBaseDriver = pContext; - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Device context is NULL"); - } - } - } - - return hr; -} - -// CDefaultQueue - -STDMETHODIMP_ (void) -CDefaultQueue::OnCreateFile( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - _In_ IWDFFile* pFileObject - ) -{ - UNREFERENCED_PARAMETER(pFileObject); - - CComPtr<WpdBaseDriver> pWpdBaseDriver; - CComPtr<IWDFDevice> pDevice; - HRESULT hr = S_OK; - - pQueue->GetDevice(&pDevice); - - hr = GetWpdBaseDriver(pDevice, &pWpdBaseDriver); - CHECK_HR(hr, "Failed to get WpdBaseDriver"); - - if (hr == S_OK) - { - hr = pRequest->ForwardToIoQueue(pWpdBaseDriver->m_pWpdQueue); - CHECK_HR(hr, "Failed to get WpdBaseDriver"); - } - - if (FAILED(hr)) - pRequest->Complete(hr); - - return; -} - -STDMETHODIMP_ (void) -CDefaultQueue::OnDeviceIoControl( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - ULONG ControlCode, - SIZE_T InputBufferSizeInBytes, - SIZE_T OutputBufferSizeInBytes - ) -{ - CComPtr<WpdBaseDriver> pWpdBaseDriver; - CComPtr<IWDFDevice> pDevice; - HRESULT hr = S_OK; - - pQueue->GetDevice(&pDevice); - - hr = GetWpdBaseDriver(pDevice, &pWpdBaseDriver); - CHECK_HR(hr, "Failed to get WpdBaseDriver"); - - if (hr == S_OK) - { - if (IS_WPD_IOCTL(ControlCode)) - { - hr = pRequest->ForwardToIoQueue(pWpdBaseDriver->m_pWpdQueue); - CHECK_HR(hr, "Failed to forward to WPD queue"); - } - else if (pWpdBaseDriver->m_pQueueCallback) - { - pWpdBaseDriver->m_pQueueCallback->OnDeviceIoControl( - pQueue, - pRequest, - ControlCode, - InputBufferSizeInBytes, - OutputBufferSizeInBytes - ); - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Unable to handle IOCTL code '0x%lx'", ControlCode); - } - } - - if (FAILED(hr)) - pRequest->Complete(hr); - - return; -} - -/****************************************************************************** - * This function calls the WpdBaseDriver to handle the WPD message. In order - * to do this it does the following: - * - * - Deserializes pBuffer into an IPortableDeviceValues which holds the command - * input parameters from the WPD application. - * - Creates an IPortableDeviceValues for the results. - * - Calls the WpdBaseDriver to handle the message. (The results of this - * operation are put into the previously created results IPortableDeviceValues.) - * - The results IPortableDeviceValues is then serialized back into pBuffer, making - * sure that it does not overrun ulOutputBufferLength. - * - *****************************************************************************/ -HRESULT CQueue::ProcessWpdMessage( - ULONG ControlCode, - _In_ ContextMap* pClientContextMap, - _In_ IWDFDevice* pDevice, - _In_reads_bytes_(ulInputBufferLength) PVOID pInBuffer, - ULONG ulInputBufferLength, - _Out_writes_bytes_to_(ulOutputBufferLength, *pdwBytesWritten) PVOID pOutBuffer, - ULONG ulOutputBufferLength, - _Out_ DWORD* pdwBytesWritten) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<WpdBaseDriver> pWpdBaseDriver; - - *pdwBytesWritten = 0; - - if (hr == S_OK) - { - hr = m_pWpdSerializer->GetIPortableDeviceValuesFromBuffer((BYTE*)pInBuffer, - ulInputBufferLength, - &pParams); - CHECK_HR(hr, "Failed to deserialize command parameters from input buffer"); - } - - // Verify that that command was sent with the appropriate access - if (hr == S_OK) - { - hr = VERIFY_WPD_COMMAND_ACCESS(ControlCode, pParams, g_WpdCommandAccessMap); - CHECK_HR(hr, "Wpd Command was sent with incorrect access flags"); - } - - // Create the WPD results collection - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Insert the client context map as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the context map. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, pClientContextMap); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Insert the IWDFDevice interface as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the WUDF Device object. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT, pDevice); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT"); - } - - // Insert the IWpdSerializer interface as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the WPD Serializer object. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT, m_pWpdSerializer); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT"); - } - - // Get the WpdBaseDriver so we can dispatch the message - if (hr == S_OK) - { - hr = GetWpdBaseDriver(pDevice, &pWpdBaseDriver); - CHECK_HR(hr, "Failed to get WpdBaseDriver"); - } - - if (hr == S_OK) - { - hr = pWpdBaseDriver->DispatchWpdMessage(pParams, pResults); - CHECK_HR(hr, "Failed to handle WPD command"); - } - - if (hr == S_OK) - { - hr = m_pWpdSerializer->WriteIPortableDeviceValuesToBuffer(ulOutputBufferLength, - pResults, - (BYTE*)pOutBuffer, - pdwBytesWritten); - CHECK_HR(hr, "Failed to serialize results to output buffer"); - } - - return hr; -} - -// CQueue - -STDMETHODIMP_ (void) -CQueue::OnCreateFile( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - _In_ IWDFFile* pFileObject - ) -{ - UNREFERENCED_PARAMETER(pQueue); - - // This critical section protects the section of code where we - // Create the serializer and results interfaces used in handling I/O messages. - // We only need to create them once, then we hang on to them for the lifetime of this - // queue object. - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - HRESULT hr = S_OK; - - // Create the WPD serializer - if ((hr == S_OK) && - (m_pWpdSerializer == NULL)) - { - hr = CoCreateInstance(CLSID_WpdSerializer, - NULL, - CLSCTX_INPROC_SERVER, - IID_IWpdSerializer, - (VOID**)&m_pWpdSerializer); - - CHECK_HR(hr, "Failed to CoCreate CLSID_WpdSerializer"); - } - - // Create the client context map and associate it with the File Object - // so we can obtain it on a per-client basis. - if (hr == S_OK) - { - ContextMap* pClientContextMap = new ContextMap(); - - if(pClientContextMap != NULL) - { - hr = pFileObject->AssignContext(this, (void*)pClientContextMap); - CHECK_HR(hr, "Failed to set client context map"); - - // Release the client context map if we cannot set it - // properly - if(FAILED(hr)) - { - pClientContextMap->Release(); - pClientContextMap = NULL; - } - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to create client context map"); - } - } - - pRequest->Complete(hr); - return; -} - - -STDMETHODIMP_ (void) -CQueue::OnDeviceIoControl( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - ULONG ControlCode, - SIZE_T InputBufferSizeInBytes, - SIZE_T OutputBufferSizeInBytes - ) -{ - HRESULT hr = S_OK; - DWORD dwBytesWritten = 0; - UNREFERENCED_PARAMETER(InputBufferSizeInBytes); - UNREFERENCED_PARAMETER(OutputBufferSizeInBytes); - - if(IS_WPD_IOCTL(ControlCode)) - { - BYTE* pInputBuffer = NULL; - SIZE_T cbInputBuffer = 0; - BYTE* pOutputBuffer = NULL; - SIZE_T cbOutputBuffer = 0; - ContextMap* pClientContextMap = NULL; - CComPtr<IWDFMemory> pMemoryIn; - CComPtr<IWDFMemory> pMemoryOut; - CComPtr<IWDFDevice> pDevice; - CComPtr<IWDFFile> pFileObject; - - // - // Get input memory buffer, the memory object is always returned even if the - // underlying buffer is NULL - // - pRequest->GetInputMemory(&pMemoryIn); - pInputBuffer = (BYTE*) pMemoryIn->GetDataBuffer(&cbInputBuffer); - - // - // Get output memory buffer, the memory object is always returned even if the - // underlying buffer is NULL - // - pRequest->GetOutputMemory(&pMemoryOut); - pOutputBuffer = (BYTE*) pMemoryOut->GetDataBuffer(&cbOutputBuffer); - - // Get the Context map for this client - pRequest->GetFileObject(&pFileObject); - if (pFileObject != NULL) - { - hr = pFileObject->RetrieveContext((void**)&pClientContextMap); - CHECK_HR(hr, "Failed to get Contextmap from WDF File Object"); - - if (hr == S_OK) - { - // Get the device object - pQueue->GetDevice(&pDevice ); - hr = ProcessWpdMessage(ControlCode, - pClientContextMap, - pDevice, - pInputBuffer, - (DWORD)cbInputBuffer, - pOutputBuffer, - (DWORD)cbOutputBuffer, - &dwBytesWritten); - } - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "WDF File Object is NULL"); - } - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Received invalid/unsupported IOCTL code '0x%lx'",ControlCode); - } - - // Complete the request - if (hr == S_OK) - { - pRequest->CompleteWithInformation(hr, dwBytesWritten); - } - else - { - pRequest->Complete(hr); - } - - return; -} - -STDMETHODIMP_ (void) -CQueue::OnCleanup( - _In_ IWDFObject* pWdfObject - ) -{ - // Destroy the client context map - HRESULT hr = S_OK; - ContextMap* pClientContextMap = NULL; - - hr = pWdfObject->RetrieveContext((void**)&pClientContextMap); - if((hr == S_OK) && (pClientContextMap != NULL)) - { - pClientContextMap->Release(); - pClientContextMap = NULL; - } -} - diff --git a/wpd/WpdMultiTransportDriver/Queue.h b/wpd/WpdMultiTransportDriver/Queue.h deleted file mode 100644 index abf14e2c..00000000 --- a/wpd/WpdMultiTransportDriver/Queue.h +++ /dev/null @@ -1,149 +0,0 @@ -// Queue.h : Declaration of the CQueue - -#pragma once -#include "resource.h" // main symbols -#include "WpdMultiTransportDriver.h" - -class ATL_NO_VTABLE CDefaultQueue : - public CComObjectRootEx<CComMultiThreadModel>, - public IQueueCallbackDeviceIoControl, - public IQueueCallbackCreate -{ -public: - CDefaultQueue() - { - - } - - DECLARE_NOT_AGGREGATABLE(CDefaultQueue) - - BEGIN_COM_MAP(CDefaultQueue) - COM_INTERFACE_ENTRY(IQueueCallbackDeviceIoControl) - COM_INTERFACE_ENTRY(IQueueCallbackCreate) - END_COM_MAP() - -public: - static - HRESULT CreateInstance( - _COM_Outptr_ IUnknown** ppUkwn) - { - *ppUkwn = NULL; - CComObject< CDefaultQueue> *pMyQueue = NULL; - HRESULT hr = CComObject<CDefaultQueue>::CreateInstance( &pMyQueue ); - if( SUCCEEDED (hr) ) - { - pMyQueue->AddRef(); - hr = pMyQueue->QueryInterface( __uuidof(IUnknown), (void **) ppUkwn ); - pMyQueue->Release(); - pMyQueue = NULL; - } - - return hr; - } - - // - // Wdf Callbacks - // - - // IQueueCallbackCreateClose - // - STDMETHOD_ (void, OnCreateFile)( - _In_ IWDFIoQueue *pQueue, - _In_ IWDFIoRequest *pRequest, - _In_ IWDFFile *pFileObject - ); - - // - // IQueueCallbackDeviceIoControl - // - STDMETHOD_ (void, OnDeviceIoControl)( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - ULONG ControlCode, - SIZE_T InputBufferSizeInBytes, - SIZE_T OutputBufferSizeInBytes - ); -}; - - -class ATL_NO_VTABLE CQueue : - public CComObjectRootEx<CComMultiThreadModel>, - public IQueueCallbackDeviceIoControl, - public IQueueCallbackCreate, - public IObjectCleanup -{ -public: - CQueue() - { - } - - DECLARE_NOT_AGGREGATABLE(CQueue) - - BEGIN_COM_MAP(CQueue) - COM_INTERFACE_ENTRY(IQueueCallbackDeviceIoControl) - COM_INTERFACE_ENTRY(IQueueCallbackCreate) - END_COM_MAP() - -public: - static - HRESULT CreateInstance( - _COM_Outptr_ IUnknown** ppUkwn) - { - *ppUkwn = NULL; - CComObject< CQueue> *pMyQueue = NULL; - HRESULT hr = CComObject<CQueue>::CreateInstance( &pMyQueue ); - if( SUCCEEDED (hr) ) - { - pMyQueue->AddRef(); - hr = pMyQueue->QueryInterface( __uuidof(IUnknown), (void **) ppUkwn ); - pMyQueue->Release(); - pMyQueue = NULL; - } - return hr; - } - - // - // Wdf Callbacks - // - - // IQueueCallbackCreateClose - // - STDMETHOD_ (void, OnCreateFile)( - _In_ IWDFIoQueue *pQueue, - _In_ IWDFIoRequest *pRequest, - _In_ IWDFFile *pFileObject - ); - - // - // IQueueCallbackDeviceIoControl - // - STDMETHOD_ (void, OnDeviceIoControl)( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - ULONG ControlCode, - SIZE_T InputBufferSizeInBytes, - SIZE_T OutputBufferSizeInBytes - ); - - // - // IObjectCleanup - // - STDMETHOD_ (void, OnCleanup)( - _In_ IWDFObject* pWdfObject - ); - -private: - HRESULT ProcessWpdMessage( - ULONG ControlCode, - _In_ ContextMap* pClientContextMap, - _In_ IWDFDevice* pDevice, - _In_reads_bytes_(ulInputBufferLength) PVOID pInBuffer, - ULONG ulInputBufferLength, - _Out_writes_bytes_to_(ulOutputBufferLength, *pdwBytesWritten) PVOID pOutBuffer, - ULONG ulOutputBufferLength, - _Out_ DWORD* pdwBytesWritten); - - CComPtr<IWpdSerializer> m_pWpdSerializer; - CComAutoCriticalSection m_CriticalSection; -}; - diff --git a/wpd/WpdMultiTransportDriver/README.md b/wpd/WpdMultiTransportDriver/README.md deleted file mode 100644 index 3656e8b9..00000000 --- a/wpd/WpdMultiTransportDriver/README.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -page_type: sample -description: "Demonstrates how to extend the WpdHelloWorldDriver for a device that supports multiple transports." -languages: -- cpp -products: -- windows -- windows-wdk ---- - -# WPD multi-transport sample driver - -The WpdMultiTransportDriver sample demonstrates how you could extend the WpdHelloWorldDriver for a device that supports multiple transports. A transport is a protocol over which a portable device communicates with a computer. Example transports include Internet Protocol (IP), Bluetooth, and USB. - -A number of portable devices now support multiple transports. For example, a number of cell phones support both Bluetooth and USB. Windows supports a multitransport driver model that ensures that only one node appears for each device. - -For a complete description of this sample and its underlying code and functionality, refer to the [WPD MultiTransport Driver](https://docs.microsoft.com/windows-hardware/drivers/portable/the-wpdmultitransportdriver-sample) description in the Windows Driver Kit documentation. - -## Related topics - -[WPD Design Guide](https://docs.microsoft.com/windows-hardware/drivers/portable/wpd-design-guide) - -[WPD Driver Development Tools](https://docs.microsoft.com/windows-hardware/drivers/portable/familiarizing-yourself-with-the-sample-driver) - -[WPD Programming Guide](https://docs.microsoft.com/windows-hardware/drivers/portable/wpd-programming-guide) diff --git a/wpd/WpdMultiTransportDriver/Stdafxsrc.cpp b/wpd/WpdMultiTransportDriver/Stdafxsrc.cpp deleted file mode 100644 index 5105a28d..00000000 --- a/wpd/WpdMultiTransportDriver/Stdafxsrc.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Stdafx.h"
\ No newline at end of file diff --git a/wpd/WpdMultiTransportDriver/WpdBaseDriver.cpp b/wpd/WpdMultiTransportDriver/WpdBaseDriver.cpp deleted file mode 100644 index f57892a3..00000000 --- a/wpd/WpdMultiTransportDriver/WpdBaseDriver.cpp +++ /dev/null @@ -1,250 +0,0 @@ -#include "stdafx.h" -#include "WpdBaseDriver.tmh" - -WpdBaseDriver::WpdBaseDriver() : - m_cRef(1) -{ -} - -WpdBaseDriver::~WpdBaseDriver() -{ - -} - -ULONG __stdcall WpdBaseDriver::AddRef() -{ - InterlockedIncrement((long*) &m_cRef); - return m_cRef; -} - -_At_(this, __drv_freesMem(Mem)) -ULONG __stdcall WpdBaseDriver::Release() -{ - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; -} - -HRESULT __stdcall WpdBaseDriver::QueryInterface( - REFIID riid, - void** ppv) -{ - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - return hr; -} - -HRESULT WpdBaseDriver::DispatchWpdMessage(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - - HRESULT hr = S_OK; - GUID guidCommandCategory = {0}; - DWORD dwCommandID = 0; - PROPERTYKEY CommandKey = WPD_PROPERTY_NULL; - - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, &guidCommandCategory); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_CATEGORY from input parameters"); - } - - if (hr == S_OK) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, &dwCommandID); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_ID from input parameters"); - } - - // If WPD_PROPERTY_COMMON_COMMAND_CATEGORY or WPD_PROPERTY_COMMON_COMMAND_ID could not be extracted - // properly then we should return E_INVALIDARG to the client. - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_CATEGORY or WPD_PROPERTY_COMMON_COMMAND_ID from input parameters"); - } - - if (hr == S_OK) - { - CommandKey.fmtid = guidCommandCategory; - CommandKey.pid = dwCommandID; - - if (CommandKey.fmtid == WPD_CATEGORY_OBJECT_ENUMERATION) - { - hr = m_ObjectEnum.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_OBJECT_PROPERTIES) - { - hr = m_ObjectProperties.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_OBJECT_RESOURCES) - { - hr = m_ObjectResources.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_CAPABILITIES) - { - hr = m_Capabilities.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (IsEqualPropertyKey(CommandKey, WPD_COMMAND_COMMON_GET_OBJECT_IDS_FROM_PERSISTENT_UNIQUE_IDS)) - { - hr = OnGetObjectIDsFromPersistentUniqueIDs(pParams, pResults); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "Unknown command %ws.%d received",CComBSTR(CommandKey.fmtid), CommandKey.pid); - } - } - - HRESULT hrTemp = pResults->SetErrorValue(WPD_PROPERTY_COMMON_HRESULT, hr); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_COMMON_HRESULT")); - - // Set to a success code, to indicate that the message was received. - // the return code for the actual command's results is stored in the - // WPD_PROPERTY_COMMON_HRESULT property. - hr = S_OK; - - return hr; -} - -/** - * This method is called to initialize the driver object. - * This is where the driver would set up it's I/O libraries - * and so on. - */ -HRESULT WpdBaseDriver::Initialize() -{ - return S_OK; -} - -/** - * This method is called to uninitialize the driver object. - * In a real driver, this is where the driver would clean up - * any resources held by this driver. - */ -VOID WpdBaseDriver::Uninitialize() -{ -} - -/** - * This method is called when we receive a WPD_COMMAND_COMMON_GET_OBJECT_IDS_FROM_PERSISTENT_UNIQUE_IDS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS: Contains an IPortableDevicePropVariantCollection of VT_LPWSTR, - * indicating the PersistentUniqueIDs. - * - * The driver should: - * - Iterate through the PersistentUniqueIDs, and convert to a currently valid object id. - * This object ID list should be returned as an IPortableDevicePropVariantCollection of VT_LPWSTR - * in WPD_PROPERTY_COMMON_OBJECT_IDS. - * Order is implicit, i.e. the first element in the Persistent Unique ID list corresponds to the - * to the first element of the ObjectID list and so on. - * - * For those elements where an existing ObjectID could not be found (e.g. the - * object is no longer present on the device), the element will contain the - * empty string (L""). - */ -HRESULT WpdBaseDriver::OnGetObjectIDsFromPersistentUniqueIDs( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - DWORD dwCount = 0; - CComPtr<IPortableDevicePropVariantCollection> pPersistentIDs; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - - if((pParams == NULL) || - (pResults == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Get the list of Persistent IDs - if (hr == S_OK) - { - hr = pParams->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS, &pPersistentIDs); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS"); - } - - // Create the collection to hold the ObjectIDs - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pObjectIDs); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Iterate through the persistent ID list and add the equivalent object ID for each element. - if (hr == S_OK) - { - hr = pPersistentIDs->GetCount(&dwCount); - CHECK_HR(hr, "Failed to get count from persistent ID collection"); - - if (hr == S_OK) - { - DWORD dwIndex = 0; - PROPVARIANT pvPersistentID = {0}; - PROPVARIANT pvObjectID = {0}; - - PropVariantInit(&pvPersistentID); - PropVariantInit(&pvObjectID); - - for(dwIndex = 0; dwIndex < dwCount; dwIndex++) - { - pvObjectID.vt = VT_LPWSTR; - hr = pPersistentIDs->GetAt(dwIndex, &pvPersistentID); - CHECK_HR(hr, "Failed to get persistent ID at index %d", dwIndex); - - // Since our persistent unique identifier are identical to our object - // identifiers, we just return it back to the caller. - if (hr == S_OK) - { - pvObjectID.pwszVal = AtlAllocTaskWideString(pvPersistentID.pwszVal); - } - - if (hr == S_OK) - { - hr = pObjectIDs->Add(&pvObjectID); - CHECK_HR(hr, "Failed to add next Object ID"); - } - - PropVariantClear(&pvPersistentID); - PropVariantClear(&pvObjectID); - - if(FAILED(hr)) - { - break; - } - } - } - } - - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_COMMON_OBJECT_IDS, pObjectIDs); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_COMMON_OBJECT_IDS"); - } - - return hr; -} - diff --git a/wpd/WpdMultiTransportDriver/WpdBaseDriver.h b/wpd/WpdMultiTransportDriver/WpdBaseDriver.h deleted file mode 100644 index a7462df2..00000000 --- a/wpd/WpdMultiTransportDriver/WpdBaseDriver.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -class WpdBaseDriver : - public IUnknown -{ -public: - WpdBaseDriver(); - virtual ~WpdBaseDriver(); - - HRESULT Initialize(); - VOID Uninitialize(); - - HRESULT DispatchWpdMessage(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - HRESULT OnGetObjectIDsFromPersistentUniqueIDs(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -public: // IUnknown - ULONG __stdcall AddRef(); - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release(); - - HRESULT __stdcall QueryInterface(REFIID riid, void** ppv); - -public: - WpdObjectEnumerator m_ObjectEnum; - WpdObjectProperties m_ObjectProperties; - WpdObjectResources m_ObjectResources; - WpdCapabilities m_Capabilities; - CComPtr<IWDFIoQueue> m_pWpdQueue; - CComPtr<IQueueCallbackDeviceIoControl> m_pQueueCallback; - -private: - ULONG m_cRef; -}; - diff --git a/wpd/WpdMultiTransportDriver/WpdCapabilities.cpp b/wpd/WpdMultiTransportDriver/WpdCapabilities.cpp deleted file mode 100644 index 9dd3faed..00000000 --- a/wpd/WpdMultiTransportDriver/WpdCapabilities.cpp +++ /dev/null @@ -1,906 +0,0 @@ -#include "stdafx.h" -#include "WpdCapabilities.tmh" - -const PROPERTYKEY g_SupportedCommands[] = -{ - // WPD_CATEGORY_OBJECT_ENUMERATION - WPD_COMMAND_OBJECT_ENUMERATION_START_FIND, - WPD_COMMAND_OBJECT_ENUMERATION_FIND_NEXT, - WPD_COMMAND_OBJECT_ENUMERATION_END_FIND, - - // WPD_CATEGORY_OBJECT_PROPERTIES - WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED, - WPD_COMMAND_OBJECT_PROPERTIES_GET, - WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL, - WPD_COMMAND_OBJECT_PROPERTIES_SET, - WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES, - WPD_COMMAND_OBJECT_PROPERTIES_DELETE, - - // WPD_CATEGORY_OBJECT_RESOURCES - WPD_COMMAND_OBJECT_RESOURCES_GET_SUPPORTED, - WPD_COMMAND_OBJECT_RESOURCES_OPEN, - WPD_COMMAND_OBJECT_RESOURCES_READ, - WPD_COMMAND_OBJECT_RESOURCES_CLOSE, - WPD_COMMAND_OBJECT_RESOURCES_GET_ATTRIBUTES, - - // WPD_CATEGORY_CAPABILITIES - WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS, - WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS, - WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES, - WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS, - WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES, - WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS, - WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES, - WPD_COMMAND_CAPABILITIES_GET_FIXED_PROPERTY_ATTRIBUTES, -}; - -const GUID g_SupportedFunctionalCategories[] = -{ - WPD_FUNCTIONAL_CATEGORY_DEVICE, - WPD_FUNCTIONAL_CATEGORY_STORAGE, -}; - -WpdCapabilities::WpdCapabilities() -{ - -} - -WpdCapabilities::~WpdCapabilities() -{ - -} - -HRESULT WpdCapabilities::DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (Command.fmtid != WPD_CATEGORY_CAPABILITIES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS)) - { - hr = OnGetSupportedCommands(pParams, pResults); - CHECK_HR(hr, "Failed to get supported commands"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS)) - { - hr = OnGetCommandOptions(pParams, pResults); - CHECK_HR(hr, "Failed to get command options"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES)) - { - hr = OnGetFunctionalCategories(pParams, pResults); - CHECK_HR(hr, "Failed to get functional categories"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS)) - { - hr = OnGetFunctionalObjects(pParams, pResults); - CHECK_HR(hr, "Failed to get functional objects"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES)) - { - hr = OnGetSupportedContentTypes(pParams, pResults); - CHECK_HR(hr, "Failed to get supported content types"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS)) - { - hr = OnGetSupportedFormats(pParams, pResults); - CHECK_HR(hr, "Failed to get supported formats"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES)) - { - hr = OnGetSupportedFormatProperties(pParams, pResults); - CHECK_HR(hr, "Failed to get supported format properties"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_FIXED_PROPERTY_ATTRIBUTES)) - { - hr = OnGetFixedPropertyAttributes(pParams, pResults); - CHECK_HR(hr, "Failed to get fixed property attributes"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_EVENTS)) - { - hr = OnGetSupportedEvents(pParams, pResults); - CHECK_HR(hr, "Failed to get supported events"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_EVENT_OPTIONS)) - { - hr = OnGetEventOptions(pParams, pResults); - CHECK_HR(hr, "Failed to get event options"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return all commands supported by this driver as an - * IPortableDeviceKeyCollection in WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS. - * This includes custom commands, if any. - * - * Note that certain commands require a "command target" to function correctly. - * (e.g. delete object command) It is understood that not all objects are necessarily - * valid targets (e.g. you cannot delete the device object). - */ -HRESULT WpdCapabilities::OnGetSupportedCommands( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pCommands; - UNREFERENCED_PARAMETER(pParams); - - // CoCreate a collection to store the supported commands. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pCommands); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // Add the supported commands to the collection. - if (hr == S_OK) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedCommands); dwIndex++) - { - hr = pCommands->Add(g_SupportedCommands[dwIndex]); - CHECK_HR(hr, "Failed to add supported command at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS, pCommands); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_COMMAND: a collection of property keys containing a single value, - * which identifies the specific command options are requested to return. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS, containing - * the relevant options. If no options are available for this command, the driver should - * return an IPortableDeviceValues with no elements in it. - */ -HRESULT WpdCapabilities::OnGetCommandOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - PROPERTYKEY Command = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pOptions; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the command whose options have been requested - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_CAPABILITIES_COMMAND, &Command); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_COMMAND"); - } - - // CoCreate a collection to store the command options. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pOptions); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Add command options to the collection - if (hr == S_OK) - { - // If your driver supports command options, then they should be added here - // to the command options collection 'pOptions'. - if (IsEqualPropertyKey(WPD_COMMAND_OBJECT_RESOURCES_READ, Command)) - { - // For better read performance, tell the API not to provide the input buffer parameter - // when issuing a WPD_COMMAND_OBJECT_RESOURCES_READ command. - hr = pOptions->SetBoolValue(WPD_OPTION_OBJECT_RESOURCES_NO_INPUT_BUFFER_ON_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_OPTION_OBJECT_RESOURCES_NO_INPUT_BUFFER_ON_READ"); - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS, pOptions); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_CLSID) in - * WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES, containing - * the supported functional categories for this device. - */ -HRESULT WpdCapabilities::OnGetFunctionalCategories( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDevicePropVariantCollection> pFunctionalCategories; - - UNREFERENCED_PARAMETER(pParams); - - // CoCreate a collection to store the supported functional categories. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFunctionalCategories); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported functional categories to the collection. - if (hr == S_OK) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedFunctionalCategories); dwIndex++) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - // Don't call PropVariantClear, since we did not allocate the memory for these GUIDs - - pv.vt = VT_CLSID; - pv.puuid = (GUID*) &g_SupportedFunctionalCategories[dwIndex]; - - hr = pFunctionalCategories->Add(&pv); - CHECK_HR(hr, "Failed to add supported functional category at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES, pFunctionalCategories); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS - * command. It is sent when the caller is interesting in finding the object IDs for all - * functional objects belonging to the specified functional category. - * Note: the number of functional objects is expected to be very small (less than 8 for the - * whole device). - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY - a GUID value containing the category - * the caller is looking for. If the value is WPD_FUNCTIONAL_CATEGORY_ALL, then the driver - * must return all functional objects, no matter which category they belong to. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_LPWSTR) in - * WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS, containing - * the ids of the functional objects who belong to the specified functional category. - * If there are no objects in the specified category, the driver should return an - * empty collection. - */ -HRESULT WpdCapabilities::OnGetFunctionalObjects( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidFunctionalCategory = GUID_NULL; - CComPtr<IPortableDevicePropVariantCollection> pFunctionalObjects; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the functional category whose functional object identifiers have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY, &guidFunctionalCategory); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY"); - } - - // CoCreate a collection to store the supported functional object identifiers. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFunctionalObjects); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported functional object identifiers for the specified functional - // category to the collection. - if (hr == S_OK) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - // Don't call PropVariantClear, since we did not allocate the memory for these object identifiers - - // Add WPD_DEVICE_OBJECT_ID to the functional object identifiers collection - if (hr == S_OK) - { - if ((guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_DEVICE) || - (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_ALL)) - { - pv.vt = VT_LPWSTR; - pv.pwszVal = WPD_DEVICE_OBJECT_ID; - hr = pFunctionalObjects->Add(&pv); - CHECK_HR(hr, "Failed to add device object ID"); - } - } - - // Add STORAGE_OBJECT_ID to the functional object identifiers collection - if (hr == S_OK) - { - if ((guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_STORAGE) || - (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_ALL)) - { - pv.vt = VT_LPWSTR; - pv.pwszVal = STORAGE_OBJECT_ID; - hr = pFunctionalObjects->Add(&pv); - CHECK_HR(hr, "Failed to add storage object ID"); - } - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS, pFunctionalObjects); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES - * command. This message is sent when the client needs to know the possible content types supported - * by the specified functional category. - * If the driver has multiple functional objects that may support different content types, - * the driver should simply merge them together and report all possible types in one list here. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY - a GUID value containing the functional category - * whose content types the caller is interested in. If the value is WPD_FUNCTIONAL_CATEGORY_ALL, then the driver - * must return a list of all content types supported by the device. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_CLSID) in - * WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES, containing - * the content types supported by the specified functional category. - * If there are no objects in the specified category, the driver should return an - * empty collection. - */ -HRESULT WpdCapabilities::OnGetSupportedContentTypes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidFunctionalCategory = GUID_NULL; - CComPtr<IPortableDevicePropVariantCollection> pContentTypes; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the functional category whose supported content types have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY, &guidFunctionalCategory); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY"); - } - - // CoCreate a collection to store the supported content types. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pContentTypes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported content types for the specified functional - // category to the collection. - if (hr == S_OK) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - // Don't call PropVariantClear, since we did not allocate the memory for these GUIDs - - // Add supported content types for known functional categories - if (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_STORAGE) - { - // Add WPD_CONTENT_TYPE_DOCUMENT to the supported content type collection - pv.vt = VT_CLSID; - pv.puuid = (CLSID*)&WPD_CONTENT_TYPE_DOCUMENT; - hr = pContentTypes->Add(&pv); - CHECK_HR(hr, "Failed to add WPD_CONTENT_TYPE_DOCUMENT"); - - if (hr == S_OK) - { - // Add WPD_CONTENT_TYPE_FOLDER to the supported content type collection - pv.vt = VT_CLSID; - pv.puuid = (CLSID*)&WPD_CONTENT_TYPE_FOLDER; - hr = pContentTypes->Add(&pv); - CHECK_HR(hr, "Failed to add WPD_CONTENT_TYPE_FOLDER"); - } - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES, pContentTypes); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS - * command. This message is sent when the client needs to know the possible formats supported - * by the specified content type (e.g. for image objects, the driver may choose to support JPEG and BMP files). - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_CONTENT_TYPE - a GUID value containing the content type - * whose formats the caller is interested in. If the value is WPD_CONTENT_TYPE_ALL, then the driver - * must return a list of all formats supported by the device. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_CLSID) in - * WPD_PROPERTY_CAPABILITIES_FORMATS, indicating the formats supported by the - * specified content type. - * If there are no formats supported by the specified content type, the driver should return an - * empty collection. - */ -HRESULT WpdCapabilities::OnGetSupportedFormats( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidContentType = GUID_NULL; - CComPtr<IPortableDevicePropVariantCollection> pFormats; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the content type whose supported formats have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_CONTENT_TYPE, &guidContentType); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_CONTENT_TYPE"); - } - - // CoCreate a collection to store the supported formats. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFormats); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported formats for the specified content type to the collection. - if (hr == S_OK) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - // Don't call PropVariantClear, since we did not allocate the memory for these GUIDs - - if ((guidContentType == WPD_CONTENT_TYPE_DOCUMENT) || - ((guidContentType == WPD_CONTENT_TYPE_ALL))) - { - // Add WPD_OBJECT_FORMAT_TEXT to the supported formats collection - pv.vt = VT_CLSID; - pv.puuid = (CLSID*)&WPD_OBJECT_FORMAT_TEXT; - hr = pFormats->Add(&pv); - CHECK_HR(hr, "Failed to add WPD_OBJECT_FORMAT_TEXT"); - } - } - - // Set the WPD_PROPERTY_CAPABILITIES_FORMATS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_FORMATS, pFormats); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_FORMATS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES - * command. This message is sent when the client needs to know the typical properties for objects of - * a given format. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FORMAT - a GUID value specifying the format the caller is interested in. - * - * The driver should: - * - Return an IPortableDeviceKeyCollection in WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS, - * containing the property keys. - */ -HRESULT WpdCapabilities::OnGetSupportedFormatProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidObjectFormat = GUID_NULL; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object format whose supported properties have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FORMAT, &guidObjectFormat); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FORMAT"); - } - - // CoCreate a collection to store the supported properties. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // Add the supported properties for the specified object format to the collection. - if (hr == S_OK) - { - hr = AddSupportedPropertyKeys(guidObjectFormat, pKeys); - CHECK_HR(hr, "Failed to get supported properties for a format"); - } - - // Set the WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS, pKeys); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_FIXED_PROPERTY_ATTRIBUTES - * command. This message is sent when the client needs to know the property attributes that - * are the same for all objects of the given format. - * - * Typically, a driver treats objects of a given format the same. Many properties therefore will - * have attributes that are identical across all objects of that format. - * These can be returned here. There are some attributes which may be differ per object instance, - * which are not returned here. - * See WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FORMAT - a GUID value specifying the format the caller is interested in. - * - WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS - a collection of property keys containing a single value, - * which is the key identifying the specific property attributes we are requested to return. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES - * containing the fixed property attributes. - */ -HRESULT WpdCapabilities::OnGetFixedPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidObjectFormat = GUID_NULL; - PROPERTYKEY key = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pAttributes; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object format whose fixed property attributes have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FORMAT, &guidObjectFormat); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FORMAT"); - } - - // Get the property whose fixed property attributes have been requested - if(hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS, &key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS"); - } - - // CoCreate a collection to store the fixed property attributes. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Add the fixed property attributes for the specified object format and property - if (hr == S_OK) - { - hr = GetFixedPropertyAttributesForFormat(guidObjectFormat, key, pAttributes); - CHECK_HR(hr, "Failed to get fixed property attributes"); - } - - // Set the WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES, pAttributes); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_EVENTS - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return all events supported by this driver should be returned as an - * IPortableDeviceKeyCollection in WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS. - * That includes custom commands, if any. - */ -HRESULT WpdCapabilities::OnGetSupportedEvents( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDevicePropVariantCollection> pEvents; - UNREFERENCED_PARAMETER(pParams); - - // CoCreate a collection to store the supported events. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pEvents); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported events to the collection. - if (hr == S_OK) - { - // If your driver supports events, then they should be added here - // to the supported events collection 'pEvents'. - } - - // Set the WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS, pEvents); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_EVENT_OPTIONS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_EVENT: a GUID value indicating the Event whose options should be returned. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS, containing - * the relevant options. - */ -HRESULT WpdCapabilities::OnGetEventOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID Event = GUID_NULL; - CComPtr<IPortableDeviceValues> pOptions; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the event whose options have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_EVENT, &Event); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_EVENT"); - } - - // CoCreate a collection to store the event options. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pOptions); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Add event options to the collection - if (hr == S_OK) - { - // If your driver supports event options, then they should be added here - // to the event options collection 'pOptions'. - } - - // Set the WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS, pOptions); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS"); - } - - return hr; -} - -/** - * This method is called to populate supported PROPERTYKEYs for the - * specified object format. - * - * The parameters sent to us are: - * guidObjectFormat - object format whose supported properties are being requested. - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add supported PROPERTYKEYs pertaining to the specified object format. - */ -HRESULT WpdCapabilities::AddSupportedPropertyKeys( - _In_ REFGUID guidObjectFormat, - _In_ IPortableDeviceKeyCollection* pKeys) -{ - HRESULT hr = S_OK; - - if (pKeys == NULL) - { - hr = E_INVALIDARG; - return hr; - } - - if (guidObjectFormat == WPD_OBJECT_FORMAT_TEXT) - { - AddCommonPropertyKeys(pKeys); - AddFilePropertyKeys(pKeys); - } - else if (guidObjectFormat == WPD_OBJECT_FORMAT_ALL) - { - AddCommonPropertyKeys(pKeys); - } - - return hr; -} - -/** - * This method is called to populate fixed property attributes - * - * The parameters sent to us are: - * guidObjectFormat - the object format whose property attributes are being requested. - * Key - the property whose attributes are being requested - * pAttributes - an IPortableDeviceValues which will contain the resulting property attributes - * - * The driver should: - * Read the property attributes for the specified property for the specified object format and - * populate pAttributes with the results. - */ -HRESULT WpdCapabilities::GetFixedPropertyAttributesForFormat( - _In_ REFGUID guidObjectFormat, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if (pAttributes == NULL) - { - hr = E_INVALIDARG; - return hr; - } - - UNREFERENCED_PARAMETER(guidObjectFormat); - UNREFERENCED_PARAMETER(Key); - - // - // Since ALL of our properties have the same attributes, we are ignoring the - // passed in guidObjectFormat and Key parameters. These parameters allow you to - // customize fixed property attributes for properties for specific formats. - // - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_DELETE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_READ"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_WRITE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_WRITE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_FORM, WPD_PROPERTY_ATTRIBUTE_FORM_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FORM"); - } - - return hr; -} - diff --git a/wpd/WpdMultiTransportDriver/WpdCapabilities.h b/wpd/WpdMultiTransportDriver/WpdCapabilities.h deleted file mode 100644 index ef2902ef..00000000 --- a/wpd/WpdMultiTransportDriver/WpdCapabilities.h +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once - -class WpdCapabilities -{ -public: - WpdCapabilities(); - virtual ~WpdCapabilities(); - - HRESULT Initialize(); - - HRESULT DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedCommands( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetCommandOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFunctionalCategories( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFunctionalObjects( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedContentTypes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedFormats( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedFormatProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFixedPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedEvents( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetEventOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - HRESULT AddSupportedPropertyKeys(_In_ REFGUID guidObjectFormat, - _In_ IPortableDeviceKeyCollection* pKeys); - - HRESULT GetFixedPropertyAttributesForFormat(_In_ REFGUID guidObjectFormat, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes); -}; - diff --git a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.cpp b/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.cpp deleted file mode 100644 index d027ba72..00000000 --- a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "stdafx.h" -#include "resource.h" -#include "WpdMultiTransportDriver.h" - -#include "WpdMultiTransportDriver.tmh" - -HINSTANCE g_hInstance = NULL; - -class CWpdMultiTransportDriverModule : public CAtlDllModuleT< CWpdMultiTransportDriverModule > -{ -public : - DECLARE_REGISTRY_APPID_RESOURCEID(IDR_WpdMultiTransportDriver, "{72D557A2-0914-454F-83A0-350530788B62}") - DECLARE_LIBID(LIBID_WpdMultiTransportDriverLib) -}; - -CWpdMultiTransportDriverModule _AtlModule; - -// DLL Entry Point -extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) -{ - if(dwReason == DLL_PROCESS_ATTACH) - { - g_hInstance = hInstance; - // Initialize tracing. - WPP_INIT_TRACING(MYDRIVER_TRACING_ID); - } - else if (dwReason == DLL_PROCESS_DETACH) - { - // Cleanup tracing. - WPP_CLEANUP(); - } - - return _AtlModule.DllMain(dwReason, lpReserved); -} - -// Used to determine whether the DLL can be unloaded by OLE -STDAPI DllCanUnloadNow(void) -{ - return _AtlModule.DllCanUnloadNow(); -} - -// Returns a class factory to create an object of the requested type -STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID* ppv) -{ - return _AtlModule.DllGetClassObject(rclsid, riid, ppv); -} - -// DllRegisterServer - Adds entries to the system registry -STDAPI DllRegisterServer(void) -{ - // registers object, typelib and all interfaces in typelib - HRESULT hr = _AtlModule.DllRegisterServer(); - return hr; -} - -// DllUnregisterServer - Removes entries from the system registry -STDAPI DllUnregisterServer(void) -{ - HRESULT hr = _AtlModule.DllUnregisterServer(); - return hr; -} diff --git a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.def b/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.def deleted file mode 100644 index 2ee10614..00000000 --- a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.def +++ /dev/null @@ -1,9 +0,0 @@ -; WpdMultiTransportDriver.def : Declares the module parameters. - -LIBRARY "WpdMultiTransportDriver.DLL" - -EXPORTS - DllCanUnloadNow PRIVATE - DllGetClassObject PRIVATE - DllRegisterServer PRIVATE - DllUnregisterServer PRIVATE diff --git a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.idl b/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.idl deleted file mode 100644 index 6b615e8f..00000000 --- a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.idl +++ /dev/null @@ -1,24 +0,0 @@ - -import "oaidl.idl"; -import "ocidl.idl"; - -import "wudfddi.idl"; - -[ - uuid(EE383031-D737-45FD-BE5F-9A2EFE863627), - version(1.0), - helpstring("Windows Portable Device Multi-Transport Sample Driver Type Library") -] -library WpdMultiTransportDriverLib -{ - importlib("stdole2.tlb"); - [ - uuid(0CA6D3F4-9C49-4B81-BA8F-98F43AE6E592), - helpstring("WpdMultiTransportDriver Class") - ] - coclass WpdMultiTransportDriver - { - [default] interface IDriverEntry; - }; -}; - diff --git a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.inx b/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.inx deleted file mode 100644 index 5e20c4c3..00000000 --- a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.inx +++ /dev/null @@ -1,84 +0,0 @@ -; -; WpdMultiTransportDriver.inf -; - -[Version] -Signature="$Windows NT$" -Class=WPD -ClassGuid={EEC5AD98-8080-425f-922A-DABF3DE3F69A} -Provider=%Provider% -CatalogFile=WpdMultiTransportDriver.cat -DriverVer=01/24/2005,1.1.1.1 - -[Manufacturer] -%Mfg%=Standard,NT$ARCH$ - -[Standard.NT$ARCH$] -%BasicDeviceName%=Basic_Install,WUDF\MultiTransport - -[SourceDisksFiles] -WudfUpdate_$UMDFCOINSTALLERVERSION$.dll=1 -WpdMultiTransportDriver.dll=1 - -[SourceDisksNames] -1 = %MediaDescription% - -; =================== WPD Sample Device ================================== - -[Basic_Install] -CopyFiles=System32Copy - -[Basic_Install.hw] -AddReg=Device_AddReg - -[Basic_Install.Services] -AddService=WUDFRd,0x000001fa,WUDFRD_ServiceInstall - -[Basic_Install.CoInstallers] -AddReg=Basic_Install.CoInstallers_AddReg -CopyFiles = CoInstallers_CopyFiles - -[Basic_Install.CoInstallers_AddReg] -HKR,,CoInstallers32,0x00010000,"WudfUpdate_$UMDFCOINSTALLERVERSION$.dll" - -[Basic_Install.Wdf] -UmdfService=WpdMultiTransportDriver, WpdMultiTransportDriver_Install -UmdfServiceOrder=WpdMultiTransportDriver -UmdfKernelModeClientPolicy=AllowKernelModeClients - -[CoInstallers_CopyFiles] -WudfUpdate_$UMDFCOINSTALLERVERSION$.dll - -[WpdMultiTransportDriver_Install] -UmdfLibraryVersion=$UMDFVERSION$ -DriverCLSID="{0CA6D3F4-9C49-4B81-BA8F-98F43AE6E592}" -ServiceBinary=%12%\UMDF\WpdMultiTransportDriver.dll - -[Device_AddReg] -; Enable WIA support for legacy WIA applications -HKR,,"EnableLegacySupport",0x10001,1 - -; Enable default AutoPlay support -HKR,,"EnableDefaultAutoPlaySupport",0x10001,1 - -[WUDFRD_ServiceInstall] -ServiceType=1 -StartType=3 -ErrorControl=1 -ServiceBinary=%12%\WUDFRd.sys - -[DestinationDirs] -System32Copy=12,UMDF ; copy to system32\drivers\umdf -CoInstallers_CopyFiles= 11 - -[System32Copy] -WpdMultiTransportDriver.dll - - -; =================== Generic ================================== - -[Strings] -Provider="TODO-Set-Provider" -Mfg="Windows Portable Devices" -MediaDescription="Windows Portable Device Multi-Transport Sample Driver Installation Media" -BasicDeviceName="Windows Portable Device Multi-Transport Sample Driver" diff --git a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.rc b/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.rc deleted file mode 100644 index c7b89e95..00000000 --- a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.rc +++ /dev/null @@ -1,15 +0,0 @@ -#include "resource.h" -#include <windows.h> -#include <ntverp.h> - -#define VER_FILETYPE VFT_DLL -#define VER_FILESUBTYPE VFT2_UNKNOWN -#define VER_FILEDESCRIPTION_STR "Windows Portable Device Multi-Transport Sample Driver" -#define VER_INTERNALNAME_STR "WpdMultiTransportDriver.dll" - -#include <common.ver> - -1 TYPELIB "WpdMultiTransportDriver.tlb" - -IDR_WpdMultiTransportDriver REGISTRY "WpdMultiTransportDriver.rgs" - diff --git a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.rgs b/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.rgs deleted file mode 100644 index 3bd8066c..00000000 --- a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.rgs +++ /dev/null @@ -1,26 +0,0 @@ -HKCR -{ - WpdMultiTransportDriver.WpdMultiTransportDriver.1 = s 'WpdMultiTransportDriver Class' - { - CLSID = s '{0CA6D3F4-9C49-4B81-BA8F-98F43AE6E592}' - } - WpdMultiTransportDriver.WpdMultiTransportDriver = s 'WpdMultiTransportDriver Class' - { - CLSID = s '{0CA6D3F4-9C49-4B81-BA8F-98F43AE6E592}' - CurVer = s 'WpdMultiTransportDriver.WpdMultiTransportDriver.1' - } - NoRemove CLSID - { - ForceRemove {0CA6D3F4-9C49-4B81-BA8F-98F43AE6E592} = s 'WpdMultiTransportDriver Class' - { - ProgID = s 'WpdMultiTransportDriver.WpdMultiTransportDriver.1' - VersionIndependentProgID = s 'WpdMultiTransportDriver.WpdMultiTransportDriver.1' - InprocServer32 = s '%MODULE%' - { - val ThreadingModel = s 'Free' - } - 'TypeLib' = s '{EE383031-D737-45FD-BE5F-9A2EFE863627}' - } - } -} - diff --git a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.sln b/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.sln deleted file mode 100644 index d978d35e..00000000 --- a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.sln +++ /dev/null @@ -1,28 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0 -MinimumVisualStudioVersion = 12.0 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WpdMultiTransportDriver", "WpdMultiTransportDriver.vcxproj", "{19B0E3C8-853C-47E1-81BA-5E9003B685C8}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - Debug|x64 = Debug|x64 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {19B0E3C8-853C-47E1-81BA-5E9003B685C8}.Debug|Win32.ActiveCfg = Debug|Win32 - {19B0E3C8-853C-47E1-81BA-5E9003B685C8}.Debug|Win32.Build.0 = Debug|Win32 - {19B0E3C8-853C-47E1-81BA-5E9003B685C8}.Release|Win32.ActiveCfg = Release|Win32 - {19B0E3C8-853C-47E1-81BA-5E9003B685C8}.Release|Win32.Build.0 = Release|Win32 - {19B0E3C8-853C-47E1-81BA-5E9003B685C8}.Debug|x64.ActiveCfg = Debug|x64 - {19B0E3C8-853C-47E1-81BA-5E9003B685C8}.Debug|x64.Build.0 = Debug|x64 - {19B0E3C8-853C-47E1-81BA-5E9003B685C8}.Release|x64.ActiveCfg = Release|x64 - {19B0E3C8-853C-47E1-81BA-5E9003B685C8}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.vcxproj b/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.vcxproj deleted file mode 100644 index 4ba4e066..00000000 --- a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.vcxproj +++ /dev/null @@ -1,355 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup Label="ProjectConfigurations"> - <ProjectConfiguration Include="Debug|Win32"> - <Configuration>Debug</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|Win32"> - <Configuration>Release</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Debug|x64"> - <Configuration>Debug</Configuration> - <Platform>x64</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|x64"> - <Configuration>Release</Configuration> - <Platform>x64</Platform> - </ProjectConfiguration> - </ItemGroup> - <PropertyGroup Label="Globals"> - <ProjectGuid>{19B0E3C8-853C-47E1-81BA-5E9003B685C8}</ProjectGuid> - <RootNamespace>$(MSBuildProjectName)</RootNamespace> - <UMDF_VERSION_MAJOR>1</UMDF_VERSION_MAJOR> - <KMDF_VERSION_MAJOR>1</KMDF_VERSION_MAJOR> - <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration> - <Platform Condition="'$(Platform)' == ''">Win32</Platform> - <SampleGuid>{52BF4ED8-1D47-455D-A68B-4EB5A520D156}</SampleGuid> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>False</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>True</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>False</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>True</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> - <PropertyGroup> - <OutDir>$(IntDir)</OutDir> - </PropertyGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ItemGroup Label="WrappedTaskItems"> - <ClCompile Include="WpdMultiTransportDriver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Driver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Device.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Queue.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdBaseDriver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectEnum.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectProperties.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectResources.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdCapabilities.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <Inf Include="WpdMultiTransportDriver.inx"> - <Architecture>$(InfArch)</Architecture> - <SpecifyArchitecture>true</SpecifyArchitecture> - <CopyOutput>.\$(IntDir)\WpdMultiTransportDriver.inf</CopyOutput> - </Inf> - <OtherWpp Include="WpdMultiTransportDriver.rc; WpdMultiTransportDriver.idl"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - </OtherWpp> - </ItemGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <TargetName>WpdMultiTransportDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <TargetName>WpdMultiTransportDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <TargetName>WpdMultiTransportDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <TargetName>WpdMultiTransportDriver</TargetName> - </PropertyGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Link> - <ModuleDefinitionFile>WpdMultiTransportDriver.def</ModuleDefinitionFile> - </Link> - <ClCompile> - <ExceptionHandling> - </ExceptionHandling> - </ClCompile> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Link> - <ModuleDefinitionFile>WpdMultiTransportDriver.def</ModuleDefinitionFile> - </Link> - <ClCompile> - <ExceptionHandling> - </ExceptionHandling> - </ClCompile> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Link> - <ModuleDefinitionFile>WpdMultiTransportDriver.def</ModuleDefinitionFile> - </Link> - <ClCompile> - <ExceptionHandling> - </ExceptionHandling> - </ClCompile> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Link> - <ModuleDefinitionFile>WpdMultiTransportDriver.def</ModuleDefinitionFile> - </Link> - <ClCompile> - <ExceptionHandling> - </ExceptionHandling> - </ClCompile> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemGroup> - <ClCompile Include="Stdafxsrc.cpp"> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Create</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <Midl Include="WpdMultiTransportDriver.idl" /> - <ResourceCompile Include="WpdMultiTransportDriver.rc" /> - </ItemGroup> - <ItemGroup> - <Inf Exclude="@(Inf)" Include="*.inf" /> - <FilesToPackage Include="$(TargetPath)" Condition="'$(ConfigurationType)'=='Driver' or '$(ConfigurationType)'=='DynamicLibrary'" /> - </ItemGroup> - <ItemGroup> - <None Exclude="@(None)" Include="*.txt;*.htm;*.html" /> - <None Exclude="@(None)" Include="*.ico;*.cur;*.bmp;*.dlg;*.rct;*.gif;*.jpg;*.jpeg;*.wav;*.jpe;*.tiff;*.tif;*.png;*.rc2" /> - <None Exclude="@(None)" Include="*.def;*.bat;*.hpj;*.asmx" /> - </ItemGroup> - <ItemGroup> - <ClInclude Exclude="@(ClInclude)" Include="*.h;*.hpp;*.hxx;*.hm;*.inl;*.xsd" /> - </ItemGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> -</Project>
\ No newline at end of file diff --git a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.vcxproj.Filters b/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.vcxproj.Filters deleted file mode 100644 index 2c61aa74..00000000 --- a/wpd/WpdMultiTransportDriver/WpdMultiTransportDriver.vcxproj.Filters +++ /dev/null @@ -1,74 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup> - <Filter Include="Source Files"> - <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;*</Extensions> - <UniqueIdentifier>{579501AE-BAA7-446C-80E9-F1268F7B5ECE}</UniqueIdentifier> - </Filter> - <Filter Include="Header Files"> - <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> - <UniqueIdentifier>{6A931571-7293-41DC-9CD7-5C971281A12C}</UniqueIdentifier> - </Filter> - <Filter Include="Resource Files"> - <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml</Extensions> - <UniqueIdentifier>{6C10CC65-5006-46E6-8E6E-30757F853D90}</UniqueIdentifier> - </Filter> - <Filter Include="Driver Files"> - <Extensions>inf;inv;inx;mof;mc;</Extensions> - <UniqueIdentifier>{33EDBFAB-833D-4375-9867-6848F1C9E425}</UniqueIdentifier> - </Filter> - </ItemGroup> - <ItemGroup> - <ClCompile Include="Device.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Driver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Queue.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Stdafxsrc.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdBaseDriver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdCapabilities.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdMultiTransportDriver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectEnum.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectProperties.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectResources.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <Midl Include="WpdMultiTransportDriver.idl"> - <Filter>Source Files</Filter> - </Midl> - <None Include="WpdMultiTransportDriver.def"> - <Filter>Source Files</Filter> - </None> - </ItemGroup> - <ItemGroup> - <Inf Include="WpdMultiTransportDriver.inx"> - <Filter>Driver Files</Filter> - </Inf> - </ItemGroup> - <ItemGroup> - <ResourceCompile Include="WpdMultiTransportDriver.rc"> - <Filter>Resource Files</Filter> - </ResourceCompile> - </ItemGroup> - <ItemGroup> - <ClInclude Include="WpdObjectResources.h"> - <Filter>Header Files</Filter> - </ClInclude> - </ItemGroup> -</Project>
\ No newline at end of file diff --git a/wpd/WpdMultiTransportDriver/WpdObjectEnum.cpp b/wpd/WpdMultiTransportDriver/WpdObjectEnum.cpp deleted file mode 100644 index 1fb4cab3..00000000 --- a/wpd/WpdMultiTransportDriver/WpdObjectEnum.cpp +++ /dev/null @@ -1,416 +0,0 @@ -#include "stdafx.h" -#include "WpdObjectEnum.tmh" - -WpdObjectEnumerator::WpdObjectEnumerator() -{ - -} - -WpdObjectEnumerator::~WpdObjectEnumerator() -{ - -} - -HRESULT WpdObjectEnumerator::DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (Command.fmtid != WPD_CATEGORY_OBJECT_ENUMERATION) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - - if (hr == S_OK) - { - if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_START_FIND.pid) - { - hr = OnStartFind(pParams, pResults); - CHECK_HR(hr, "Failed to begin enumeration"); - } - else if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_FIND_NEXT.pid) - { - hr = OnFindNext(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to find next object"); - } - } - else if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_END_FIND.pid) - { - hr = OnEndFind(pParams, pResults); - CHECK_HR(hr, "Failed to end enumeration"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_ENUMERATION_START_FIND - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID: the parent where we should start - * the enumeration. - * - WPD_PROPERTY_OBJECT_ENUMERATION_FILTER: the filter to use when doing - * enumeration. Since this parameter is optional, it may not exist. - * This driver currently ignores the filter parameter. - * - * The driver should: - * - Create a new context for this enumeration. - * - Set the string identifier in WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT for the newly created enumeration context. - * This value will be passed back during OnFindNext and OnEndFind. - */ -HRESULT WpdObjectEnumerator::OnStartFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszParentID = NULL; - ContextMap* pContextMap = NULL; - CAtlStringW strEnumContext; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier of the parent where the enumeration is starting from. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID, &wszParentID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID"); - } - - // Get the client context map so we can store an enumeration context for this enumeration - // operation. - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Create and initialize a new enumeration context. - // Add the new enumertion context to the client context map. This context is used to - // keep track of this particular enumeration operation. - if (hr == S_OK) - { - WpdObjectEnumeratorContext* pEnumeratorContext = new WpdObjectEnumeratorContext(); - if (pEnumeratorContext != NULL) - { - // Initialize the enumeration context - InitializeEnumerationContext(pEnumeratorContext, wszParentID); - - // Add the enumeration context to the client context map. - pContextMap->Add(pEnumeratorContext, strEnumContext); - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate enumeration context"); - } - SAFE_RELEASE(pEnumeratorContext); - } - - // Set the WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT value in the results. - // This context identifier will be passed back during OnFindNext and OnEndFind to allow the driver to access it. - if (hr == S_OK) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, strEnumContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszParentID); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -HRESULT WpdObjectEnumerator::OnFindNext(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszEnumContext = NULL; - DWORD dwNumObjectsRequested = 0; - ContextMap* pContextMap = NULL; - WpdObjectEnumeratorContext* pEnumeratorContext = NULL; - DWORD NumObjectsEnumerated = 0; - - CComPtr<IPortableDevicePropVariantCollection> pObjectIDCollection; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the enumeration context identifier for this enumeration operation. - // The enumeration context identifier is needed to lookup the specific - // enumeration context in the client context map for this enumeration operation. - // NOTE that more than one enumeration may be in progress. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, &wszEnumContext); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - // Get the number of objects requested for this enumeration call. - // The driver should always attempt to meet this requested value. - // If there are fewer children than requested, the driver should return the remaining - // children and a return code of S_FALSE. - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_ENUMERATION_NUM_OBJECTS_REQUESTED, &dwNumObjectsRequested); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_NUM_OBJECTS_REQUESTED"); - } - - // Get the client context map so we can retrieve the enumeration context for this enumeration - // operation. - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (hr == S_OK) - { - pEnumeratorContext = (WpdObjectEnumeratorContext*)pContextMap->GetContext(wszEnumContext); - if (pEnumeratorContext == NULL) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing enumeration context"); - } - } - - // CoCreate a collection to store the object identifiers being returned for this enumeration call. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pObjectIDCollection); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // If the enumeration context reports that their are more objects to return, then continue, if not, - // return an empty results set. - if ((hr == S_OK) && (pEnumeratorContext != NULL) && pEnumeratorContext->HasMoreChildrenToEnumerate()) - { - if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(L"") == 0) - { - // We are being asked for the WPD_DEVICE_OBJECT_ID - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to add 'DEVICE' object ID to enumeration collection"); - - // Update the the number of children we are returning for this enumeration call - NumObjectsEnumerated++; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(WPD_DEVICE_OBJECT_ID) == 0) - { - // We are being asked for direct children of the WPD_DEVICE_OBJECT_ID - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, STORAGE_OBJECT_ID); - CHECK_HR(hr, "Failed to add storage object ID to enumeration collection"); - - // Update the the number of children we are returning for this enumeration call - NumObjectsEnumerated++; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(STORAGE_OBJECT_ID) == 0) - { - // We are being asked for direct children of the STORAGE_OBJECT_ID - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, DOCUMENTS_FOLDER_OBJECT_ID); - CHECK_HR(hr, "Failed to add documents folder object ID to enumeration collection"); - - // Update the the number of children we are returning for this enumeration call - NumObjectsEnumerated++; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(DOCUMENTS_FOLDER_OBJECT_ID) == 0) - { - // We are being asked for direct children of the DOCUMENTS_FOLDER_OBJECT_ID - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, README_FILE_OBJECT_ID); - CHECK_HR(hr, "Failed to add documents readme text file object ID to enumeration collection"); - - // Update the the number of children we are returning for this enumeration call - NumObjectsEnumerated++; - } - } - - // Set the collection of object identifiers enumerated in the results - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_ENUMERATION_OBJECT_IDS, pObjectIDCollection); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_ENUMERATION_OBJECT_IDS"); - } - - // If the enumeration context reports that their are no more objects to return then return S_FALSE indicating to the - // caller that we are finished. - if (hr == S_OK) - { - if (pEnumeratorContext != NULL) - { - // Update the number of children we have enumerated and returned to the caller - pEnumeratorContext->m_ChildrenEnumerated += NumObjectsEnumerated; - - // Check the number requested against the number enumerated and set the HRESULT - // accordingly. - if (NumObjectsEnumerated < dwNumObjectsRequested) - { - // We returned less than the number of objects requested to the caller - hr = S_FALSE; - } - else - { - // We returned exactly the number of objects requested to the caller - hr = S_OK; - } - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszEnumContext); - - SAFE_RELEASE(pContextMap); - SAFE_RELEASE(pEnumeratorContext); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_ENUMERATION_END_FIND - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT: the context the driver returned to - * the client in OnStartFind. - * - * The driver should: - * - Destroy any data associated with this context. - */ -HRESULT WpdObjectEnumerator::OnEndFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszEnumContext = NULL; - ContextMap* pContextMap = NULL; - - UNREFERENCED_PARAMETER(pResults); - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the enumeration context identifier for this enumeration operation. We will - // need this to lookup the specific enumeration context in the client context map. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, &wszEnumContext); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - // Get the client context map so we can retrieve the enumeration context for this enumeration - // operation using the WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT property value obtained above. - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Destroy any data allocated/associated with the enumeration context and then remove it from the context map. - // We no longer need to keep this context around because the enumeration has been ended. - if (hr == S_OK) - { - pContextMap->Remove(wszEnumContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszEnumContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -// Initialize the enumeration context -VOID WpdObjectEnumerator::InitializeEnumerationContext( - _In_ WpdObjectEnumeratorContext* pEnumeratorContext, - _In_ LPCWSTR wszParentObjectID) -{ - if (pEnumeratorContext == NULL) - { - return; - } - - // Initialize the enumeration context with the parent object identifier - pEnumeratorContext->m_strParentObjectID = wszParentObjectID; - - // Our sample driver has a very simple object structure where we know - // how many children are under each parent. - // The eumeration context is initialized below with this information. - if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(L"") == 0) - { - // Clients passing an 'empty' string for the parent are asking for the - // 'DEVICE' object. We should return 1 child in this case. - pEnumeratorContext->m_TotalChildren = 1; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(WPD_DEVICE_OBJECT_ID) == 0) - { - // The device object contains 1 child (the storage object). - pEnumeratorContext->m_TotalChildren = 1; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(STORAGE_OBJECT_ID) == 0) - { - // The storage object contains 1 child (the documents folder object). - pEnumeratorContext->m_TotalChildren = 1; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(DOCUMENTS_FOLDER_OBJECT_ID) == 0) - { - // The documents folder object contains 1 child (the readme text file object). - pEnumeratorContext->m_TotalChildren = 1; - } - else if (pEnumeratorContext->m_strParentObjectID.CompareNoCase(README_FILE_OBJECT_ID) == 0) - { - // The readme text file object contains no children. - pEnumeratorContext->m_TotalChildren = 0; - } - else - { - // Invalid, or non-existing objects contain no children. - pEnumeratorContext->m_TotalChildren = 0; - } -} - -HRESULT WpdObjectEnumerator::AddStringValueToPropVariantCollection( - _In_ IPortableDevicePropVariantCollection* pCollection, - _In_ LPCWSTR wszValue) -{ - HRESULT hr = S_OK; - - if ((pCollection == NULL) || - (wszValue == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - - pv.vt = VT_LPWSTR; - pv.pwszVal = (LPWSTR)wszValue; - - // The wszValue will be copied into the collection, keeping the ownership - // of the string belonging to the caller. - // Don't call PropVariantClear, since we did not allocate the memory for these string values - - hr = pCollection->Add(&pv); - - return hr; -} - diff --git a/wpd/WpdMultiTransportDriver/WpdObjectEnum.h b/wpd/WpdMultiTransportDriver/WpdObjectEnum.h deleted file mode 100644 index 8d38526b..00000000 --- a/wpd/WpdMultiTransportDriver/WpdObjectEnum.h +++ /dev/null @@ -1,103 +0,0 @@ -#pragma once - -// This class is used to store the context for a specific enumeration. -class WpdObjectEnumeratorContext : public IUnknown -{ -public: - WpdObjectEnumeratorContext() : - m_cRef(1), - m_TotalChildren(0), - m_ChildrenEnumerated(0) - { - - } - - ~WpdObjectEnumeratorContext() - { - - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -private: - DWORD m_cRef; - -public: - bool HasMoreChildrenToEnumerate() - { - return ((m_TotalChildren - m_ChildrenEnumerated) > 0); - } - -// WpdObjectEnumeratorContext specific data -public: - CAtlStringW m_strParentObjectID; // object identifier of the object whose children are being enumerated - DWORD m_TotalChildren; // number of bytes transferred from the resource to the caller - DWORD m_ChildrenEnumerated; // number of children returned during the enumeration operation -}; - -class WpdObjectEnumerator -{ -public: - WpdObjectEnumerator(); - virtual ~WpdObjectEnumerator(); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnStartFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnFindNext(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnEndFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - VOID InitializeEnumerationContext( - _In_ WpdObjectEnumeratorContext* pEnumeratorContext, - _In_ LPCWSTR wszParentObjectID); - - HRESULT AddStringValueToPropVariantCollection( - _In_ IPortableDevicePropVariantCollection* pCollection, - _In_ LPCWSTR wszValue); -}; diff --git a/wpd/WpdMultiTransportDriver/WpdObjectProperties.cpp b/wpd/WpdMultiTransportDriver/WpdObjectProperties.cpp deleted file mode 100644 index 79dc00b4..00000000 --- a/wpd/WpdMultiTransportDriver/WpdObjectProperties.cpp +++ /dev/null @@ -1,1421 +0,0 @@ -#include "stdafx.h" -#include "WpdObjectProperties.tmh" - -const PROPERTYKEY g_SupportedCommonProperties[] = -{ - WPD_OBJECT_ID, - WPD_OBJECT_PERSISTENT_UNIQUE_ID, - WPD_OBJECT_PARENT_ID, - WPD_OBJECT_NAME, - WPD_OBJECT_FORMAT, - WPD_OBJECT_CONTENT_TYPE, - WPD_OBJECT_CAN_DELETE, -}; - -const PROPERTYKEY g_SupportedDeviceProperties[] = -{ - WPD_DEVICE_FIRMWARE_VERSION, - WPD_DEVICE_POWER_LEVEL, - WPD_DEVICE_POWER_SOURCE, - WPD_DEVICE_PROTOCOL, - WPD_DEVICE_MODEL, - WPD_DEVICE_SERIAL_NUMBER, - WPD_DEVICE_SUPPORTS_NON_CONSUMABLE, - WPD_DEVICE_MANUFACTURER, - WPD_DEVICE_FRIENDLY_NAME, - WPD_DEVICE_TYPE, - WPD_FUNCTIONAL_OBJECT_CATEGORY, -}; - -const PROPERTYKEY g_SupportedStorageProperties[] = -{ - WPD_STORAGE_TYPE, - WPD_STORAGE_FILE_SYSTEM_TYPE, - WPD_STORAGE_CAPACITY, - WPD_STORAGE_FREE_SPACE_IN_BYTES, - WPD_STORAGE_SERIAL_NUMBER, - WPD_STORAGE_DESCRIPTION, - WPD_FUNCTIONAL_OBJECT_CATEGORY, -}; - -const PROPERTYKEY g_SupportedCommonFileProperties[] = -{ - WPD_OBJECT_ORIGINAL_FILE_NAME, - WPD_OBJECT_SIZE, - WPD_OBJECT_DATE_MODIFIED, - WPD_OBJECT_DATE_CREATED, -}; - -const PROPERTYKEY g_SupportedCommonFolderProperties[] = -{ - WPD_OBJECT_ORIGINAL_FILE_NAME, - WPD_OBJECT_DATE_MODIFIED, - WPD_OBJECT_DATE_CREATED, -}; - -WpdObjectProperties::WpdObjectProperties() -{ - -} - -WpdObjectProperties::~WpdObjectProperties() -{ - -} - -HRESULT WpdObjectProperties::DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (Command.fmtid != WPD_CATEGORY_OBJECT_PROPERTIES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED)) - { - hr = OnGetSupportedProperties(pParams, pResults); - CHECK_HR(hr, "Failed to get supported properties"); - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET)) - { - hr = OnGetPropertyValues(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to get properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL)) - { - hr = OnGetAllPropertyValues(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to get all properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_SET)) - { - hr = OnSetPropertyValues(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to set properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES)) - { - hr = OnGetPropertyAttributes(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to get property attributes"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_DELETE)) - { - hr = OnDeleteProperties(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to delete properties"); - } - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose supported properties have - * been requested. - * - * - WPD_PROPERTY_OBJECT_PROPERTIES_FILTER: the filter to use when returning supported properties. - * Since this parameter is optional, it may not exist. - * ! This driver currently ignores the filter parameter. ! - * - * The driver should: - * - Return supported property keys for the specified object in WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS - */ -HRESULT WpdObjectProperties::OnGetSupportedProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose supported properties have been requested - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing string value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // CoCreate a collection to store the supported property keys. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // Add supported property keys for the specified object to the collection - if (hr == S_OK) - { - hr = AddSupportedPropertyKeys(wszObjectID, pKeys); - CHECK_HR(hr, "Failed to add supported property keys for object '%ws'", wszObjectID); - } - - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, pKeys); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values have been requested. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys, identifying which - * specific property values we are requested to return. - * - * The driver should: - * - Return all requested property values in WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES. If any property read failed, the corresponding value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were read successfully. - * - S_FALSE should be returned if any property read failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property values have been requested - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // Get the list of property keys for the property values the caller wants to retrieve from the specified object - if (hr == S_OK) - { - hr = pParams->GetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, &pKeys); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - // CoCreate a collection to store the property values. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Read the specified properties on the specified object and add the property values to the collection. - if (hr == S_OK) - { - hr = GetPropertyValuesForObject(wszObjectID, pKeys, pValues); - CHECK_HR(hr, "Failed to get property values for object '%ws'", wszObjectID); - } - - // S_OK or S_FALSE can be returned from GetPropertyValuesForObject( ). - // S_FALSE means that 1 or more property values could not be retrieved successfully. - // The value for the specified property should be set to an error HRESULT of - // the reason why the property could not be read. - // (e.g. If the property being requested is not supported on the object then an error of - // HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) should be set as the value. - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES value in the results. - HRESULT hrTemp = S_OK; - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, pValues); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values have been requested. - * - * The driver should: - * - Return all property values in WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES. If any property read failed, the corresponding value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were read successfully. - * - S_FALSE should be returned if any property read failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetAllPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property values have been requested - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // CoCreate a collection to store the property values. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the property keys we are going to use - // to request the property values of. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // First we make a request for ALL supported property keys for the specified object. - // Next, we delegate to our helper function GetPropertyValuesForObject( ) passing - // the entire property key collection. This will reuse existing implementation - // in our driver to perform the GetAllPropertyValues operation. - if (hr == S_OK) - { - hr = AddSupportedPropertyKeys(wszObjectID, pKeys); - CHECK_HR(hr, "Failed to get ALL supported properties for object '%ws'", wszObjectID); - if (hr == S_OK) - { - hr = GetPropertyValuesForObject(wszObjectID, pKeys, pValues); - CHECK_HR(hr, "Failed to get property values for object '%ws'", wszObjectID); - } - } - - // S_OK or S_FALSE can be returned from GetPropertyValuesForObject( ). - // S_FALSE means that 1 or more property values could not be retrieved successfully. - // The value for the specified property key should be set to the error HRESULT of - // the reason why the property could not be read. - // (i.e. an error of HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) if a property value was - // requested and is not supported by the specified object.) - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES value in the results - HRESULT hrTemp = S_OK; - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, pValues); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_SET - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values we want to return. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES: an IPortableDeviceValues of values, identifying which - * specific property values we are requested to write. - * - * The driver should: - * - Write all requested property values. For each property, a write result should be returned in the - * write result property store. - * - If any property write failed, the corresponding write result value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were written successfully. - * - S_FALSE should be returned if any property write failed. - * - Any error return indicates that the driver did not write any results, and the caller will - * not attempt to unpack any property write results. - */ -HRESULT WpdObjectProperties::OnSetPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - DWORD cValues = 0; - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceValues> pWriteResults; - CComPtr<IPortableDeviceValues> pEventParams; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property values are being set - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // Get the caller-supplied property values requested to be set on the object - if (hr == S_OK) - { - hr = pParams->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, &pValues); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES"); - } - - // CoCreate a collection to store the property set operation results. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pWriteResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Set the property values on the specified object - if (hr == S_OK) - { - // Since this driver does not support setting any properties, all property set operation - // results will be set to E_ACCESSDENIED. - if (hr == S_OK) - { - hr = pValues->GetCount(&cValues); - CHECK_HR(hr, "Failed to get total number of values"); - } - - if (hr == S_OK) - { - for (DWORD dwIndex = 0; dwIndex < cValues; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - hr = pValues->GetAt(dwIndex, &Key, NULL); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d", dwIndex); - - if (hr == S_OK) - { - hr = pWriteResults->SetErrorValue(Key, E_ACCESSDENIED); - CHECK_HR(hr, "Failed to set error result value at index %d", dwIndex); - } - } - } - - // Since we have set failures for the property set operations we must let the application - // know by returning S_FALSE. This will instruct the application to look at the - // property set operation results for failure values. - if (hr == S_OK) - { - hr = S_FALSE; - } - } - - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_WRITE_RESULTS value in the results - HRESULT hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_WRITE_RESULTS, pWriteResults); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_WRITE_RESULTS")); - - if (FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property attributes we want to return. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys containing a single value, - * which is the key identifying the specific property attributes we are requested to return. - * - * The driver should: - * - Return the requested property attributes. If any property attributes failed to be retrieved, - * the corresponding value should be set to type VT_ERROR with the 'scode' member holding the - * HRESULT reason for the failure. - * - S_OK should be returned if all property attributes were read successfully. - * - S_FALSE should be returned if any property attribute failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - PROPERTYKEY Key = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pAttributes; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property attributes have been requested - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // Get the list of property keys whose attributes are being requested - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, &Key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - // CoCreate a collection to store the property attributes. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Get the attributes for the specified properties on the specified object and add them - // to the collection. - if (hr == S_OK) - { - hr = GetPropertyAttributesForObject(wszObjectID, Key, pAttributes); - CHECK_HR(hr, "Failed to get property attributes"); - } - - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_ATTRIBUTES value in the results - HRESULT hrTemp = S_OK; - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_ATTRIBUTES, pAttributes); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_ATTRIBUTES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_DELETE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose properties should be deleted. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys indicating which - * properties to delete. - * - * The driver should: - * - Delete the specified properties from the object. - * - S_OK should be returned if all specified properties were successfully deleted. - * - E_ACCESSDENIED should be returned if the client attempts to delete a property which is not deletable (i.e. - * WPD_PROPERTY_ATTRIBUTE_CAN_DELETE is FALSE for that property.) - */ -HRESULT WpdObjectProperties::OnDeleteProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = E_ACCESSDENIED; - - UNREFERENCED_PARAMETER(pParams); - UNREFERENCED_PARAMETER(pResults); - - // This driver has no properties which can be deleted. - - return hr; -} - -/** - * This method is called to populate supported PROPERTYKEYs found on objects. - * - * The parameters sent to us are: - * wszObjectID - the object whose supported property keys are being requested - * pKeys - An IPortableDeviceKeyCollection to be populated with supported PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the specified object. - */ -HRESULT AddSupportedPropertyKeys( - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys) -{ - HRESULT hr = S_OK; - CAtlStringW strObjectID = wszObjectID; - - // Add Common PROPERTYKEYs for ALL WPD objects - AddCommonPropertyKeys(pKeys); - - if (strObjectID.CompareNoCase(WPD_DEVICE_OBJECT_ID) == 0) - { - // Add the PROPERTYKEYs for the 'DEVICE' object - AddDevicePropertyKeys(pKeys); - } - - if (strObjectID.CompareNoCase(STORAGE_OBJECT_ID) == 0) - { - // Add the PROPERTYKEYs for the storage object - AddStoragePropertyKeys(pKeys); - } - - if (strObjectID.CompareNoCase(README_FILE_OBJECT_ID) == 0) - { - // Add the PROPERTYKEYs for the file object - AddFilePropertyKeys(pKeys); - } - - if (strObjectID.CompareNoCase(DOCUMENTS_FOLDER_OBJECT_ID) == 0) - { - // Add the PROPERTYKEYs for the folder object - AddFolderPropertyKeys(pKeys); - } - - // Add other PROPERTYKEYs for other supported objects... - - return hr; -} - -/** - * This method is called to populate common PROPERTYKEYs found on ALL objects. - * - * The parameters sent to us are: - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the ALL objects. - */ -VOID AddCommonPropertyKeys( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - if (pKeys != NULL) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedCommonProperties); dwIndex++) - { - HRESULT hr = S_OK; - hr = pKeys->Add(g_SupportedCommonProperties[dwIndex] ); - CHECK_HR(hr, "Failed to add common property"); - } - } -} - -/** - * This method is called to populate common PROPERTYKEYs found on the DEVICE object. - * - * The parameters sent to us are: - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the DEVICE object. - */ -VOID AddDevicePropertyKeys( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - if (pKeys != NULL) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedDeviceProperties); dwIndex++) - { - HRESULT hr = S_OK; - hr = pKeys->Add(g_SupportedDeviceProperties[dwIndex] ); - CHECK_HR(hr, "Failed to add device property"); - } - } -} - -/** - * This method is called to populate common PROPERTYKEYs found on storage objects. - * - * The parameters sent to us are: - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the storage objects. - */ -VOID AddStoragePropertyKeys( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - if (pKeys != NULL) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedStorageProperties); dwIndex++) - { - HRESULT hr = S_OK; - hr = pKeys->Add(g_SupportedStorageProperties[dwIndex] ); - CHECK_HR(hr, "Failed to add storage property"); - } - } -} - -/** - * This method is called to populate common PROPERTYKEYs found on file objects. - * - * The parameters sent to us are: - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the file objects. - */ -VOID AddFilePropertyKeys( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - if (pKeys != NULL) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedCommonFileProperties); dwIndex++) - { - HRESULT hr = S_OK; - hr = pKeys->Add(g_SupportedCommonFileProperties[dwIndex] ); - CHECK_HR(hr, "Failed to add common file property"); - } - } -} - -/** - * This method is called to populate common PROPERTYKEYs found on folder objects. - * - * The parameters sent to us are: - * pKeys - An IPortableDeviceKeyCollection to be populated with PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the file objects. - */ -VOID AddFolderPropertyKeys( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - if (pKeys != NULL) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedCommonFolderProperties); dwIndex++) - { - HRESULT hr = S_OK; - hr = pKeys->Add(g_SupportedCommonFolderProperties[dwIndex] ); - CHECK_HR(hr, "Failed to add common folder property"); - } - } -} - -/** - * This method is called to populate property values for the object specified. - * - * The parameters sent to us are: - * wszObjectID - the object whose properties are being requested. - * pKeys - the list of property keys of the properties to request from the object - * pValues - an IPortableDeviceValues which will contain the property values retreived from the object - * - * The driver should: - * Read the specified properties for the specified object and populate pValues with the - * results. - */ -HRESULT WpdObjectProperties::GetPropertyValuesForObject( - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys, - _In_ IPortableDeviceValues* pValues) -{ - HRESULT hr = S_OK; - CAtlStringW strObjectID = wszObjectID; - DWORD cKeys = 0; - - if ((wszObjectID == NULL) || - (pKeys == NULL) || - (pValues == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - hr = pKeys->GetCount(&cKeys); - CHECK_HR(hr, "Failed to number of PROPERTYKEYs in collection"); - - if (hr == S_OK) - { - // Get values for the DEVICE object - if (strObjectID.CompareNoCase(WPD_DEVICE_OBJECT_ID) == 0) - { - for (DWORD dwIndex = 0; dwIndex < cKeys; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - hr = pKeys->GetAt(dwIndex, &Key); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d in collection", dwIndex); - - if (hr == S_OK) - { - // Preset the property value to 'error not supported'. The actual value - // will replace this value, if read from the device. - pValues->SetErrorValue(Key, HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)); - - // Set DEVICE object properties - if (IsEqualPropertyKey(Key, WPD_DEVICE_FIRMWARE_VERSION)) - { - hr = pValues->SetStringValue(WPD_DEVICE_FIRMWARE_VERSION, DEVICE_FIRMWARE_VERSION_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_FIRMWARE_VERSION"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_POWER_LEVEL)) - { - hr = pValues->SetUnsignedIntegerValue(WPD_DEVICE_POWER_LEVEL, DEVICE_POWER_LEVEL_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_POWER_LEVEL"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_POWER_SOURCE)) - { - hr = pValues->SetUnsignedIntegerValue(WPD_DEVICE_POWER_SOURCE, WPD_POWER_SOURCE_EXTERNAL); - CHECK_HR(hr, "Failed to set WPD_DEVICE_POWER_SOURCE"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_PROTOCOL)) - { - hr = pValues->SetStringValue(WPD_DEVICE_PROTOCOL, DEVICE_PROTOCOL_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_PROTOCOL"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_MODEL)) - { - hr = pValues->SetStringValue(WPD_DEVICE_MODEL, DEVICE_MODEL_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_MODEL"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_SERIAL_NUMBER)) - { - hr = pValues->SetStringValue(WPD_DEVICE_SERIAL_NUMBER, DEVICE_SERIAL_NUMBER_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_SERIAL_NUMBER"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_SUPPORTS_NON_CONSUMABLE)) - { - hr = pValues->SetBoolValue(WPD_DEVICE_SUPPORTS_NON_CONSUMABLE, DEVICE_SUPPORTS_NONCONSUMABLE_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_SUPPORTS_NON_CONSUMABLE"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_MANUFACTURER)) - { - hr = pValues->SetStringValue(WPD_DEVICE_MANUFACTURER, DEVICE_MANUFACTURER_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_MANUFACTURER"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_FRIENDLY_NAME)) - { - hr = pValues->SetStringValue(WPD_DEVICE_FRIENDLY_NAME, DEVICE_FRIENDLY_NAME_VALUE); - CHECK_HR(hr, "Failed to set WPD_DEVICE_FRIENDLY_NAME"); - } - - if (IsEqualPropertyKey(Key, WPD_DEVICE_TYPE)) - { - hr = pValues->SetUnsignedIntegerValue(WPD_DEVICE_TYPE, WPD_DEVICE_TYPE_GENERIC); - CHECK_HR(hr, "Failed to set WPD_DEVICE_TYPE"); - } - - // Set general properties for DEVICE - if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ID, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - hr = pValues->SetStringValue(WPD_OBJECT_NAME, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PARENT_ID, L""); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PARENT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_FORMAT, WPD_OBJECT_FORMAT_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CONTENT_TYPE"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - hr = pValues->SetBoolValue(WPD_OBJECT_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CAN_DELETE"); - } - - if (IsEqualPropertyKey(Key, WPD_FUNCTIONAL_OBJECT_CATEGORY)) - { - hr = pValues->SetGuidValue(WPD_FUNCTIONAL_OBJECT_CATEGORY, WPD_FUNCTIONAL_CATEGORY_DEVICE); - CHECK_HR(hr, "Failed to set WPD_FUNCTIONAL_OBJECT_CATEGORY"); - } - } - } - } - else if (strObjectID.CompareNoCase(STORAGE_OBJECT_ID) == 0) - { - for (DWORD dwIndex = 0; dwIndex < cKeys; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - hr = pKeys->GetAt(dwIndex, &Key); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d in collection", dwIndex); - - if (hr == S_OK) - { - // Preset the property value to 'error not supported'. The actual value - // will replace this value, if read from the device. - pValues->SetErrorValue(Key, HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)); - - // Set storage object properties - if (IsEqualPropertyKey(Key, WPD_STORAGE_SERIAL_NUMBER)) - { - hr = pValues->SetStringValue(WPD_STORAGE_SERIAL_NUMBER, STORAGE_SERIAL_NUMBER_VALUE); - CHECK_HR(hr, "Failed to set WPD_STORAGE_SERIAL_NUMBER"); - } - - if (IsEqualPropertyKey(Key, WPD_STORAGE_FREE_SPACE_IN_BYTES)) - { - hr = pValues->SetUnsignedLargeIntegerValue(WPD_STORAGE_FREE_SPACE_IN_BYTES, (STORAGE_FREE_SPACE_IN_BYTES_VALUE - GetObjectSize(README_FILE_OBJECT_ID))); - CHECK_HR(hr, "Failed to set WPD_STORAGE_FREE_SPACE_IN_BYTES"); - } - - if (IsEqualPropertyKey(Key, WPD_STORAGE_CAPACITY)) - { - hr = pValues->SetUnsignedLargeIntegerValue(WPD_STORAGE_CAPACITY, STORAGE_CAPACITY_VALUE); - CHECK_HR(hr, "Failed to set WPD_STORAGE_CAPACITY"); - } - - if (IsEqualPropertyKey(Key, WPD_STORAGE_TYPE)) - { - hr = pValues->SetUnsignedIntegerValue(WPD_STORAGE_TYPE, WPD_STORAGE_TYPE_FIXED_ROM); - CHECK_HR(hr, "Failed to set WPD_STORAGE_TYPE"); - } - - // Set general properties for storage - if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ID, STORAGE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - hr = pValues->SetStringValue(WPD_OBJECT_NAME, STORAGE_OBJECT_NAME_VALUE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, STORAGE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PARENT_ID, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PARENT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_FORMAT, WPD_OBJECT_FORMAT_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CONTENT_TYPE"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - hr = pValues->SetBoolValue(WPD_OBJECT_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CAN_DELETE"); - } - - if (IsEqualPropertyKey(Key, WPD_FUNCTIONAL_OBJECT_CATEGORY)) - { - hr = pValues->SetGuidValue(WPD_FUNCTIONAL_OBJECT_CATEGORY, WPD_FUNCTIONAL_CATEGORY_STORAGE); - CHECK_HR(hr, "Failed to set WPD_FUNCTIONAL_OBJECT_CATEGORY"); - } - - if (IsEqualPropertyKey(Key, WPD_STORAGE_FILE_SYSTEM_TYPE)) - { - hr = pValues->SetStringValue(WPD_STORAGE_FILE_SYSTEM_TYPE, STORAGE_FILE_SYSTEM_TYPE_VALUE); - CHECK_HR(hr, "Failed to set WPD_STORAGE_FILE_SYSTEM_TYPE"); - } - - if (IsEqualPropertyKey(Key, WPD_STORAGE_DESCRIPTION)) - { - hr = pValues->SetStringValue(WPD_STORAGE_DESCRIPTION, STORAGE_DESCRIPTION_VALUE); - CHECK_HR(hr, "Failed to set WPD_STORAGE_DESCRIPTION"); - } - } - } - } - else if (strObjectID.CompareNoCase(DOCUMENTS_FOLDER_OBJECT_ID) == 0) - { - for (DWORD dwIndex = 0; dwIndex < cKeys; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - hr = pKeys->GetAt(dwIndex, &Key); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d in collection", dwIndex); - - if (hr == S_OK) - { - // Preset the property value to 'error not supported'. The actual value - // will replace this value, if read from the device. - pValues->SetErrorValue(Key, HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)); - - // Set general properties for the folder object - if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ID, DOCUMENTS_FOLDER_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, DOCUMENTS_FOLDER_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PARENT_ID, STORAGE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PARENT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - hr = pValues->SetStringValue(WPD_OBJECT_NAME, DOCUMENTS_FOLDER_OBJECT_NAME_VALUE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_ORIGINAL_FILE_NAME)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, DOCUMENTS_FOLDER_OBJECT_ORIGINAL_FILE_NAME_VALUE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_FORMAT, WPD_OBJECT_FORMAT_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, WPD_CONTENT_TYPE_FOLDER); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CONTENT_TYPE"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - hr = pValues->SetBoolValue(WPD_OBJECT_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CAN_DELETE"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_DATE_MODIFIED)) - { - PROPVARIANT pvDateModified = {0}; - SYSTEMTIME systemtime = {0}; - - systemtime.wMonth = 6; - systemtime.wDay = 26; - systemtime.wYear = 2006; - systemtime.wHour = 5; - - // Initialize the Date Modified PROPVARIANT value - PropVariantInit(&pvDateModified); - - pvDateModified.vt = VT_DATE; - if (SystemTimeToVariantTime(&systemtime, &pvDateModified.date) == TRUE) - { - hr = pValues->SetValue(WPD_OBJECT_DATE_MODIFIED, &pvDateModified); - CHECK_HR(hr, "Failed to set WPD_OBJECT_DATE_MODIFIED"); - } - else - { - LONG lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - - PropVariantClear(&pvDateModified); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_DATE_CREATED)) - { - PROPVARIANT pvDateCreated = {0}; - SYSTEMTIME systemtime = {0}; - - systemtime.wMonth = 1; - systemtime.wDay = 24; - systemtime.wYear = 2006; - systemtime.wHour = 12; - - // Initialize the Date Created PROPVARIANT value - PropVariantInit(&pvDateCreated); - - pvDateCreated.vt = VT_DATE; - if (SystemTimeToVariantTime(&systemtime, &pvDateCreated.date) == TRUE) - { - hr = pValues->SetValue(WPD_OBJECT_DATE_CREATED, &pvDateCreated); - CHECK_HR(hr, "Failed to set WPD_OBJECT_DATE_CREATED"); - } - else - { - LONG lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - - PropVariantClear(&pvDateCreated); - } - } - } - } - else if (strObjectID.CompareNoCase(README_FILE_OBJECT_ID) == 0) - { - for (DWORD dwIndex = 0; dwIndex < cKeys; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - hr = pKeys->GetAt(dwIndex, &Key); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d in collection", dwIndex); - - if (hr == S_OK) - { - // Preset the property value to 'error not supported'. The actual value - // will replace this value, if read from the device. - pValues->SetErrorValue(Key, HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)); - - if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ID, README_FILE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, README_FILE_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - hr = pValues->SetStringValue(WPD_OBJECT_PARENT_ID, DOCUMENTS_FOLDER_OBJECT_ID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PARENT_ID"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - hr = pValues->SetStringValue(WPD_OBJECT_NAME, README_FILE_OBJECT_NAME_VALUE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_ORIGINAL_FILE_NAME)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, README_FILE_OBJECT_ORIGINAL_FILE_NAME_VALUE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_FORMAT, GetObjectFormat(strObjectID)); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - hr = pValues->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, GetObjectContentType(strObjectID)); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CONTENT_TYPE"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - hr = pValues->SetBoolValue(WPD_OBJECT_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CAN_DELETE"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_SIZE)) - { - hr = pValues->SetUnsignedLargeIntegerValue(WPD_OBJECT_SIZE, GetObjectSize(strObjectID)); - CHECK_HR(hr, "Failed to set WPD_OBJECT_SIZE"); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_DATE_MODIFIED)) - { - PROPVARIANT pvDateModified = {0}; - SYSTEMTIME systemtime = {0}; - - systemtime.wMonth = 6; - systemtime.wDay = 26; - systemtime.wYear = 2006; - systemtime.wHour = 5; - - // Initialize the Date Modified PROPVARIANT value - PropVariantInit(&pvDateModified); - - pvDateModified.vt = VT_DATE; - if (SystemTimeToVariantTime(&systemtime, &pvDateModified.date) == TRUE) - { - hr = pValues->SetValue(WPD_OBJECT_DATE_MODIFIED, &pvDateModified); - CHECK_HR(hr, "Failed to set WPD_OBJECT_DATE_MODIFIED"); - } - else - { - LONG lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - - PropVariantClear(&pvDateModified); - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_DATE_CREATED)) - { - PROPVARIANT pvDateCreated = {0}; - SYSTEMTIME systemtime = {0}; - - systemtime.wMonth = 1; - systemtime.wDay = 24; - systemtime.wYear = 2006; - systemtime.wHour = 12; - - // Initialize the Date Created PROPVARIANT value - PropVariantInit(&pvDateCreated); - - pvDateCreated.vt = VT_DATE; - if (SystemTimeToVariantTime(&systemtime, &pvDateCreated.date) == TRUE) - { - hr = pValues->SetValue(WPD_OBJECT_DATE_CREATED, &pvDateCreated); - CHECK_HR(hr, "Failed to set WPD_OBJECT_DATE_CREATED"); - } - else - { - LONG lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - - PropVariantClear(&pvDateCreated); - } - } - } - } - } - - return hr; -} - -/** - * This method is called to populate property attributes for the object and property specified. - * - * The parameters sent to us are: - * wszObjectID - the object whose property attributes are being requested. - * Key - the property whose attributes are being requested - * pAttributes - an IPortableDeviceValues which will contain the resulting property attributes - * - * The driver should: - * Read the property attributes for the specified property on the specified object and - * populate pAttributes with the results. - */ -HRESULT WpdObjectProperties::GetPropertyAttributesForObject( - _In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if ((wszObjectID == NULL) || - (pAttributes == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - UNREFERENCED_PARAMETER(wszObjectID); - UNREFERENCED_PARAMETER(Key); - - // - // Since ALL of our properties have the same attributes, we are ignoring the - // passed in wszObjectID and Key parameters. These parameters allow you to - // customize attributes for properties on specific objects. (i.e. WPD_OBJECT_ORIGINAL_FILE_NAME - // may be READ/WRITE on some objects and READONLY on others. ) - // - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_DELETE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_READ"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_WRITE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_WRITE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_FORM, WPD_PROPERTY_ATTRIBUTE_FORM_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FORM"); - } - - return hr; -} - -/** - * This method is called to return the total size of the specified object - * - * The parameters sent to us are: - * strObjectID - the object whose total size is being requested. - * - * The driver should: - * Calculate or read the total size of the object and return it to the caller. - */ -ULONGLONG GetObjectSize(_In_ LPCWSTR wszObjectID) -{ - ULONGLONG FileObjectSize = 0; - - if (_wcsicmp(wszObjectID, README_FILE_OBJECT_ID) == 0) - { - size_t cbFileObjectContents = 0; - if (SUCCEEDED(StringCbLengthA(README_FILE_OBJECT_CONTENTS, STRSAFE_MAX_CCH*sizeof(CHAR), &cbFileObjectContents))) - { - // StringCbLength() returns the size of the string excluding the null terminator, - // so we will account for it in our size calculation. - FileObjectSize = cbFileObjectContents + sizeof(CHAR); - } - } - - return FileObjectSize; -} - -/** - * This method is called to return the WPD format of the specified object - * - * The parameters sent to us are: - * strObjectID - the object whose WPD format is being requested. - * - * The driver should: - * Read the native format of the object and return a WPD format to the caller. - */ -GUID GetObjectFormat(_In_ LPCWSTR wszObjectID) -{ - GUID FileObjectFormat = WPD_OBJECT_FORMAT_UNSPECIFIED; - - if (_wcsicmp(wszObjectID, README_FILE_OBJECT_ID) == 0) - { - FileObjectFormat = WPD_OBJECT_FORMAT_TEXT; - } - - return FileObjectFormat; -} - -/** - * This method is called to return the WPD content type of the specified object - * - * The parameters sent to us are: - * strObjectID - the object whose WPD content type is being requested. - * - * The driver should: - * Read the native content type of the object and return a WPD content type to the caller. - */ -GUID GetObjectContentType(_In_ LPCWSTR wszObjectID) -{ - GUID FileObjectFormat = WPD_CONTENT_TYPE_UNSPECIFIED; - - if (_wcsicmp(wszObjectID, README_FILE_OBJECT_ID) == 0) - { - FileObjectFormat = WPD_CONTENT_TYPE_DOCUMENT; - } - - return FileObjectFormat; -} diff --git a/wpd/WpdMultiTransportDriver/WpdObjectProperties.h b/wpd/WpdMultiTransportDriver/WpdObjectProperties.h deleted file mode 100644 index d76be32d..00000000 --- a/wpd/WpdMultiTransportDriver/WpdObjectProperties.h +++ /dev/null @@ -1,79 +0,0 @@ -#pragma once - -#define DEVICE_PROTOCOL_VALUE L"Multi-Transport Protocol ver 1.00" -#define DEVICE_FIRMWARE_VERSION_VALUE L"1.0.0.0" -#define DEVICE_POWER_LEVEL_VALUE 100 -#define DEVICE_MODEL_VALUE L"Multi-Transport" -#define DEVICE_FRIENDLY_NAME_VALUE L"Multi-Transport Hello World!" -#define DEVICE_MANUFACTURER_VALUE L"Windows Portable Devices Group" -#define DEVICE_SERIAL_NUMBER_VALUE L"01234567890123-45676890123456" -#define DEVICE_SUPPORTS_NONCONSUMABLE_VALUE TRUE - -#define STORAGE_OBJECT_ID L"123ABC" -#define STORAGE_CAPACITY_VALUE 1024 * 1024 -#define STORAGE_FREE_SPACE_IN_BYTES_VALUE STORAGE_CAPACITY_VALUE -#define STORAGE_SERIAL_NUMBER_VALUE L"98765432109876-54321098765432" -#define STORAGE_OBJECT_NAME_VALUE L"Internal Memory" -#define STORAGE_FILE_SYSTEM_TYPE_VALUE L"FAT32" -#define STORAGE_DESCRIPTION_VALUE L"Hello World! Memory Storage System" - -#define DOCUMENTS_FOLDER_OBJECT_ID L"XYZ456" -#define DOCUMENTS_FOLDER_OBJECT_NAME_VALUE L"Documents Folder" -#define DOCUMENTS_FOLDER_OBJECT_ORIGINAL_FILE_NAME_VALUE L"Documents" - -#define README_FILE_OBJECT_ID L"6543210" -#define README_FILE_OBJECT_NAME_VALUE L"Sample ReadMe Text File" -#define README_FILE_OBJECT_ORIGINAL_FILE_NAME_VALUE L"ReadMe.txt" -#define README_FILE_OBJECT_CONTENTS "Hello World!\r\nThis is a text file transferred from the WPD Multi-Transport Hello World sample driver.\r\n" - -ULONGLONG GetObjectSize(_In_ LPCWSTR strObjectID); -GUID GetObjectFormat(_In_ LPCWSTR strObjectID); -GUID GetObjectContentType(_In_ LPCWSTR strObjectID); -HRESULT AddSupportedPropertyKeys(_In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys); - -VOID AddCommonPropertyKeys(_In_ IPortableDeviceKeyCollection* pKeys); -VOID AddDevicePropertyKeys(_In_ IPortableDeviceKeyCollection* pKeys); -VOID AddStoragePropertyKeys(_In_ IPortableDeviceKeyCollection* pKeys); -VOID AddFilePropertyKeys(_In_ IPortableDeviceKeyCollection* pKeys); -VOID AddFolderPropertyKeys(_In_ IPortableDeviceKeyCollection* pKeys); - -class WpdObjectProperties -{ -public: - WpdObjectProperties(); - virtual ~WpdObjectProperties(); - - HRESULT Initialize(); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedProperties(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetPropertyValues(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetAllPropertyValues(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnSetPropertyValues(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetPropertyAttributes(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnDeleteProperties(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - HRESULT GetPropertyValuesForObject(_In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys, - _In_ IPortableDeviceValues* pValues); - - HRESULT GetPropertyAttributesForObject(_In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes); -}; diff --git a/wpd/WpdMultiTransportDriver/WpdObjectResources.cpp b/wpd/WpdMultiTransportDriver/WpdObjectResources.cpp deleted file mode 100644 index 456af6dc..00000000 --- a/wpd/WpdMultiTransportDriver/WpdObjectResources.cpp +++ /dev/null @@ -1,674 +0,0 @@ -#include "stdafx.h" -#include "WpdObjectResources.tmh" - -WpdObjectResources::WpdObjectResources() -{ - -} - -WpdObjectResources::~WpdObjectResources() -{ - -} - -HRESULT WpdObjectResources::DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (Command.fmtid != WPD_CATEGORY_OBJECT_RESOURCES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_GET_SUPPORTED)) - { - hr = OnGetSupportedResources(pParams, pResults); - CHECK_HR(hr, "Failed to get supported resources"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_OPEN)) - { - hr = OnOpenResource(pParams, pResults); - CHECK_HR(hr, "Failed to open resource"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_READ)) - { - hr = OnReadResource(pParams, pResults); - CHECK_HR(hr, "Failed to read resource"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_CLOSE)) - { - hr = OnCloseResource(pParams, pResults); - CHECK_HR(hr, "Failed to close resource"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_GET_ATTRIBUTES)) - { - hr = OnGetResourceAttributes(pParams, pResults); - CHECK_HR(hr, "Failed to get resource attributes"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_GET_SUPPORTED - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID: identifies the object whose resources we want to return. - * - * The driver should: - * - Return all resources for this object in WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS. - */ -HRESULT WpdObjectResources::OnGetSupportedResources( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // Get the Object ID - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID, &wszObjectID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID"); - } - - // Create the collection to hold the resource keys - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - if (hr == S_OK) - { - hr = GetSupportedResourcesForObject(wszObjectID, pKeys); - CHECK_HR(hr, "Failed to get supported resources for object '%ws'", wszObjectID); - } - - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS, pKeys); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_GET_ATTRIBUTES - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID: identifies the object whose resource attributes we want to return. - * - WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS: a collection of property keys containing a single value, - * which is the key identifying the specific resource we are requested to return attributes for. - * - * The driver should: - * - Return the requested property attributes in WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_ATTRIBUTES. - * If any resource attributes failed to be retrieved, - * the corresponding value should be set to type VT_ERROR with the 'scode' member holding the - * HRESULT reason for the failure. - * - S_OK should be returned if all resource attributes were read successfully. - * - S_FALSE should be returned if any resource attribute failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - * - */ -HRESULT WpdObjectResources::OnGetResourceAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - PROPERTYKEY Key = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pAttributes; - - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID"); - } - - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS, &Key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = GetResourceAttributesForObject(wszObjectID, Key, pAttributes); - CHECK_HR(hr, "Failed to get resource attributes"); - } - - if (SUCCEEDED(hr)) - { - HRESULT hrTemp = S_OK; - - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_ATTRIBUTES, pAttributes); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_ATTRIBUTES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_OPEN - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID: the object identifier of the - * object which contains the specified resource - * - * - WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS: the specified resource - * to open - * - * - WPD_PROPERTY_OBJECT_RESOURCES_ACCESS_MODE: the access mode to which to - * open the specified resource - * - * The driver should: - * - Create a new context for this resource operation. - * - Return an identifier for the context in WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT. - * - Set the optimal transfer size in WPD_PROPERTY_OBJECT_RESOURCES_OPTIMAL_TRANSFER_BUFFER_SIZE - * - */ -HRESULT WpdObjectResources::OnOpenResource( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - PROPERTYKEY Key = WPD_PROPERTY_NULL; - DWORD dwMode = STGM_READ; - CAtlStringW strStrObjectID; - CAtlStringW strResourceContext; - ContextMap* pContextMap = NULL; - - // Get the Object identifier of the object which contains the specified resource - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID, &wszObjectID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID"); - } - - // Get the resource key - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS, &Key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS"); - } - - // Get the access mode - if (hr == S_OK) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_ACCESS_MODE, &dwMode); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_ACCESS_MODE"); - } - - // Validate whether the params given to us are correct. In this case, we need to check that the object - // supports the resource requested, and can be opened in the requested access mode. - if (hr == S_OK) - { - // In this sample, we only have one object (README_FILE_OBJECT_ID) which supports a - // resource (WPD_RESOURCE_DEFAULT) for reading only. - // So if any other Object ID or any other resource is specified, it must be invalid. - strStrObjectID = wszObjectID; - if(strStrObjectID.CompareNoCase(README_FILE_OBJECT_ID) != 0) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Object [%ws] does not support resources", wszObjectID); - } - if (hr == S_OK) - { - if (!IsEqualPropertyKey(Key, WPD_RESOURCE_DEFAULT)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Only WPD_RESOURCE_DEFAULT is supported in this sample driver"); - } - } - if (hr == S_OK) - { - if ((dwMode & STGM_WRITE) != 0) - { - hr = E_ACCESSDENIED; - CHECK_HR(hr, "This resource is not available for write access"); - } - } - } - - // Get the context map which the driver stored in pParams for convenience - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Create a new resource operation context, initialize it, and add it to the client context map. - if (hr == S_OK) - { - WpdObjectResourceContext* pResourceContext = new WpdObjectResourceContext(); - if (pResourceContext != NULL) - { - // Initialize the resource context with ... - pResourceContext->m_strObjectID = wszObjectID; - pResourceContext->m_Resource = Key; - pResourceContext->m_BytesTransferred = 0; - pResourceContext->m_BytesTotal = GetObjectSize(wszObjectID); - - // Add the resource context to the context map - pContextMap->Add(pResourceContext, strResourceContext); - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate resource context"); - } - SAFE_RELEASE(pResourceContext); - } - - if (hr == S_OK) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, strResourceContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Set the optimal buffer size - if (hr == S_OK) - { - hr = pResults->SetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_OPTIMAL_TRANSFER_BUFFER_SIZE, FILE_OPTIMAL_READ_BUFFER_SIZE_VALUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_OPTIMAL_TRANSFER_BUFFER_SIZE value"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_READ - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT: the context the driver returned to - * the client in OnOpenResource. - * - WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ: the number of bytes to - * read from the resource. - * - * The driver should: - * - Read data associated with the resource and return it back to the caller in - * WPD_PROPERTY_OBJECT_RESOURCES_DATA. - * - Report the number of bytes actually read from the resource in - * WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_READ. This number may be smaller - * than WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ when reading the last - * chunk of data from the resource. - */ -HRESULT WpdObjectResources::OnReadResource( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszResourceContext = NULL; - DWORD dwNumBytesToRead = 0; - DWORD dwNumBytesRead = 0; - BYTE* pBuffer = NULL; - WpdObjectResourceContext* pResourceContext = NULL; - ContextMap* pContextMap = NULL; - - // Get the enumeration context identifier for this enumeration operation. We will - // need this to lookup the specific enumeration context in the client context map. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, &wszResourceContext); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Get the number of bytes to read - if (hr == S_OK) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ, &dwNumBytesToRead); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ"); - } - - // Allocate the destination buffer - if (hr == S_OK) - { - pBuffer = reinterpret_cast<BYTE *>(CoTaskMemAlloc(dwNumBytesToRead)); - if (pBuffer == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate the destination buffer"); - } - } - - // Get the client context map so we can retrieve the resource context for this resource - // operation using the WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT property value obtained above. - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (hr == S_OK) - { - pResourceContext = (WpdObjectResourceContext*)pContextMap->GetContext(wszResourceContext); - if (pResourceContext == NULL) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing resource context"); - } - } - - // Read the next chunk of data for this request - if (hr == S_OK && pBuffer != NULL) - { - hr = ReadDataFromResource(pResourceContext, pBuffer, dwNumBytesToRead, &dwNumBytesRead); - CHECK_HR(hr, "Failed to read %d bytes from resource", dwNumBytesToRead); - } - - if (hr == S_OK && pBuffer != NULL) - { - hr = pResults->SetBufferValue(WPD_PROPERTY_OBJECT_RESOURCES_DATA, pBuffer, dwNumBytesRead); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_DATA"); - } - - if (hr == S_OK) - { - hr = pResults->SetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_READ, dwNumBytesRead); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_READ"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszResourceContext); - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pBuffer); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_CLOSE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT: the context the driver returned to - * the client in OnOpenResource. - * - * The driver should: - * - Destroy any data associated with this context. - */ -HRESULT WpdObjectResources::OnCloseResource( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszResourceContext = NULL; - ContextMap* pContextMap = NULL; - - UNREFERENCED_PARAMETER(pResults); - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the resource context identifier for this resource operation. We will - // need this to lookup the specific resource context in the client context map. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, &wszResourceContext); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Get the client context map so we can retrieve the resource context for this resource - // operation using the WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT property value obtained above. - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Destroy any data allocated/associated with the resource context and then remove it from the context map. - // We no longer need to keep this context around because the resource operation has been ended. - if (hr == S_OK) - { - pContextMap->Remove(wszResourceContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszResourceContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called to populate PROPERTYKEYs found on objects. - * - * The parameters sent to us are: - * wszObjectID - the object whose supported resource keys are being requested - * pKeys - An IPortableDeviceKeyCollection to be populated with supported PROPERTYKEYs - * - * The driver should: - * Add PROPERTYKEYs pertaining to the specified object. - */ -HRESULT WpdObjectResources::GetSupportedResourcesForObject( - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys) -{ - HRESULT hr = S_OK; - CAtlStringW strObjectID; - - if ((wszObjectID == NULL) || - (pKeys == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - strObjectID = wszObjectID; - - if (strObjectID.CompareNoCase(README_FILE_OBJECT_ID) == 0) - { - hr = pKeys->Add(WPD_RESOURCE_DEFAULT); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_DEFAULT"); - } - - return hr; -} - -/** - * This method is called to populate resource attributes found on a particular object - * resource. - * - * The parameters sent to us are: - * wszObjectID - the object whose resource attributes are being requested - * Key - the resource on the specified object whose attributes are being returned - * pAttributes - An IPortableDeviceValues to be populated with resource attributes. - * - * The driver should: - * Add attributes pertaining to the resource on the specified object. - */ -HRESULT WpdObjectResources::GetResourceAttributesForObject( - _In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - CAtlStringW strObjectID; - - if ((wszObjectID == NULL) || - (pAttributes == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - strObjectID = wszObjectID; - - if ((strObjectID.CompareNoCase(README_FILE_OBJECT_ID) == 0) && (IsEqualPropertyKey(Key, WPD_RESOURCE_DEFAULT))) - { - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_DELETE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedLargeIntegerValue(WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE, GetObjectSize(strObjectID)); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_READ"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_WRITE, FALSE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_WRITE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_DELETE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetGuidValue(WPD_RESOURCE_ATTRIBUTE_FORMAT, GetObjectFormat(strObjectID)); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_FORMAT"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_OPTIMAL_READ_BUFFER_SIZE, FILE_OPTIMAL_READ_BUFFER_SIZE_VALUE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_OPTIMAL_READ_BUFFER_SIZE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_OPTIMAL_WRITE_BUFFER_SIZE, FILE_OPTIMAL_WRITE_BUFFER_SIZE_VALUE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_OPTIMAL_WRITE_BUFFER_SIZE"); - } - } - - return hr; -} - -/** - * This method is called to read data from a particular object - * resource. - * - * The parameters sent to us are: - * pResourceContext - the resource operation context - * pBuffer - the buffer to read the resource data into - * dwNumBytesToRead - number of bytes to read into the resource. This is also - * the total size of the passed in pBuffer. - * pdwNumBytesRead - On return, should contain the actual number of bytes read into pBuffer - * - * The driver should: - * - Read data from the specified resource - * - Update the resource operation context with transfer state information - * - Return the actual number of bytes written in pdwNumBytesRead. - */ -HRESULT WpdObjectResources::ReadDataFromResource( - _In_ WpdObjectResourceContext* pResourceContext, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) -{ - HRESULT hr = S_OK; - - if ((pResourceContext == NULL) || - (pBuffer == NULL) || - (pdwNumBytesRead == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - *pdwNumBytesRead = 0; - ZeroMemory(pBuffer, dwNumBytesToRead * sizeof(BYTE)); - - // If we have data left to transfer, then transfer up to dwNumBytesToRead - // if possible. - if (pResourceContext->m_BytesTotal >= pResourceContext->m_BytesTransferred) - { - dwNumBytesToRead = (DWORD)min((ULONGLONG)dwNumBytesToRead,(pResourceContext->m_BytesTotal - pResourceContext->m_BytesTransferred)); - } - - // Read the data from the resource - if (dwNumBytesToRead > 0) - { - // If we are reading from our single file resource, make sure you read - // from the proper source data contents. - if (pResourceContext->m_strObjectID.CompareNoCase(README_FILE_OBJECT_ID) == 0) - { - hr = StringCbCopyA((LPSTR)pBuffer, dwNumBytesToRead, README_FILE_OBJECT_CONTENTS); - CHECK_HR(hr, "StringCbCopyA failed, dwNumBytesToRead = %ld", dwNumBytesToRead); - } - } - - if (SUCCEEDED(hr)) - { - // update the number of bytes transferred in the resource context - pResourceContext->m_BytesTransferred += dwNumBytesToRead; - - // set the number of bytes actually read into to pBuffer - *pdwNumBytesRead = dwNumBytesToRead; - } - - return hr; -} diff --git a/wpd/WpdMultiTransportDriver/WpdObjectResources.h b/wpd/WpdMultiTransportDriver/WpdObjectResources.h deleted file mode 100644 index e9d4fb63..00000000 --- a/wpd/WpdMultiTransportDriver/WpdObjectResources.h +++ /dev/null @@ -1,111 +0,0 @@ -#pragma once - -#define FILE_OPTIMAL_READ_BUFFER_SIZE_VALUE (2 * 1024 * 1024) -#define FILE_OPTIMAL_WRITE_BUFFER_SIZE_VALUE (2 * 1024 * 1024) - -// This class is used to store the context for a specific resource operation. -class WpdObjectResourceContext : public IUnknown -{ -public: - WpdObjectResourceContext() : - m_cRef(1), - m_Resource(WPD_RESOURCE_DEFAULT), - m_BytesTransferred(0), - m_BytesTotal(0) - { - - } - - ~WpdObjectResourceContext() - { - - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -private: - DWORD m_cRef; - -// WpdObjectResourceContext specific data -public: - CAtlStringW m_strObjectID; // object identifier of the object whose resource is being transferred - PROPERTYKEY m_Resource; // the specific resource being transferred - ULONGLONG m_BytesTransferred; // number of bytes transferred from the resource to the caller - ULONGLONG m_BytesTotal; // total number of bytes of the resource data -}; - -class WpdObjectResources -{ -public: - WpdObjectResources(); - virtual ~WpdObjectResources(); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedResources(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetResourceAttributes(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnOpenResource(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnReadResource(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnCloseResource(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); -private: - HRESULT GetSupportedResourcesForObject(_In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys); - - HRESULT GetResourceAttributesForObject(_In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes); - - HRESULT ReadDataFromResource(_In_ WpdObjectResourceContext* pResourceContext, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead); -}; diff --git a/wpd/WpdMultiTransportDriver/resource.h b/wpd/WpdMultiTransportDriver/resource.h deleted file mode 100644 index d59fe80e..00000000 --- a/wpd/WpdMultiTransportDriver/resource.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -#define IDR_WpdMultiTransportDriver 101 - diff --git a/wpd/WpdMultiTransportDriver/stdafx.h b/wpd/WpdMultiTransportDriver/stdafx.h deleted file mode 100644 index 67b8525b..00000000 --- a/wpd/WpdMultiTransportDriver/stdafx.h +++ /dev/null @@ -1,266 +0,0 @@ -#pragma once - -#include "resource.h" -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#define STRSAFE_NO_DEPRECATE - -#include <stdio.h> -#include <tchar.h> -#include <strsafe.h> - -#include <atlbase.h> -#include <atlcom.h> -#include <atlcoll.h> -#include <atlstr.h> - -#ifndef SAFE_RELEASE - #define SAFE_RELEASE(p) if( NULL != p ) { ( p )->Release(); p = NULL; } -#endif - -#include "WpdMultiTransportDriver.h" -#include "PortableDeviceTypes.h" -#include "PortableDeviceClassExtension.h" -#include "PortableDevice.h" - -#include <initguid.h> -#include <propkeydef.h> - -// {CDD18979-A7B0-4D5E-9EB2-0A826805CBBD} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT, 0xCDD18979, 0xA7B0, 0x4D5E, 0x9E, 0xB2, 0x0A, 0x82, 0x68, 0x05, 0xCB, 0xBD, 2); -// {9BD949E5-59CF-41AE-90A9-BE1D044F578F} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT, 0x9BD949E5, 0x59CF, 0x41AE, 0x90, 0xA9, 0xBE, 0x1D, 0x04, 0x4F, 0x57, 0x8F, 2); -// {4DF6C8C7-2CE5-457C-9F53-EFCECAA95C04} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, 0x4DF6C8C7, 0x2CE5, 0x457C, 0x9F, 0x53, 0xEF, 0xCE, 0xCA, 0xA9, 0x5C, 0x04, 2); - -class ContextMap : public IUnknown -{ -public: - ContextMap() : - m_cRef(1) - { - - } - - ~ContextMap() - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - - IUnknown* pUnk = NULL; - POSITION elementPosition = NULL; - - elementPosition = m_Map.GetStartPosition(); - while(elementPosition != NULL) - { - pUnk = m_Map.GetNextValue(elementPosition); - if(pUnk != NULL) - { - pUnk->Release(); - } - } - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - return hr; - } - - -public: // Context accessor methods - - // If successful, this method AddRef's the context and returns - // a context key - HRESULT Add( - _In_ IUnknown* pContext, - _Out_ CAtlStringW& key) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - HRESULT hr = S_OK; - GUID guidContext = GUID_NULL; - CComBSTR bstrContext; - - key = L""; - - // Create a unique context key - hr = CoCreateGuid(&guidContext); - if (hr == S_OK) - { - bstrContext = guidContext; - if(bstrContext.Length() > 0) - { - key = bstrContext; - } - else - { - hr = E_OUTOFMEMORY; - } - } - - if (hr == S_OK) - { - // Insert this into the map - POSITION elementPosition = m_Map.SetAt(key, pContext); - if(elementPosition != NULL) - { - // AddRef since we are holding onto it - pContext->AddRef(); - } - else - { - hr = E_OUTOFMEMORY; - } - } - return hr; - } - - void Remove( - _In_ const CAtlStringW& key) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - // Get the element - IUnknown* pContext = NULL; - - if (m_Map.Lookup(key, pContext) == true) - { - // Remove the entry for it - m_Map.RemoveKey(key); - - // Release it - pContext->Release(); - } - } - - // Returns the context pointer. If not found, return value is NULL. - // If non-NULL, caller is responsible for Releasing when it is done, - // since this method will AddRef the context. - IUnknown* GetContext( - _In_ const CAtlStringW& key) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - // Get the element - IUnknown* pContext = NULL; - - if (m_Map.Lookup(key, pContext) == true) - { - // AddRef - pContext->AddRef(); - } - return pContext; - } - -private: - CComAutoCriticalSection m_CriticalSection; - CAtlMap<CAtlStringW, IUnknown*> m_Map; - DWORD m_cRef; -}; - -HRESULT UpdateDeviceFriendlyName( - _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension, - _In_ PCWSTR wszDeviceFriendlyName); - -#include "WpdObjectEnum.h" -#include "WpdObjectProperties.h" -#include "WpdObjectResources.h" -#include "WpdCapabilities.h" -#include "WpdBaseDriver.h" - -extern HINSTANCE g_hInstance; - -// -// Driver specific tracing #defines -// -// TODO: Change these values to be appropriate for your driver. -// -#define MYDRIVER_TRACING_ID L"Microsoft\\WPD\\MultiTransportDriver" - -// -// TODO: Choose a different trace control GUID -// -#define WPP_CONTROL_GUIDS \ - WPP_DEFINE_CONTROL_GUID(MultiTransportDriverCtlGuid,(300fbd95,366b,4d6a,b4d1,c426603ca2e6), \ - WPP_DEFINE_BIT(TRACE_FLAG_ALL) \ - WPP_DEFINE_BIT(TRACE_FLAG_DEVICE) \ - WPP_DEFINE_BIT(TRACE_FLAG_DRIVER) \ - WPP_DEFINE_BIT(TRACE_FLAG_QUEUE) \ - ) - -#define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) \ - WPP_LEVEL_LOGGER(flags) - -#define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) \ - (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= lvl) - -// -// This comment block is scanned by the trace preprocessor to define our -// TraceEvents function. -// -// begin_wpp config -// FUNC Trace{FLAG=TRACE_FLAG_ALL}(LEVEL, MSG, ...); -// FUNC TraceEvents(LEVEL, FLAGS, MSG, ...); -// end_wpp - -// -// This comment block is scanned by the trace preprocessor to define our -// CHECK_HR function. -// -// -// begin_wpp config -// USEPREFIX (CHECK_HR,"%!STDPREFIX!"); -// FUNC CHECK_HR{FLAG=TRACE_FLAG_ALL}(hrCheck, MSG, ...); -// USESUFFIX (CHECK_HR, " hr= %!HRESULT!", hrCheck); -// end_wpp - -// -// PRE macro: The name of the macro includes the condition arguments FLAGS and EXP -// define in FUNC above -// -#define WPP_FLAG_hrCheck_PRE(FLAGS, hrCheck) {if(hrCheck != S_OK) { - -// -// POST macro -// The name of the macro includes the condition arguments FLAGS and EXP -// define in FUNC above -#define WPP_FLAG_hrCheck_POST(FLAGS, hrCheck) ; } } - -// -// The two macros below are for checking if the event should be logged and for -// choosing the logger handle to use when calling the ETW trace API -// -#define WPP_FLAG_hrCheck_ENABLED(FLAGS, hrCheck) WPP_FLAG_ENABLED(FLAGS) -#define WPP_FLAG_hrCheck_LOGGER(FLAGS, hrCheck) WPP_FLAG_LOGGER(FLAGS) diff --git a/wpd/WpdServiceSampleDriver/Device.cpp b/wpd/WpdServiceSampleDriver/Device.cpp deleted file mode 100644 index b5f4f278..00000000 --- a/wpd/WpdServiceSampleDriver/Device.cpp +++ /dev/null @@ -1,367 +0,0 @@ -#include "stdafx.h" -#include "Device.h" -#include "WpdServiceSampleDriver_i.c" - -#include "Device.tmh" - -STDMETHODIMP_(HRESULT) -CDevice::OnD0Entry(_In_ IWDFDevice* /*pDevice*/, WDF_POWER_DEVICE_STATE /*previousState*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnD0Exit(_In_ IWDFDevice* /*pDevice*/, WDF_POWER_DEVICE_STATE /*newState*/) -{ - return S_OK; -} - -STDMETHODIMP_(VOID) -CDevice::OnSurpriseRemoval(_In_ IWDFDevice* /*pDevice*/) -{ - return; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnQueryRemove(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnQueryStop(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(VOID) -CDevice::OnSelfManagedIoCleanup(_In_ IWDFDevice* /*pDevice*/) -{ - return; -} - -STDMETHODIMP_(VOID) -CDevice::OnSelfManagedIoFlush(_In_ IWDFDevice* /*pDevice*/) -{ - return; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoInit(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoSuspend(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoRestart(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoStop(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnPrepareHardware(_In_ IWDFDevice* pDevice) -{ - HRESULT hr = S_OK; - - if (m_pWpdBaseDriver != NULL) - { - hr = m_pWpdBaseDriver->Initialize(); - CHECK_HR(hr, "Failed to Initialize the driver class"); - } - - // Initialize the WPD Class Extension. This will enable the appropriate WPD interface GUID, - // as well as do any additional initialization (e.g. enabling Legacy Compatibility layers for those drivers - // which requested support in their INF). - if (hr == S_OK && m_pPortableDeviceClassExtension == NULL) - { - CComPtr<IPortableDeviceValues> pOptions; - CComPtr<IPortableDevicePropVariantCollection> pContentTypes; - - hr = CoCreateInstance(CLSID_PortableDeviceClassExtension, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceClassExtension, - (VOID**)&m_pPortableDeviceClassExtension); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceClassExtension"); - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pOptions); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - - if (hr == S_OK) - { - // Get supported content types - if (hr == S_OK) - { - hr = GetSupportedContentTypes(&pContentTypes); - CHECK_HR(hr, "Failed to get supported content types"); - } - - // Add the supported types to the options - if (hr == S_OK) - { - hr = pOptions->SetIPortableDevicePropVariantCollectionValue(WPD_CLASS_EXTENSION_OPTIONS_SUPPORTED_CONTENT_TYPES, pContentTypes); - CHECK_HR(hr, "Failed to set WPD_CLASS_EXTENSION_OPTIONS_SUPPORTED_CONTENT_TYPES"); - } - - // Initialize the PortableDeviceClassExtension with a list of supported content types for the - // connected device. This will ensure that the correct application compatibility settings will - // be applied for your device. - if (hr == S_OK) - { - hr = m_pPortableDeviceClassExtension->Initialize(pDevice, pOptions); - CHECK_HR(hr, "Failed to Initialize portable device class extension object"); - } - - // Register the services as Plug and Play interfaces - if (hr == S_OK) - { - hr = RegisterServices(m_pPortableDeviceClassExtension, false /*bUnregister*/); - CHECK_HR(hr, "Failed to register services"); - } - - // Since users commonly have the abiltity to customize their device even when it is not - // connected to the PC, we need to make sure the PC is current when the driver loads. - // - // Send the latest device friendly name to the PortableDeviceClassExtension component - // so the system is always updated with the current device name. - // - // This call should also be made after a successful property set operation of - // WPD_DEVICE_FRIENDLY_NAME. - - LPWSTR wszDeviceFriendlyName = NULL; - - if (hr == S_OK) - { - hr = GetDeviceFriendlyName(&wszDeviceFriendlyName); - CHECK_HR(hr, "Failed to get device's friendly name"); - } - - if (hr == S_OK) - { - hr = UpdateDeviceFriendlyName(m_pPortableDeviceClassExtension, wszDeviceFriendlyName); - CHECK_HR(hr, "Failed to update device's friendly name"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszDeviceFriendlyName); - } - } - } - - return hr; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnReleaseHardware(_In_ IWDFDevice* /*pDevice*/) -{ - // Unregister the services as Plug and Play interfaces (errors are ignored). - HRESULT hr = RegisterServices(m_pPortableDeviceClassExtension, true /*bUnregister*/); - CHECK_HR(hr, "Failed to unregister services"); - - if (m_pWpdBaseDriver != NULL) - { - m_pWpdBaseDriver->Uninitialize(); - } - - if (m_pPortableDeviceClassExtension != NULL) - { - m_pPortableDeviceClassExtension = NULL; - } - - return S_OK; -} - -HRESULT CDevice::GetSupportedContentTypes( - _Outptr_ IPortableDevicePropVariantCollection** ppContentTypes) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - - if (ppContentTypes == NULL) - { - hr = E_INVALIDARG; - return hr; - } - - *ppContentTypes = NULL; - - // CoCreate a collection to store the WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES command parameters. - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES command results. - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Set the params - if (SUCCEEDED(hr)) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - if (SUCCEEDED(hr)) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - if (SUCCEEDED(hr)) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY, WPD_FUNCTIONAL_CATEGORY_ALL); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY")); - } - - // Make the call - if (SUCCEEDED(hr)) - { - hr = m_pWpdBaseDriver->DispatchWpdMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to dispatch message to get supported content types")); - } - - // Get the results - if (SUCCEEDED(hr)) - { - hr = pResults->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES, ppContentTypes); - CHECK_HR(hr, ("Failed to get WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES")); - } - - return hr; -} - -HRESULT CDevice::GetDeviceFriendlyName( - _Outptr_ LPWSTR* pwszDeviceFriendlyName) -{ - HRESULT hr = S_OK; - - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<IPortableDeviceKeyCollection> pKeys; - CComPtr<IPortableDeviceValues> pValues; - - if (pwszDeviceFriendlyName == NULL) - { - hr = E_INVALIDARG; - return hr; - } - - *pwszDeviceFriendlyName = NULL; - - // CoCreate a collection to store the WPD_COMMAND_OBJECT_PROPERTIES_GET command parameters. - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the WPD_COMMAND_OBJECT_PROPERTIES_GET command results. - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the requested property keys. In our case, we are requesting just the device friendly name - // (WPD_DEVICE_FRIENDLY_NAME) - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**)&pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection for results"); - } - - // Set the params - if (SUCCEEDED(hr)) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_OBJECT_PROPERTIES_GET.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - - if (SUCCEEDED(hr)) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_OBJECT_PROPERTIES_GET.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - - if (SUCCEEDED(hr)) - { - hr = pParams->SetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID")); - } - - if (SUCCEEDED(hr)) - { - hr = pKeys->Add(WPD_DEVICE_FRIENDLY_NAME); - CHECK_HR(hr, ("Failed to add WPD_DEVICE_FRIENDLY_NAME to key collection")); - } - - if (SUCCEEDED(hr)) - { - hr = pParams->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, pKeys); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS")); - } - - // Make the call - if (SUCCEEDED(hr)) - { - hr = m_pWpdBaseDriver->DispatchWpdMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to dispatch message to get supported content types")); - } - - // Get the results - if (SUCCEEDED(hr)) - { - hr = pResults->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, &pValues); - CHECK_HR(hr, ("Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES")); - } - - if (SUCCEEDED(hr)) - { - hr = pValues->GetStringValue(WPD_DEVICE_FRIENDLY_NAME, pwszDeviceFriendlyName); - CHECK_HR(hr, ("Failed to get WPD_DEVICE_FRIENDLY_NAME")); - } - - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/Device.h b/wpd/WpdServiceSampleDriver/Device.h deleted file mode 100644 index cf7fdc03..00000000 --- a/wpd/WpdServiceSampleDriver/Device.h +++ /dev/null @@ -1,91 +0,0 @@ -#pragma once - -#include "resource.h" -#include "WpdServiceSampleDriver.h" - -class ATL_NO_VTABLE CDevice : - public CComObjectRootEx<CComMultiThreadModel>, - public IPnpCallback, - public IPnpCallbackSelfManagedIo, - public IPnpCallbackHardware -{ -public: - CDevice() : - m_pWpdBaseDriver(NULL) - { - } - - DECLARE_NOT_AGGREGATABLE(CDevice) - - BEGIN_COM_MAP(CDevice) - COM_INTERFACE_ENTRY(IPnpCallback) - COM_INTERFACE_ENTRY(IPnpCallbackSelfManagedIo) - COM_INTERFACE_ENTRY(IPnpCallbackHardware) - END_COM_MAP() - -public: - static HRESULT - CreateInstance( - _In_ IWDFDeviceInitialize* pDeviceInit, - _In_ WpdBaseDriver* pWpdBaseDriver, - _COM_Outptr_ IUnknown** ppUnkwn) - { - *ppUnkwn = NULL; - - // - // Set device properties. - // - pDeviceInit->SetLockingConstraint(None); - - CComObject< CDevice> *pMyDevice = NULL; - HRESULT hr = CComObject<CDevice>::CreateInstance( &pMyDevice ); - if( SUCCEEDED (hr) ) - { - pMyDevice->AddRef(); - hr = pMyDevice->QueryInterface( __uuidof(IUnknown),(void **) ppUnkwn); - if (hr == S_OK) - { - pMyDevice->m_pWpdBaseDriver = pWpdBaseDriver; - } - pMyDevice->Release(); - pMyDevice = NULL; - } - - return hr; - } - - // IPnpCallback - // - STDMETHOD_(HRESULT, OnD0Entry) (_In_ IWDFDevice* pDevice, WDF_POWER_DEVICE_STATE previousState); - STDMETHOD_(HRESULT, OnD0Exit) (_In_ IWDFDevice* pDevice, WDF_POWER_DEVICE_STATE newState); - STDMETHOD_(VOID, OnSurpriseRemoval)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnQueryRemove) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnQueryStop) (_In_ IWDFDevice* pDevice); - - // IPnpCallbackSelfManagedIo - // - STDMETHOD_(VOID, OnSelfManagedIoCleanup)(_In_ IWDFDevice* pDevice); - STDMETHOD_(VOID, OnSelfManagedIoFlush) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoInit) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoSuspend) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoRestart) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoStop) (_In_ IWDFDevice* pDevice); - - // IPnpCallbackHardware - // - STDMETHOD_(HRESULT, OnPrepareHardware)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnReleaseHardware)(_In_ IWDFDevice* pDevice); - -private: - HRESULT GetSupportedContentTypes( - _Outptr_ IPortableDevicePropVariantCollection** ppContentTypes); - - HRESULT GetDeviceFriendlyName( - _Outptr_ LPWSTR* pwszDeviceFriendlyName); - -private: - - WpdBaseDriver* m_pWpdBaseDriver; - CComPtr<IPortableDeviceClassExtension> m_pPortableDeviceClassExtension; -}; - diff --git a/wpd/WpdServiceSampleDriver/Driver.cpp b/wpd/WpdServiceSampleDriver/Driver.cpp deleted file mode 100644 index c6f90c53..00000000 --- a/wpd/WpdServiceSampleDriver/Driver.cpp +++ /dev/null @@ -1,200 +0,0 @@ -#include "stdafx.h" - -#include "Driver.h" -#include "Device.h" -#include "Queue.h" - -#include "Driver.tmh" - -CDriver::CDriver() -{ - - -} - -HRESULT -CDriver::OnDeviceAdd( - _In_ IWDFDriver* pDriver, - _In_ IWDFDeviceInitialize* pDeviceInit - ) -/*++ - -Routine Description: - - The framework calls this function when a device is being added to - the driver stack. - -Arguments: - - IWDFDriver - Framework interface. The driver uses this - interface to create device objects. - IWDFDeviceInitialize - Framework interface. The driver uses this - interface to set device parameters before - creating the device obeject. - -Return Value: - - HRESULT S_OK - Device added successfully - ---*/ -{ - HRESULT hr = S_OK; - CComPtr<IUnknown> pDeviceCallback; - - if (hr == S_OK) - { - WpdBaseDriver *pWpdBaseDriver = NULL; - - // - // Create the WPD driver object that handles all WPD messages for this device - // - pWpdBaseDriver = new WpdBaseDriver(); - if(pWpdBaseDriver == NULL) - { - hr = E_OUTOFMEMORY; - } - - if(SUCCEEDED(hr)) - { - // - // Create device callback object - // - hr = CDevice::CreateInstance(pDeviceInit, pWpdBaseDriver, &pDeviceCallback); - } - - // - // This driver has no special power management requirements and so - // we set power policy ownership to UMDF to indicate that UMDF should - // handle powermanagement for us. - // - pDeviceInit->SetPowerPolicyOwnership(FALSE); - - // - // Create WDFDevice. - // - CComPtr<IWDFDevice> pIWDFDevice; - if(SUCCEEDED(hr)) - { - hr = pDriver->CreateDevice( - pDeviceInit, - pDeviceCallback, - &pIWDFDevice); - } - - // - // Assign pWpdBaseDriver to the device object. Each UMDF device requires its own instance of - // a WpdBaseDriver to handle WPD messages. - // - if(SUCCEEDED(hr)) - { - hr = pIWDFDevice->AssignContext(this, (void*)pWpdBaseDriver); - if(SUCCEEDED(hr)) - { - // AddRef the WpdBaseDriver object since it is not stored with the - // device context. - pWpdBaseDriver->AddRef(); - } - } - - // - // Create queue callback object - // - CComPtr<IUnknown> pIUnknown; - if(S_OK == hr) - { - hr = CQueue::CreateInstance(&pIUnknown); - } - - // - // Configure the default queue. - // - if(S_OK == hr) - { - CComPtr<IWDFIoQueue> pDefaultQueue; - hr = pIWDFDevice->CreateIoQueue( - pIUnknown, - TRUE, // bDefaultQueue - WdfIoQueueDispatchSequential, - TRUE, // bPowerManaged - FALSE, // bAllowZeroLengthRequests - &pDefaultQueue); - } - - pDeviceCallback = NULL; - pIWDFDevice = NULL; - - // - // It is fine to release the interface on the callback object. - // The framework has its own refcount on this object and will - // provide an interface when calling into the driver. - // - pIUnknown = NULL; - - // Release the WpdBaseDriver object. If it was successfully added to the device context, - // it was already addref'd above. Releasing it here ensures it will be destroyed if - // an error occured and it could not be added to the device context. - SAFE_RELEASE(pWpdBaseDriver); - } - - return hr; -} - -void -CDriver::OnDeinitialize( - _In_ IWDFDriver* pDriver - ) -/*++ - -Routine Description: - - The framework calls this function just before de-initializing itself. All - WDF framework resources should be released by driver before returning from this call. - -Arguments: - -Return Value: - ---*/ -{ - UNREFERENCED_PARAMETER(pDriver); - return; -} - -HRESULT -CDriver::OnInitialize( - _In_ IWDFDriver* pDriver - ) -/*++ - -Routine Description: - - The framework calls this function just after loading the driver. The driver can - perform any global, device independent intialization in this routine. - -Arguments: - -Return Value: - ---*/ -{ - UNREFERENCED_PARAMETER(pDriver); - return S_OK; -} - -STDMETHODIMP_ (void) -CDriver::OnCleanup( - _In_ IWDFObject* pWdfObject - ) -{ - // Release the base driver object - HRESULT hr = S_OK; - WpdBaseDriver* pWpdBaseDriver = NULL; - - hr = pWdfObject->RetrieveContext((void**)&pWpdBaseDriver); - if((hr == S_OK) && (pWpdBaseDriver != NULL)) - { - pWpdBaseDriver->Release(); - pWpdBaseDriver = NULL; - } -} - diff --git a/wpd/WpdServiceSampleDriver/Driver.h b/wpd/WpdServiceSampleDriver/Driver.h deleted file mode 100644 index 7f826154..00000000 --- a/wpd/WpdServiceSampleDriver/Driver.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "resource.h" -#include "WpdServiceSampleDriver.h" - -class ATL_NO_VTABLE CDriver : - public CComObjectRootEx<CComMultiThreadModel>, - public CComCoClass<CDriver, &CLSID_WpdServiceSampleDriver>, - public IDriverEntry, - public IObjectCleanup -{ -public: - CDriver(); - - DECLARE_REGISTRY_RESOURCEID(IDR_WpdServiceSampleDriver) - - DECLARE_NOT_AGGREGATABLE(CDriver) - - BEGIN_COM_MAP(CDriver) - COM_INTERFACE_ENTRY(IDriverEntry) - END_COM_MAP() - -public: - // - // IDriverEntry - // - STDMETHOD (OnInitialize)( - _In_ IWDFDriver* pDriver - ); - STDMETHOD (OnDeviceAdd)( - _In_ IWDFDriver* pDriver, - _In_ IWDFDeviceInitialize* pDeviceInit - ); - STDMETHOD_ (void, OnDeinitialize)( - _In_ IWDFDriver* pDriver - ); - - // - // IObjectCleanup - // - STDMETHOD_ (void, OnCleanup)( - _In_ IWDFObject* pWdfObject - ); -}; - -OBJECT_ENTRY_AUTO(__uuidof(WpdServiceSampleDriver), CDriver) - diff --git a/wpd/WpdServiceSampleDriver/FakeContactContent.cpp b/wpd/WpdServiceSampleDriver/FakeContactContent.cpp deleted file mode 100644 index f5807756..00000000 --- a/wpd/WpdServiceSampleDriver/FakeContactContent.cpp +++ /dev/null @@ -1,268 +0,0 @@ -#include "stdafx.h" - -#include "FakeContactContent.tmh" - -// Properties supported by a contact -const PropertyAttributeInfo g_SupportedContactProperties[] = -{ - // Standard WPD properties. - {&WPD_OBJECT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NAME_GenericObj_ObjectID}, - {&WPD_OBJECT_PERSISTENT_UNIQUE_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NAME_GenericObj_PersistentUID}, - {&WPD_OBJECT_PARENT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NAME_GenericObj_ParentID}, - {&WPD_OBJECT_NAME, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NAME_GenericObj_Name}, - {&WPD_OBJECT_FORMAT, VT_CLSID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NAME_GenericObj_ObjectFormat}, - {&WPD_OBJECT_CONTENT_TYPE, VT_CLSID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, L"ObjectContentType"}, - {&WPD_OBJECT_CAN_DELETE, VT_BOOL, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, L"ObjectCanDelete"}, - {&WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, L"StorageID"}, - - // Contact Service extension properties - {&PKEY_ContactObj_GivenName, VT_LPWSTR, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast, NAME_ContactObj_GivenName}, - {&PKEY_ContactObj_FamilyName, VT_LPWSTR, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast, NAME_ContactObj_FamilyName}, - - // Custom property used to store the version of this object - {&MyContactVersionIdentifier, VT_UI4, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, L"ContactVersionIdentifier"}, -}; - -HRESULT GetSupportedContactProperties( - _In_ IPortableDeviceKeyCollection *pKeys) -{ - HRESULT hr = S_OK; - - if(pKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedContactProperties); dwIndex++) - { - hr = pKeys->Add(*g_SupportedContactProperties[dwIndex].pKey); - CHECK_HR(hr, "Failed to add custom contacts property"); - } - - return hr; -} - -HRESULT GetContactPropertyAttributes( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if(pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = SetPropertyAttributes(Key, &g_SupportedContactProperties[0], ARRAYSIZE(g_SupportedContactProperties), pAttributes); - - return hr; -} - - -// For this object, the supported properties are the same as the supported -// format properties. -// This is where customization for supported properties per object can happen -HRESULT FakeContactContent::GetSupportedProperties( - _In_ IPortableDeviceKeyCollection *pKeys) -{ - return GetSupportedContactProperties(pKeys); -} - -HRESULT FakeContactContent::GetValue( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pStore) -{ - HRESULT hr = S_OK; - - PropVariantWrapper pvValue; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - // Add WPD_OBJECT_ID - pvValue = ObjectID; - hr = pStore->SetValue(WPD_OBJECT_ID, &pvValue); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_ID")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - // Add WPD_OBJECT_PERSISTENT_UNIQUE_ID - pvValue = this->PersistentUniqueID; - hr = pStore->SetValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, &pvValue); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - // Add WPD_OBJECT_PARENT_ID - pvValue = ParentID; - hr = pStore->SetValue(WPD_OBJECT_PARENT_ID, &pvValue); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_PARENT_ID")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - // Add WPD_OBJECT_NAME - pvValue = Name; - hr = pStore->SetValue(WPD_OBJECT_NAME, &pvValue); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_NAME")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - // Add WPD_OBJECT_CONTENT_TYPE - hr = pStore->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, ContentType); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_CONTENT_TYPE")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - // Add WPD_OBJECT_FORMAT - hr = pStore->SetGuidValue(WPD_OBJECT_FORMAT, Format); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_FORMAT")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - // Add WPD_OBJECT_CAN_DELETE - hr = pStore->SetBoolValue(WPD_OBJECT_CAN_DELETE, CanDelete); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_CAN_DELETE")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID)) - { - // Add WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID - hr = pStore->SetStringValue(WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, ContainerFunctionalObjectID); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID")); - } - else if (IsEqualPropertyKey(Key, PKEY_ContactObj_GivenName)) - { - // Add PKEY_ContactObj_GivenName - pvValue = GivenName; - hr = pStore->SetValue(PKEY_ContactObj_GivenName, &pvValue); - CHECK_HR(hr, ("Failed to set PKEY_ContactObj_GivenName")); - } - else if (IsEqualPropertyKey(Key, PKEY_ContactObj_FamilyName)) - { - // Add PKEY_ContactObj_FamilyName - pvValue = FamilyName; - hr = pStore->SetValue(PKEY_ContactObj_FamilyName, &pvValue); - CHECK_HR(hr, ("Failed to set PKEY_ContactObj_FamilyName")); - } - else if (IsEqualPropertyKey(Key, MyContactVersionIdentifier)) - { - // Add MyContactVersionIdentifier - pvValue = VersionIdentifier; - hr = pStore->SetValue(MyContactVersionIdentifier, &pvValue); - CHECK_HR(hr, ("Failed to set MyContactVersionIdentifier")); - } - else - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - CHECK_HR(hr, "Property {%ws}.%d is not supported", CComBSTR(Key.fmtid), Key.pid); - } - - return hr; -} - - -HRESULT FakeContactContent::WriteValue( - _In_ REFPROPERTYKEY Key, - _In_ REFPROPVARIANT Value) -{ - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(IsEqualPropertyKey(Key, PKEY_ContactObj_FamilyName)) - { - if(Value.vt == VT_LPWSTR) - { - FamilyName = Value.pwszVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set PKEY_ContactObj_FamilyName because type was not VT_LPWSTR"); - } - } - else if(IsEqualPropertyKey(Key, PKEY_ContactObj_GivenName)) - { - if(Value.vt == VT_LPWSTR) - { - GivenName = Value.pwszVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set PKEY_ContactObj_GivenName because type was not VT_LPWSTR"); - } - } - else - { - hr = E_ACCESSDENIED; - CHECK_HR(hr, "Property %ws.%d on [%ws] does not support set value operation", CComBSTR(Key.fmtid), Key.pid, ObjectID); - } - - return hr; -} - -HRESULT FakeContactContent::GetPropertyAttributes( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if(pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - hr = GetContactPropertyAttributes(Key, pAttributes); - CHECK_HR(hr, "Failed to add property attributes for %ws.%d", CComBSTR(Key.fmtid), Key.pid); - - // Some of our properties have extra attributes on top of the ones that are common to all - if(IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - CAtlStringW strDefaultName; - - strDefaultName.Format(L"%ws%ws", L"Name", ObjectID.GetString()); - - hr = pAttributes->SetStringValue(WPD_PROPERTY_ATTRIBUTE_DEFAULT_VALUE, strDefaultName.GetString());; - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_DEFAULT_VALUE"); - } - - return hr; -} - -HRESULT FakeContactContent::WriteValues( - _In_ IPortableDeviceValues* pValues, - _In_ IPortableDeviceValues* pResults, - _Out_ bool* pbObjectChanged) -{ - HRESULT hr = FakeContent::WriteValues(pValues, pResults, pbObjectChanged); - - if (SUCCEEDED(hr) && (*pbObjectChanged == true)) - { - UpdateVersion(); - } - - return hr; -} - -void FakeContactContent::UpdateVersion() -{ - if (VersionIdentifier < ULONG_MAX) - { - VersionIdentifier++; - } - else - { - VersionIdentifier = 0; - } -} diff --git a/wpd/WpdServiceSampleDriver/FakeContactContent.h b/wpd/WpdServiceSampleDriver/FakeContactContent.h deleted file mode 100644 index 1b2d8dfb..00000000 --- a/wpd/WpdServiceSampleDriver/FakeContactContent.h +++ /dev/null @@ -1,77 +0,0 @@ -#pragma once - -/** - * This class represents an abstraction of a contact content object - * Driver implementors should replace this with their own - * device I/O classes/libraries. - */ - -class FakeContactContent : public FakeContent -{ -public: - FakeContactContent() - { - Format = FORMAT_AbstractContact; - ContentType = WPD_CONTENT_TYPE_CONTACT; - RequiredScope = CONTACTS_SERVICE_ACCESS; - CanDelete = true; - VersionIdentifier = 0; - } - - FakeContactContent(const FakeContactContent& src) - { - *this = src; - } - - ~FakeContactContent() - { - } - - FakeContactContent& operator= (const FakeContactContent& src) - { - FamilyName = src.FamilyName; - GivenName = src.GivenName; - VersionIdentifier = src.VersionIdentifier; - - return *this; - } - - HRESULT GetValue( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pStore); - - HRESULT WriteValue( - _In_ REFPROPERTYKEY Key, - _In_ REFPROPVARIANT Value); - - HRESULT GetPropertyAttributes( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes); - - HRESULT GetSupportedProperties( - _In_ IPortableDeviceKeyCollection* pKeys); - - HRESULT WriteValues( - _In_ IPortableDeviceValues* pValues, - _In_ IPortableDeviceValues* pResults, - _Out_ bool* pbObjectChanged); - -private: - void UpdateVersion(); - -public: - // Custom properties defined by the contacts service - CAtlStringW FamilyName; - CAtlStringW GivenName; - -private: - // Indicates whether the object has been updated - DWORD VersionIdentifier; -}; - -HRESULT GetSupportedContactProperties( - _In_ IPortableDeviceKeyCollection* pKeys); - -HRESULT GetContactPropertyAttributes( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes); diff --git a/wpd/WpdServiceSampleDriver/FakeContactsService.cpp b/wpd/WpdServiceSampleDriver/FakeContactsService.cpp deleted file mode 100644 index 405279a9..00000000 --- a/wpd/WpdServiceSampleDriver/FakeContactsService.cpp +++ /dev/null @@ -1,753 +0,0 @@ -#include "stdafx.h" - -#include "FakeContactsService.tmh" - -const FormatAttributeInfo g_SupportedContactFormats[] = -{ - {&FORMAT_AbstractContact, L"AbstractContact"}, - {&FORMAT_VCard2Contact, L"VCard2"} -}; - -const GUID* g_SupportedMethods[] = -{ - &METHOD_FullEnumSyncSvc_BeginSync, - &METHOD_FullEnumSyncSvc_EndSync, - &MyCustomMethod -}; - -// Method parameters -const MethodParameterAttributeInfo g_MethodParameters[] = -{ - {&MyCustomMethodResult, VT_BOOL, WPD_PARAMETER_USAGE_RETURN, WPD_PARAMETER_ATTRIBUTE_FORM_UNSPECIFIED, 0, L"Result"}, - {&MyCustomMethodParam, VT_UI4, WPD_PARAMETER_USAGE_IN, WPD_PARAMETER_ATTRIBUTE_FORM_UNSPECIFIED, 1, L"Integer_Param"}, - {&MyCustomMethodParamInOut, VT_LPWSTR, WPD_PARAMETER_USAGE_INOUT, WPD_PARAMETER_ATTRIBUTE_FORM_OBJECT_IDENTIFIER, 2, L"ObjectId_Param"}, -}; - -const GUID* g_SupportedServiceEvents[] = -{ - &WPD_EVENT_OBJECT_ADDED, - &WPD_EVENT_OBJECT_REMOVED, - &WPD_EVENT_OBJECT_UPDATED, - &MyCustomEvent, -}; - -// Event parameters -const EventParameterAttributeInfo g_ServiceEventParameters[] = -{ - {&WPD_EVENT_OBJECT_ADDED, &WPD_EVENT_PARAMETER_EVENT_ID, VT_CLSID}, - {&WPD_EVENT_OBJECT_ADDED, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, VT_LPWSTR}, - {&WPD_EVENT_OBJECT_ADDED, &WPD_EVENT_PARAMETER_OBJECT_PARENT_PERSISTENT_UNIQUE_ID, VT_LPWSTR}, - {&WPD_EVENT_OBJECT_ADDED, &WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, VT_LPWSTR}, - - {&WPD_EVENT_OBJECT_REMOVED, &WPD_EVENT_PARAMETER_EVENT_ID, VT_CLSID}, - {&WPD_EVENT_OBJECT_REMOVED, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, VT_LPWSTR}, - {&WPD_EVENT_OBJECT_REMOVED, &WPD_EVENT_PARAMETER_OBJECT_PARENT_PERSISTENT_UNIQUE_ID, VT_LPWSTR}, - {&WPD_EVENT_OBJECT_REMOVED, &WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, VT_LPWSTR}, - - {&WPD_EVENT_OBJECT_UPDATED, &WPD_EVENT_PARAMETER_EVENT_ID, VT_CLSID}, - {&WPD_EVENT_OBJECT_UPDATED, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, VT_LPWSTR}, - {&WPD_EVENT_OBJECT_UPDATED, &WPD_EVENT_PARAMETER_OBJECT_PARENT_PERSISTENT_UNIQUE_ID, VT_LPWSTR}, - {&WPD_EVENT_OBJECT_UPDATED, &WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, VT_LPWSTR}, - - {&MyCustomEvent, &WPD_EVENT_PARAMETER_EVENT_ID, VT_CLSID}, - {&MyCustomEvent, &WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, VT_LPWSTR}, - {&MyCustomEvent, &MyCustomEventParam0, VT_BOOL}, - {&MyCustomEvent, &MyCustomEventParam1, VT_UI4}, -}; - -// Supported commands for this service -const PROPERTYKEY* g_ServiceSupportedCommands[] = -{ - // WPD_CATEGORY_OBJECT_ENUMERATION - &WPD_COMMAND_OBJECT_ENUMERATION_START_FIND, - &WPD_COMMAND_OBJECT_ENUMERATION_FIND_NEXT, - &WPD_COMMAND_OBJECT_ENUMERATION_END_FIND, - - // WPD_CATEGORY_OBJECT_PROPERTIES - &WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED, - &WPD_COMMAND_OBJECT_PROPERTIES_GET, - &WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL, - &WPD_COMMAND_OBJECT_PROPERTIES_SET, - &WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES, - &WPD_COMMAND_OBJECT_PROPERTIES_DELETE, - - // WPD_CATEGORY_OBJECT_RESOURCES - &WPD_COMMAND_OBJECT_RESOURCES_GET_SUPPORTED, - &WPD_COMMAND_OBJECT_RESOURCES_OPEN, - &WPD_COMMAND_OBJECT_RESOURCES_READ, - &WPD_COMMAND_OBJECT_RESOURCES_CLOSE, - &WPD_COMMAND_OBJECT_RESOURCES_GET_ATTRIBUTES, - - // WPD_CATEGORY_OBJECT_MANAGEMENT - &WPD_COMMAND_OBJECT_MANAGEMENT_CREATE_OBJECT_WITH_PROPERTIES_ONLY, - &WPD_COMMAND_OBJECT_MANAGEMENT_DELETE_OBJECTS, - - // WPD_CATEGORY_OBJECT_PROPERTIES_BULK - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_START, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_NEXT, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_END, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_START, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_NEXT, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_END, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_START, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_NEXT, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_END, - - // WPD_CATEGORY_COMMON - &WPD_COMMAND_COMMON_GET_OBJECT_IDS_FROM_PERSISTENT_UNIQUE_IDS, - - // WPD_CATEGORY_SERVICE_COMMON - &WPD_COMMAND_SERVICE_COMMON_GET_SERVICE_OBJECT_ID, - - // WPD_CATEGORY_SERVICE_CAPABILITIES - &WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_COMMANDS, - &WPD_COMMAND_SERVICE_CAPABILITIES_GET_COMMAND_OPTIONS, - &WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_METHODS, - &WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_METHODS_BY_FORMAT, - &WPD_COMMAND_SERVICE_CAPABILITIES_GET_METHOD_ATTRIBUTES, - &WPD_COMMAND_SERVICE_CAPABILITIES_GET_METHOD_PARAMETER_ATTRIBUTES, - &WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_FORMATS, - &WPD_COMMAND_SERVICE_CAPABILITIES_GET_FORMAT_ATTRIBUTES, - &WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES, - &WPD_COMMAND_SERVICE_CAPABILITIES_GET_FORMAT_PROPERTY_ATTRIBUTES, - &WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_EVENTS, - &WPD_COMMAND_SERVICE_CAPABILITIES_GET_EVENT_ATTRIBUTES, - &WPD_COMMAND_SERVICE_CAPABILITIES_GET_EVENT_PARAMETER_ATTRIBUTES, - &WPD_COMMAND_SERVICE_CAPABILITIES_GET_INHERITED_SERVICES -}; - - -HRESULT FakeContactsService::GetSupportedCommands( - _In_ IPortableDeviceKeyCollection* pCommands) -{ - HRESULT hr = S_OK; - - if(pCommands == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_ServiceSupportedCommands); dwIndex++) - { - PROPERTYKEY key = *(g_ServiceSupportedCommands[dwIndex]); - hr = pCommands->Add(key); - CHECK_HR(hr, "Failed to add supported command at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - return hr; -} - -HRESULT FakeContactsService::GetCommandOptions( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pOptions) -{ - HRESULT hr = S_OK; - - if(pOptions == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Check for command options - if (IsEqualPropertyKey(WPD_COMMAND_OBJECT_MANAGEMENT_DELETE_OBJECTS, Command)) - { - // This driver does not support recursive deletion - hr = pOptions->SetBoolValue(WPD_OPTION_OBJECT_MANAGEMENT_RECURSIVE_DELETE_SUPPORTED, TRUE); - CHECK_HR(hr, "Failed to set WPD_OPTION_OBJECT_MANAGEMENT_RECURSIVE_DELETE_SUPPORTED"); - } - - return hr; -} - - -HRESULT FakeContactsService::GetSupportedMethods( - _In_ IPortableDevicePropVariantCollection* pMethods) -{ - HRESULT hr = S_OK; - - if (pMethods == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Add the supported methods to the collection. - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedMethods); dwIndex++) - { - PROPVARIANT pv; - pv.vt = VT_CLSID; - pv.puuid = (GUID*)g_SupportedMethods[dwIndex]; // Assignment only, don't PropVariantClear this - - hr = pMethods->Add(&pv); - CHECK_HR(hr, "Failed to add supported method at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - - return hr; -} - -BOOL FakeContactsService::IsMethodSupported( - _In_ REFGUID Method) -{ - // Add the supported methods to the collection. - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedMethods); dwIndex++) - { - if (Method == *g_SupportedMethods[dwIndex]) - { - return TRUE; - } - } - - return FALSE; -} - -HRESULT FakeContactsService::GetSupportedMethodsByFormat( - _In_ REFGUID Format, - _In_ IPortableDevicePropVariantCollection* pMethods) -{ - HRESULT hr = S_OK; - - if (pMethods == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - for (DWORD i=0; i<ARRAYSIZE(g_SupportedContactFormats); i++) - { - if (Format == *g_SupportedContactFormats[i].pFormatGuid) - { - // Add the supported methods for the format to the collection, right now there are none, so we - // return an emtpy collection - hr = S_OK; - break; - } - } - CHECK_HR(hr, "Format %ws is not supported", CComBSTR(Format)); - - return hr; -} - - -HRESULT FakeContactsService::GetMethodAttributes( - _In_ REFGUID Method, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pParameters; - - if (pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // CoCreate a collection for specifying the method parameters. - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pParameters); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - - // Add the method attributes to this collection - if (Method == METHOD_FullEnumSyncSvc_BeginSync) - { - if (hr == S_OK) - { - hr = pAttributes->SetStringValue(WPD_METHOD_ATTRIBUTE_NAME, L"BeginSync"); - CHECK_HR(hr, "Failed to set WPD_METHOD_ATTRIBUTE_NAME"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_METHOD_ATTRIBUTE_ACCESS, WPD_COMMAND_ACCESS_READWRITE); - CHECK_HR(hr, "Failed to set WPD_METHOD_ATTRIBUTE_ACCESS"); - } - - if (hr == S_OK) - { - // no parameters, set empty collection - hr = pAttributes->SetIPortableDeviceKeyCollectionValue(WPD_METHOD_ATTRIBUTE_PARAMETERS, pParameters); - CHECK_HR(hr, "Failed to set WPD_METHOD_ATTRIBUTE_PARAMETERS"); - } - - if (hr == S_OK) - { - // no associated format, set GUID_NULL - hr = pAttributes->SetGuidValue(WPD_METHOD_ATTRIBUTE_ASSOCIATED_FORMAT, GUID_NULL); - CHECK_HR(hr, "Failed to set WPD_METHOD_ATTRIBUTE_ASSOCIATED_FORMAT"); - } - - } - else if (Method == METHOD_FullEnumSyncSvc_EndSync) - { - if (hr == S_OK) - { - hr = pAttributes->SetStringValue(WPD_METHOD_ATTRIBUTE_NAME, L"EndSync"); - CHECK_HR(hr, "Failed to set WPD_METHOD_ATTRIBUTE_NAME"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_METHOD_ATTRIBUTE_ACCESS, WPD_COMMAND_ACCESS_READWRITE); - CHECK_HR(hr, "Failed to set WPD_METHOD_ATTRIBUTE_ACCESS"); - } - - if (hr == S_OK) - { - // no parameters, set empty collection - hr = pAttributes->SetIPortableDeviceKeyCollectionValue(WPD_METHOD_ATTRIBUTE_PARAMETERS, pParameters); - CHECK_HR(hr, "Failed to set WPD_METHOD_ATTRIBUTE_PARAMETERS"); - } - - if (hr == S_OK) - { - // no associated format, set GUID_NULL - hr = pAttributes->SetGuidValue(WPD_METHOD_ATTRIBUTE_ASSOCIATED_FORMAT, GUID_NULL); - CHECK_HR(hr, "Failed to set WPD_METHOD_ATTRIBUTE_ASSOCIATED_FORMAT"); - } - } - else if (Method == MyCustomMethod) - { - if (hr == S_OK) - { - hr = pAttributes->SetStringValue(WPD_METHOD_ATTRIBUTE_NAME, L"CustomMethod"); - CHECK_HR(hr, "Failed to set WPD_METHOD_ATTRIBUTE_NAME"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_METHOD_ATTRIBUTE_ACCESS, WPD_COMMAND_ACCESS_READWRITE); - CHECK_HR(hr, "Failed to set WPD_METHOD_ATTRIBUTE_ACCESS"); - } - - if (hr == S_OK) - { - // Set the supported parameters - for (size_t i=0; i<ARRAYSIZE(g_MethodParameters); i++) - { - pParameters->Add(*(g_MethodParameters[i].pKey)); - } - - hr = pAttributes->SetIPortableDeviceKeyCollectionValue(WPD_METHOD_ATTRIBUTE_PARAMETERS, pParameters); - CHECK_HR(hr, "Failed to set WPD_METHOD_ATTRIBUTE_PARAMETERS"); - } - - if (hr == S_OK) - { - // no associated format, set GUID_NULL - hr = pAttributes->SetGuidValue(WPD_METHOD_ATTRIBUTE_ASSOCIATED_FORMAT, GUID_NULL); - CHECK_HR(hr, "Failed to set WPD_METHOD_ATTRIBUTE_ASSOCIATED_FORMAT"); - } - } - else - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - CHECK_HR(hr, "Unknown method %ws received",CComBSTR(Method)); - } - - return hr; -} - -HRESULT FakeContactsService::GetMethodParameterAttributes( - _In_ REFPROPERTYKEY Parameter, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if (pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = SetMethodParameterAttributes(Parameter, &g_MethodParameters[0], ARRAYSIZE(g_MethodParameters), pAttributes); - CHECK_HR(hr, "Failed to set method parameter attributes"); - - return hr; -} - -HRESULT FakeContactsService::GetSupportedFormats( - _In_ IPortableDevicePropVariantCollection* pFormats) -{ - HRESULT hr = S_OK; - - if (pFormats == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - if (hr == S_OK) - { - // Add the supported formats to this collection - for (DWORD i=0; i<ARRAYSIZE(g_SupportedContactFormats); i++) - { - PROPVARIANT pv = {0}; - pv.vt = VT_CLSID; - pv.puuid = (CLSID*)g_SupportedContactFormats[i].pFormatGuid; // assignment, do not call PropVariantClear - - hr = pFormats->Add(&pv); - CHECK_HR(hr, "Failed to add format to IPortableDevicePropVariantCollection"); - } - } - - return hr; -} - -HRESULT FakeContactsService::GetFormatAttributes( - _In_ REFGUID Format, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if (pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - - // Add the supported formats to this collection - for (DWORD i=0; i<ARRAYSIZE(g_SupportedContactFormats); i++) - { - if (Format == *g_SupportedContactFormats[i].pFormatGuid) - { - hr = pAttributes->SetStringValue(WPD_FORMAT_ATTRIBUTE_NAME, g_SupportedContactFormats[i].wszName); - CHECK_HR(hr, "Failed to set WPD_FORMAT_ATTRIBUTE_NAME"); - break; - } - } - - if (hr == HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)) - { - CHECK_HR(hr, "Unknown format %ws received",CComBSTR(Format)); - } - - return hr; -} - -HRESULT FakeContactsService::GetSupportedFormatProperties( - _In_ REFGUID Format, - _In_ IPortableDeviceKeyCollection* pKeys) -{ - HRESULT hr = S_OK; - - if (pKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Add the supported format properties to this collection - // The formats of this service happen to support the same set of properties - hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - for (DWORD i=0; i<ARRAYSIZE(g_SupportedContactFormats); i++) - { - if (Format == (*g_SupportedContactFormats[i].pFormatGuid)) - { - hr = GetSupportedContactProperties(pKeys); - CHECK_HR(hr, "Failed to add supported contact format properties"); - break; - } - } - CHECK_HR(hr, "Format %ws is not supported", CComBSTR(Format)); - - return hr; -} - -HRESULT FakeContactsService::GetPropertyAttributes( - _In_ REFGUID Format, - _In_ REFPROPERTYKEY Property, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - - for (DWORD i=0; i<ARRAYSIZE(g_SupportedContactFormats); i++) - { - if (Format == (*g_SupportedContactFormats[i].pFormatGuid)) - { - hr = GetContactPropertyAttributes(Property, pAttributes); - CHECK_HR(hr, "Failed to get property attributes"); - break; - } - } - - CHECK_HR(hr, "Failed to find supported format to retrieve property attributes"); - - return hr; -} - -HRESULT FakeContactsService::GetSupportedEvents( - _In_ IPortableDevicePropVariantCollection* pEvents) -{ - HRESULT hr = S_OK; - - if (pEvents == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - PROPVARIANT pv; - pv.vt = VT_CLSID; - - for (DWORD i=0; i<ARRAYSIZE(g_SupportedServiceEvents); i++) - { - pv.puuid = (CLSID*)g_SupportedServiceEvents[i]; // Assignment, don't PropVariantClear this - - hr = pEvents->Add(&pv); - CHECK_HR(hr, "Failed to add event to the collection"); - } - - return hr; -} - -HRESULT FakeContactsService::GetEventAttributes( - _In_ REFGUID Event, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pEventOptions; - CComPtr<IPortableDeviceKeyCollection> pEventParameters; - - if (pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // CoCreate a collection to store the event options. - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pEventOptions); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - if (hr == S_OK) - { - hr = pEventOptions->SetBoolValue(WPD_EVENT_OPTION_IS_BROADCAST_EVENT, TRUE); - CHECK_HR(hr, "Failed to set WPD_EVENT_OPTION_IS_BROADCAST_EVENT"); - } - - // Loop through the supported events for this service to find a match - hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - for (DWORD i=0; i<ARRAYSIZE(g_SupportedServiceEvents); i++) - { - if (Event == *g_SupportedServiceEvents[i]) - { - // Set the event options. - hr = pAttributes->SetIPortableDeviceValuesValue(WPD_EVENT_ATTRIBUTE_OPTIONS, pEventOptions); - CHECK_HR(hr, "Failed to set WPD_EVENT_ATTRIBUTE_OPTIONS"); - - // Set the event parameters. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pEventParameters); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = SetEventParameters(Event, &g_ServiceEventParameters[0], ARRAYSIZE(g_ServiceEventParameters), pEventParameters); - CHECK_HR(hr, "Failed to set event parameters"); - - if (hr == S_OK) - { - hr = pAttributes->SetIPortableDeviceKeyCollectionValue(WPD_EVENT_ATTRIBUTE_PARAMETERS, pEventParameters); - CHECK_HR(hr, "Failed to set WPD_METHOD_ATTRIBUTE_PARAMETERS"); - } - } - - // Set a name for the custom event - if (hr == S_OK) - { - if (Event == MyCustomEvent) - { - hr = pAttributes->SetStringValue(WPD_EVENT_ATTRIBUTE_NAME , L"MyCustomEvent"); - CHECK_HR(hr, "Failed to set WPD_EVENT_ATTRIBUTE_NAME"); - } - } - break; - } - } - - return hr; -} - -HRESULT FakeContactsService::GetEventParameterAttributes( - _In_ REFPROPERTYKEY Parameter, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if (pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = SetEventParameterAttributes(Parameter, &g_ServiceEventParameters[0], ARRAYSIZE(g_ServiceEventParameters), pAttributes); - CHECK_HR(hr, "Failed to set event parameter attributes"); - - return hr; -} - -HRESULT FakeContactsService::GetInheritedServices( - const DWORD dwInheritanceType, - _In_ IPortableDevicePropVariantCollection* pServices) -{ - HRESULT hr = S_OK; - - if (pServices == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - if (dwInheritanceType == WPD_SERVICE_INHERITANCE_IMPLEMENTATION) - { - PROPVARIANT pv; - pv.vt = VT_CLSID; - pv.puuid = (CLSID*)&SERVICE_FullEnumSync; // Assignment, don't PropVariantClear this - - hr = pServices->Add(&pv); - CHECK_HR(hr, "Failed to add service GUID to the collection"); - } - - return hr; -} - -HRESULT FakeContactsService::OnBeginSync( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - UNREFERENCED_PARAMETER(pParams); - UNREFERENCED_PARAMETER(pResults); - - // This is where the sync service receives a notification from the application that - // sync is about to begin so that it can lock the session - // This method does not do anything right now - - return S_OK; -} - -HRESULT FakeContactsService::OnEndSync( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - UNREFERENCED_PARAMETER(pParams); - UNREFERENCED_PARAMETER(pResults); - - // This is where the sync service receives a notification from the application that - // sync is about to end so that it can unlock the session - // This method does not do anything right now - - return S_OK; -} - -// This demonstrates how a custom service method can be implemented -HRESULT FakeContactsService::OnMyCustomMethod( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults, - _In_ IPortableDeviceValues* pEventParams) -{ - HRESULT hr = S_OK; - DWORD dwParamValue = 0; - BOOL bResultValue = FALSE; - LPWSTR pszParamValue = NULL; - - if (pParams == NULL || pResults == NULL || pEventParams == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = pParams->GetUnsignedIntegerValue(MyCustomMethodParam, &dwParamValue); - CHECK_HR(hr, "Failed to get MyCustomMethodParam"); - - if (hr == S_OK) - { - hr = pParams->GetStringValue(MyCustomMethodParamInOut, &pszParamValue); - CHECK_HR(hr, "Failed to get MyCustomMethodParamInOut"); - } - - if (hr == S_OK) - { - // For demonstration purposes only, we simply return the inout parameter as is - hr = pResults->SetStringValue(MyCustomMethodParamInOut, pszParamValue); - CHECK_HR(hr, "Failed to set MyCustomMethodParamInOut"); - } - - if (hr == S_OK) - { - // This is where the device will process the method invocation - // For demonstration purposes only, we return TRUE if the input is an even number - bResultValue = (dwParamValue % 1 == 0)?TRUE:FALSE; - } - - if (hr == S_OK) - { - hr = pResults->SetBoolValue(MyCustomMethodResult, bResultValue); - CHECK_HR(hr, "Failed to set MyCustomMethodResult"); - } - - if (hr == S_OK) - { - hr = pEventParams->SetGuidValue(WPD_EVENT_PARAMETER_EVENT_ID, MyCustomEvent); - CHECK_HR(hr, "Failed to add WPD_EVENT_PARAMETER_EVENT_ID"); - - if (hr == S_OK) - { - // Adding this event parameter will allow WPD to scope this event to the container functional object - hr = pEventParams->SetStringValue(WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, RequestFilename); - CHECK_HR(hr, "Failed to add WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID"); - } - - if (hr == S_OK) - { - // set the first custom event parameter - hr = pEventParams->SetBoolValue(MyCustomEventParam0, bResultValue); - CHECK_HR(hr, "Failed to add MyCustomEvent parameter 0"); - } - - if (hr == S_OK) - { - // set the second custom event parameter - hr = pEventParams->SetUnsignedIntegerValue(MyCustomEventParam1, dwParamValue); - CHECK_HR(hr, "Failed to add MyCustomEvent parameter 1"); - } - } - - CoTaskMemFree(pszParamValue); - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/FakeContactsService.h b/wpd/WpdServiceSampleDriver/FakeContactsService.h deleted file mode 100644 index 23522c07..00000000 --- a/wpd/WpdServiceSampleDriver/FakeContactsService.h +++ /dev/null @@ -1,101 +0,0 @@ -#pragma once - -/** - * This class represents an abstraction of a contacts service that implements - * the full enumeration sync model. - * Driver implementors should replace this with their own - * device I/O classes/libraries. - */ - -class FakeContactsService -{ -public: - FakeContactsService() : RequestFilename(CONTACTS_SERVICE_OBJECT_ID) - { - } - - ~FakeContactsService() - { - } - - // Capabilities - HRESULT GetSupportedCommands( - _In_ IPortableDeviceKeyCollection* pCommands); - - HRESULT GetCommandOptions( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pOptions); - - HRESULT GetSupportedMethods( - _In_ IPortableDevicePropVariantCollection* pMethods); - - BOOL IsMethodSupported( - _In_ REFGUID Method); - - HRESULT GetSupportedMethodsByFormat( - _In_ REFGUID Format, - _In_ IPortableDevicePropVariantCollection* pMethods); - - HRESULT GetMethodAttributes( - _In_ REFGUID Method, - _In_ IPortableDeviceValues* pAttributes); - - HRESULT GetMethodParameterAttributes( - _In_ REFPROPERTYKEY Parameter, - _In_ IPortableDeviceValues* pAttributes); - - HRESULT GetSupportedFormats( - _In_ IPortableDevicePropVariantCollection* pFormats); - - HRESULT GetFormatAttributes( - _In_ REFGUID Format, - _In_ IPortableDeviceValues* pAttributes); - - HRESULT GetSupportedFormatProperties( - _In_ REFGUID Format, - _In_ IPortableDeviceKeyCollection* pKeys); - - HRESULT GetPropertyAttributes( - _In_ REFGUID Format, - _In_ REFPROPERTYKEY Property, - _In_ IPortableDeviceValues* pAttributes); - - HRESULT GetSupportedEvents( - _In_ IPortableDevicePropVariantCollection* pEvents); - - HRESULT GetEventAttributes( - _In_ REFGUID Event, - _In_ IPortableDeviceValues* pAttributes); - - HRESULT GetEventParameterAttributes( - _In_ REFPROPERTYKEY Parameter, - _In_ IPortableDeviceValues* pAttributes); - - HRESULT GetInheritedServices( - const DWORD dwInheritanceType, - _In_ IPortableDevicePropVariantCollection* pServices); - - // Methods - HRESULT OnBeginSync( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnEndSync( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnMyCustomMethod( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults, - _In_ IPortableDeviceValues* pEventParameters); - - LPCWSTR GetRequestFilename() - { - return RequestFilename.GetString(); - } - -private: - CAtlStringW RequestFilename; -}; - - diff --git a/wpd/WpdServiceSampleDriver/FakeContactsServiceContent.cpp b/wpd/WpdServiceSampleDriver/FakeContactsServiceContent.cpp deleted file mode 100644 index d6135e2d..00000000 --- a/wpd/WpdServiceSampleDriver/FakeContactsServiceContent.cpp +++ /dev/null @@ -1,555 +0,0 @@ -#include "stdafx.h" - -#include "FakeContactsServiceContent.tmh" - -// Change unit is a subset of the custom properties supported by a contact object. -// This typically contains at least one read-only property that indicates that the -// object has changed -const PROPERTYKEY* g_ContactsServiceChangeUnit[1] = -{ - &MyContactVersionIdentifier, -}; - -const PropertyAttributeInfo g_SupportedServiceProperties[] = -{ - {&WPD_OBJECT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_PERSISTENT_UNIQUE_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_PARENT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_NAME, VT_LPWSTR, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_FORMAT, VT_CLSID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_CONTENT_TYPE, VT_CLSID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_CAN_DELETE, VT_BOOL, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_FUNCTIONAL_OBJECT_CATEGORY, VT_CLSID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_SERVICE_VERSION, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&PKEY_Services_ServiceDisplayName, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NAME_Services_ServiceDisplayName}, - {&PKEY_Services_ServiceIcon, VT_VECTOR | VT_UI1, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NAME_Services_ServiceIcon}, - {&PKEY_FullEnumSyncSvc_SyncFormat, VT_VECTOR | VT_UI1, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NAME_FullEnumSyncSvc_SyncFormat}, - {&PKEY_FullEnumSyncSvc_VersionProps, VT_VECTOR | VT_UI1, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NAME_FullEnumSyncSvc_VersionProps}, - {&PKEY_FullEnumSyncSvc_LocalOnlyDelete, VT_UI1, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast, NAME_FullEnumSyncSvc_LocalOnlyDelete}, - {&PKEY_FullEnumSyncSvc_FilterType, VT_UI1, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast, NAME_FullEnumSyncSvc_FilterType}, - {&PKEY_FullEnumSyncSvc_ReplicaID, VT_VECTOR | VT_UI1, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast, NAME_FullEnumSyncSvc_ReplicaID}, -}; - -HRESULT FakeContactsServiceContent::InitializeContent( - _Inout_ DWORD *pdwLastObjectID) -{ - HRESULT hr = S_OK; - - if (pdwLastObjectID == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Add contact objects to the contact service - for(DWORD dwContactIndex = 1; dwContactIndex <= NUM_CONTACT_OBJECTS; dwContactIndex++) - { - (*pdwLastObjectID)++; - - CAutoPtr<FakeContactContent> pContact(new FakeContactContent()); - if (pContact) - { - pContact->ParentID = ObjectID; - pContact->ContainerFunctionalObjectID = ObjectID; - pContact->ParentPersistentUniqueID = PersistentUniqueID; - pContact->RequiredScope = CONTACTS_SERVICE_ACCESS; - pContact->Name.Format(L"Contact%d", *pdwLastObjectID); - pContact->ObjectID.Format(L"%d", *pdwLastObjectID); - pContact->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pContact->ObjectID.GetString()); - pContact->GivenName.Format(L"GivenName%d", dwContactIndex); - pContact->FamilyName.Format(L"FamilyName%d", dwContactIndex); - - _ATLTRY - { - m_Children.Add(pContact); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeContactContent"); - } - - if (SUCCEEDED(hr)) - { - pContact.Detach(); - } - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate contact content at index %d", dwContactIndex); - return hr; - } - } - - return hr; -} - -HRESULT FakeContactsServiceContent::CreatePropertiesOnlyObject( - _In_ IPortableDeviceValues* pObjectProperties, - _Out_ DWORD* pdwLastObjectID, - _Outptr_result_nullonfailure_ FakeContent** ppNewObject) -{ - HRESULT hr = S_OK; - HRESULT hrTemp = S_OK; - GUID guidContentType = WPD_CONTENT_TYPE_UNSPECIFIED; - GUID guidFormat = WPD_OBJECT_FORMAT_UNSPECIFIED; - - if (pObjectProperties == NULL || pdwLastObjectID == NULL || ppNewObject == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - *pdwLastObjectID = NULL; - *ppNewObject = NULL; - - // Get WPD_OBJECT_FORMAT - if (SUCCEEDED(hr)) - { - hr = pObjectProperties->GetGuidValue(WPD_OBJECT_FORMAT, &guidFormat); - CHECK_HR(hr, "Failed to get WPD_OBJECT_FORMAT"); - } - - if (SUCCEEDED(hr) && (guidFormat != WPD_OBJECT_FORMAT_VCARD2) && (guidFormat != WPD_OBJECT_FORMAT_ABSTRACT_CONTACT)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid Format [%ws]", CComBSTR(guidFormat)); - } - - if (SUCCEEDED(hr)) - { - // Create the object - CAutoPtr<FakeContactContent> pContent(new FakeContactContent()); - if (pContent) - { - (*pdwLastObjectID)++; - pContent->ParentID = ObjectID; - pContent->ParentPersistentUniqueID = PersistentUniqueID; - pContent->Name.Format(L"Contact%d", *pdwLastObjectID); - pContent->ObjectID.Format(L"%d", (*pdwLastObjectID)); - pContent->ContentType = guidContentType; - pContent->Format = guidFormat; - pContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pContent->ObjectID.GetString()); - pContent->ContainerFunctionalObjectID = ObjectID; - pContent->RequiredScope = CONTACTS_SERVICE_ACCESS; - - // Get the other optional contact properties. - LPWSTR pszTempString = NULL; - hrTemp = pObjectProperties->GetStringValue(WPD_OBJECT_NAME, &pszTempString); - if(hrTemp == S_OK) - { - pContent->Name = pszTempString; - CoTaskMemFree(pszTempString); - } - - hrTemp = pObjectProperties->GetStringValue(PKEY_ContactObj_FamilyName, &pszTempString); - if(hrTemp == S_OK) - { - pContent->FamilyName = pszTempString; - CoTaskMemFree(pszTempString); - } - - hrTemp = pObjectProperties->GetStringValue(PKEY_ContactObj_GivenName, &pszTempString); - if(hrTemp == S_OK) - { - pContent->GivenName = pszTempString; - CoTaskMemFree(pszTempString); - } - - _ATLTRY - { - m_Children.Add(pContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeContactContent"); - } - - if (SUCCEEDED(hr)) - { - *ppNewObject = pContent.Detach(); - } - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new FakeContactContent object"); - } - } - return hr; -} - -HRESULT FakeContactsServiceContent::GetSupportedProperties( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - HRESULT hr = S_OK; - - if (pKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - for (DWORD dwIndex = 0; (dwIndex < ARRAYSIZE(g_SupportedServiceProperties)) && (hr == S_OK); dwIndex++) - { - // Common WPD service properties - hr = pKeys->Add(*g_SupportedServiceProperties[dwIndex].pKey); - CHECK_HR(hr, "Failed to add common service property"); - } - - return hr; -} - -HRESULT FakeContactsServiceContent::GetPropertyAttributes( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if(pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = SetPropertyAttributes(Key, &g_SupportedServiceProperties[0], ARRAYSIZE(g_SupportedServiceProperties), pAttributes); - - return hr; -} - -HRESULT FakeContactsServiceContent::GetValue( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pStore) -{ - HRESULT hr = S_OK; - - PropVariantWrapper pvValue; - - if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - // Add WPD_OBJECT_ID - pvValue = ObjectID; - hr = pStore->SetValue(WPD_OBJECT_ID, &pvValue); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_ID")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - // Add WPD_OBJECT_NAME - pvValue = Name; - hr = pStore->SetValue(WPD_OBJECT_NAME, &pvValue); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_NAME")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - // Add WPD_OBJECT_PERSISTENT_UNIQUE_ID - pvValue = PersistentUniqueID; - hr = pStore->SetValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, &pvValue); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - // Add WPD_OBJECT_PARENT_ID - pvValue = ParentID; - hr = pStore->SetValue(WPD_OBJECT_PARENT_ID, &pvValue); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_PARENT_ID")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - // Add WPD_OBJECT_FORMAT - hr = pStore->SetGuidValue(WPD_OBJECT_FORMAT, Format); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_FORMAT")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - // Add WPD_OBJECT_CONTENT_TYPE - hr = pStore->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, ContentType); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_CONTENT_TYPE")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - // Add WPD_OBJECT_CAN_DELETE - hr = pStore->SetBoolValue(WPD_OBJECT_CAN_DELETE, CanDelete); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_CAN_DELETE")); - } - else if (IsEqualPropertyKey(Key, WPD_FUNCTIONAL_OBJECT_CATEGORY)) - { - // Add WPD_FUNCTIONAL_OBJECT_CATEGORY - hr = pStore->SetGuidValue(WPD_FUNCTIONAL_OBJECT_CATEGORY, FunctionalCategory); - CHECK_HR(hr, ("Failed to set WPD_FUNCTIONAL_OBJECT_CATEGORY")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID)) - { - // Add WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID - hr = pStore->SetStringValue(WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, ContainerFunctionalObjectID); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID")); - } - else if (IsEqualPropertyKey(Key, WPD_SERVICE_VERSION)) - { - // Add WPD_SERVICE_VERSION - hr = pStore->SetStringValue(WPD_SERVICE_VERSION, Version); - CHECK_HR(hr, ("Failed to set WPD_SERVICE_VERSION")); - } - else if (IsEqualPropertyKey(Key, PKEY_Services_ServiceDisplayName)) - { - // Add PKEY_Services_ServiceDisplayName - pvValue = HumanReadableName; - hr = pStore->SetValue(PKEY_Services_ServiceDisplayName, &pvValue); - CHECK_HR(hr, ("Failed to set PKEY_Services_ServiceDisplayName")); - } - else if (IsEqualPropertyKey(Key, PKEY_FullEnumSyncSvc_SyncFormat)) - { - // Add PKEY_FullEnumSyncSvc_SyncFormat - hr = pStore->SetBufferValue(PKEY_FullEnumSyncSvc_SyncFormat, reinterpret_cast<BYTE*>(&PreferredSyncFormat), sizeof(PreferredSyncFormat)); - CHECK_HR(hr, ("Failed to set PKEY_FullEnumSyncSvc_SyncFormat")); - } - else if (IsEqualPropertyKey(Key, PKEY_Services_ServiceIcon)) - { - // Add PKEY_Services_ServiceIcon - hr = GetIconData(pStore); - CHECK_HR(hr, "Failed to set PKEY_Services_ServiceIcon"); - } - else if (IsEqualPropertyKey(Key, PKEY_FullEnumSyncSvc_VersionProps)) - { - // Add PKEY_FullEnumSyncSvc_VersionProps - hr = GetVICData(pStore); - CHECK_HR(hr, "Failed to set PKEY_FullEnumSyncSvc_VersionProps"); - } - else if (IsEqualPropertyKey(Key, PKEY_FullEnumSyncSvc_LocalOnlyDelete)) - { - // Add PKEY_FullEnumSyncSvc_LocalOnlyDelete - PROPVARIANT pv = {0}; - pv.vt = VT_UI1; - pv.bVal = LocalOnlyDelete; - - hr = pStore->SetValue(PKEY_FullEnumSyncSvc_LocalOnlyDelete, &pv); - CHECK_HR(hr, "Failed to set PKEY_FullEnumSyncSvc_LocalOnlyDelete"); - } - else if (IsEqualPropertyKey(Key, PKEY_FullEnumSyncSvc_FilterType)) - { - // Add PKEY_FullEnumSyncSvc_FilterType - PROPVARIANT pv = {0}; - pv.vt = VT_UI1; - pv.bVal = FilterType; - - hr = pStore->SetValue(PKEY_FullEnumSyncSvc_FilterType, &pv); - CHECK_HR(hr, "Failed to set PKEY_FullEnumSyncSvc_FilterType"); - } - else if (IsEqualPropertyKey(Key, PKEY_FullEnumSyncSvc_ReplicaID)) - { - // Add PKEY_FullEnumSyncSvc_ReplicaID - hr = pStore->SetBufferValue(PKEY_FullEnumSyncSvc_ReplicaID, reinterpret_cast<BYTE*>(&ReplicaId), sizeof(ReplicaId)); - CHECK_HR(hr, "Failed to set PKEY_FullEnumSyncSvc_ReplicaID"); - } - else - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - CHECK_HR(hr, "Property {%ws}.%d is not supported", CComBSTR(Key.fmtid), Key.pid); - } - - return hr; -} - -/** - * This method is called to get the contacts service icon data. - * - * The parameters sent to us are: - * pValues - An IPortableDeviceValues to be populated with the icon data - * - * The driver should: - * Retrieve the icon data and set it in pValues for PKEY_Services_ServiceIcon - */ -HRESULT FakeContactsServiceContent::GetIconData( - _In_ IPortableDeviceValues* pStore) -{ - HRESULT hr = S_OK; - PBYTE pIconData = NULL; - DWORD cbIconData = 0; - - if (pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - pIconData = GetResourceData(IDR_WPD_SAMPLEDRIVER_SERVICE_ICON); - cbIconData = GetResourceSize(IDR_WPD_SAMPLEDRIVER_SERVICE_ICON); - - if ((pIconData == NULL) || (cbIconData == 0)) - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Failed to get resource representing the service icon data"); - } - - if (hr == S_OK) - { - hr = pStore->SetBufferValue(PKEY_Services_ServiceIcon, pIconData, cbIconData); - CHECK_HR(hr, "Failed to copy the icon data to IPortableDeviceValues"); - } - - return hr; -} - -/** - * This method is called to get the contacts service's full enumeration version properties - * - * The parameters sent to us are: - * pValues - An IPortableDeviceValues to be populated with the version property data - * - * The driver should: - * Retrieve the version property data blob and set it in pValues for SVCPROP_FullEnumVersionProps - * - * Version property data blob must adhere to the following format: - * - * Count of Change Unit Groups - * Change Unit PROPERTYKEY (group 0) - * Count of Keys (group 0) - * Key0, Key1..Keyn(group 0) - * ... - * Change Unit PROPERTYKEY (group 1) - * Count of Keys (group 1) - * Key0, Key1..Keyn(group 1) - */ -HRESULT FakeContactsServiceContent::GetVICData( - _In_ IPortableDeviceValues* pStore) -{ - HRESULT hr = E_OUTOFMEMORY; - const DWORD cGroup = 1; // currently support only 1 group - DWORD cVIC = ARRAYSIZE(g_ContactsServiceChangeUnit); - - // Our VIC contains only a single change unit, identified by GUID_NULL - DWORD cbVIC = - sizeof(cGroup) + // count of groups of change units - // Currently we support only 1 group - sizeof(PROPERTYKEY) + // change unit identifier - sizeof(cVIC) + // change unit count - ARRAYSIZE(g_ContactsServiceChangeUnit) * sizeof(PROPERTYKEY); // Properties in this change unit - - BYTE *pVIC = new BYTE[cbVIC]; - - if (pVIC) - { - hr = E_FAIL; - - BYTE *pPos = pVIC; - const BYTE *pEnd = pVIC + cbVIC; - - if ((pPos + sizeof(cGroup)) <= pEnd) - { - // count of groups - memcpy(pPos, &cGroup, sizeof(cGroup)); - pPos+=sizeof(cGroup); - - if ((pPos + sizeof(PROPERTYKEY)) <= pEnd) - { - // Change Unit Identifier - memcpy(pPos, &WPD_PROPERTY_NULL, sizeof(PROPERTYKEY)); - pPos+=sizeof(PROPERTYKEY); - - if ((pPos + sizeof(cVIC)) <= pEnd) - { - // Number of items in the change unit - memcpy(pPos, &cVIC, sizeof(cVIC)); - pPos+=sizeof(cVIC); - - // Change Unit Property List - DWORD i = 0; - while ((i < cVIC) && (pPos + sizeof(PROPERTYKEY) <= pEnd)) - { - memcpy(pPos, g_ContactsServiceChangeUnit[i], sizeof(PROPERTYKEY)); - pPos+=sizeof(PROPERTYKEY); - i++; - } - - if ((pPos == pEnd) && (i == cVIC)) - { - // All done - hr = pStore->SetBufferValue(PKEY_FullEnumSyncSvc_VersionProps, pVIC, cbVIC); - } - } - } - } - delete [] pVIC; - } - - CHECK_HR(hr, "Failed to copy the PKEY_FullEnumSyncSvc_VersionProps data to IPortableDeviceValues"); - return hr; -} - -HRESULT FakeContactsServiceContent::WriteValue( - _In_ REFPROPERTYKEY Key, - _In_ REFPROPVARIANT Value) -{ - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - if(Value.vt == VT_LPWSTR) - { - if (Value.pwszVal != NULL && Value.pwszVal[0] != L'\0') - { - Name = Value.pwszVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME because value was an empty string"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME because type (%d) was not VT_LPWSTR", Value.vt); - } - } - else if(IsEqualPropertyKey(Key, PKEY_FullEnumSyncSvc_LocalOnlyDelete)) - { - if(Value.vt == VT_UI1) - { - LocalOnlyDelete = Value.bVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set PKEY_FullEnumSyncSvc_LocalOnlyDelete because type (%d) was not VT_UI1", Value.vt); - } - } - else if(IsEqualPropertyKey(Key, PKEY_FullEnumSyncSvc_FilterType)) - { - if(Value.vt == VT_UI1) - { - FilterType = Value.bVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set PKEY_FullEnumSyncSvc_FilterType because type (%d) was not VT_UI1", Value.vt); - } - } - else if(IsEqualPropertyKey(Key, PKEY_FullEnumSyncSvc_ReplicaID)) - { - if(Value.vt == (VT_VECTOR | VT_UI1) && Value.caub.cElems == sizeof(ReplicaId)) - { - CopyMemory(&ReplicaId, Value.caub.pElems, sizeof(ReplicaId)); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set PKEY_FullEnumSyncSvc_FilterType because type (%d) was not VT_VECTOR | VT_UI1", Value.vt); - } - } - else - { - hr = E_ACCESSDENIED; - CHECK_HR(hr, "Property %ws.%d on [%ws] does not support set value operation", CComBSTR(Key.fmtid), Key.pid, ObjectID); - } - - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/FakeContactsServiceContent.h b/wpd/WpdServiceSampleDriver/FakeContactsServiceContent.h deleted file mode 100644 index e7dbee0e..00000000 --- a/wpd/WpdServiceSampleDriver/FakeContactsServiceContent.h +++ /dev/null @@ -1,92 +0,0 @@ -#pragma once - -/** - * This class represents an abstraction of a contacts service content object - * Driver implementors should replace this with their own - * device I/O classes/libraries. - */ - -#define CONTACTS_SERVICE_OBJECT_ID L"789DEF" -#define CONTACTS_SERVICE_PERSISTENT_UNIQUE_ID L"{95A95EA9-9904-430E-8FF6-70851F208478}" -#define CONTACTS_SERVICE_OBJECT_NAME_VALUE NAME_ContactsSvc -#define CONTACTS_SERVICE_HUMAN_READABLE_NAME L"Hello World Phone Contacts" -#define CONTACTS_SERVICE_PREFERRED_FORMAT WPD_OBJECT_FORMAT_ABSTRACT_CONTACT -#define CONTACTS_SERVICE_VERSION L"1.0" -#define CONTACTS_SERVICE_LOCAL_ONLY_DELETE 1 - -#define NUM_CONTACT_OBJECTS 10 - -class FakeContactsServiceContent : public FakeContent -{ -public: - FakeContactsServiceContent() - { - ObjectID = CONTACTS_SERVICE_OBJECT_ID; - PersistentUniqueID = CONTACTS_SERVICE_PERSISTENT_UNIQUE_ID; - ParentID = WPD_DEVICE_OBJECT_ID; - Name = CONTACTS_SERVICE_OBJECT_NAME_VALUE; - ContentType = WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT; - Format = WPD_OBJECT_FORMAT_UNSPECIFIED; - ParentPersistentUniqueID = WPD_DEVICE_OBJECT_ID; - ContainerFunctionalObjectID = WPD_DEVICE_OBJECT_ID; - - Version = CONTACTS_SERVICE_VERSION; - FunctionalCategory = SERVICE_Contacts; - HumanReadableName = CONTACTS_SERVICE_HUMAN_READABLE_NAME; - PreferredSyncFormat = CONTACTS_SERVICE_PREFERRED_FORMAT; - RequiredScope = CONTACTS_SERVICE_ACCESS; - LocalOnlyDelete = CONTACTS_SERVICE_LOCAL_ONLY_DELETE; - FilterType = SYNCSVC_FILTER_CONTACTS_WITH_PHONE; - CopyMemory(&ReplicaId, &MyFullEnumSyncReplicaId, sizeof(ReplicaId)); - } - - FakeContactsServiceContent(const FakeContent& src) - { - *this = src; - } - - virtual ~FakeContactsServiceContent() - { - } - - virtual HRESULT InitializeContent( - _Inout_ DWORD *pdwLastObjectID); - - virtual HRESULT CreatePropertiesOnlyObject( - _In_ IPortableDeviceValues* pObjectProperties, - _Out_ DWORD* pdwLastObjectID, - _Outptr_result_nullonfailure_ FakeContent** ppNewObject); - - virtual HRESULT GetSupportedProperties( - _In_ IPortableDeviceKeyCollection *pKeys); - - virtual HRESULT GetPropertyAttributes( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes); - - virtual HRESULT GetValue( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pStore); - - virtual HRESULT WriteValue( - _In_ REFPROPERTYKEY Key, - _In_ REFPROPVARIANT Value); - -private: - HRESULT GetIconData( - _In_ IPortableDeviceValues* pStore); - - HRESULT GetVICData( - _In_ IPortableDeviceValues* pStore); - -public: - CAtlStringW Version; - CAtlStringW HumanReadableName; - - GUID FunctionalCategory; - GUID PreferredSyncFormat; - GUID ReplicaId; - - BYTE LocalOnlyDelete; - BYTE FilterType; -}; diff --git a/wpd/WpdServiceSampleDriver/FakeContent.cpp b/wpd/WpdServiceSampleDriver/FakeContent.cpp deleted file mode 100644 index 96139791..00000000 --- a/wpd/WpdServiceSampleDriver/FakeContent.cpp +++ /dev/null @@ -1,635 +0,0 @@ -#include "stdafx.h" -#include "FakeContent.tmh" - -HRESULT FakeContent::InitializeContent(_Inout_ DWORD *pdwLastObjectID) -{ - UNREFERENCED_PARAMETER(pdwLastObjectID); - return S_OK; -} - -HRESULT FakeContent::InitializeEnumerationContext( - ACCESS_SCOPE Scope, - _In_ WpdObjectEnumeratorContext* pEnumeratorContext) -{ - HRESULT hr = S_OK; - UNREFERENCED_PARAMETER(Scope); - - if (pEnumeratorContext == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - pEnumeratorContext->m_TotalChildren = static_cast<DWORD>(m_Children.GetCount()); - return hr; -} - -HRESULT FakeContent::GetSupportedProperties(_In_ IPortableDeviceKeyCollection *pKeys) -{ - HRESULT hr = S_OK; - - if(pKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - hr = pKeys->Add(WPD_OBJECT_ID); - CHECK_HR(hr, "Failed to add WPD_OBJECT_ID"); - - if (hr == S_OK) - { - hr = pKeys->Add(WPD_OBJECT_PERSISTENT_UNIQUE_ID); - CHECK_HR(hr, "Failed to add WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - - if (hr == S_OK) - { - hr = pKeys->Add(WPD_OBJECT_PARENT_ID); - CHECK_HR(hr, "Failed to add WPD_OBJECT_PARENT_ID"); - } - - if (hr == S_OK) - { - hr = pKeys->Add(WPD_OBJECT_NAME); - CHECK_HR(hr, "Failed to add WPD_OBJECT_NAME"); - } - - if (hr == S_OK) - { - hr = pKeys->Add(WPD_OBJECT_CONTENT_TYPE); - CHECK_HR(hr, "Failed to add WPD_OBJECT_CONTENT_TYPE"); - } - - if (hr == S_OK) - { - hr = pKeys->Add(WPD_OBJECT_FORMAT); - CHECK_HR(hr, "Failed to add WPD_OBJECT_FORMAT"); - } - - if (hr == S_OK) - { - hr = pKeys->Add(WPD_OBJECT_CAN_DELETE); - CHECK_HR(hr, "Failed to add WPD_OBJECT_CAN_DELETE"); - } - - return hr; -} - -HRESULT FakeContent::GetPropertyAttributes( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if(pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_DELETE"); - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_READ"); - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_WRITE, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_WRITE"); - } - else - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_WRITE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_WRITE"); - } - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_FORM, WPD_PROPERTY_ATTRIBUTE_FORM_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FORM"); - } - - return hr; -} - -HRESULT FakeContent::GetValue( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pStore) -{ - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - // Add WPD_OBJECT_ID - pvValue = ObjectID; - hr = pStore->SetValue(WPD_OBJECT_ID, &pvValue); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_ID")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - // Add WPD_OBJECT_PERSISTENT_UNIQUE_ID - pvValue = this->PersistentUniqueID; - hr = pStore->SetValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, &pvValue); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - // Add WPD_OBJECT_PARENT_ID - pvValue = ParentID; - hr = pStore->SetValue(WPD_OBJECT_PARENT_ID, &pvValue); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_PARENT_ID")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - // Add WPD_OBJECT_NAME - pvValue = Name; - hr = pStore->SetValue(WPD_OBJECT_NAME, &pvValue); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_NAME")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - // Add WPD_OBJECT_CONTENT_TYPE - hr = pStore->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, ContentType); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_CONTENT_TYPE")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - // Add WPD_OBJECT_FORMAT - hr = pStore->SetGuidValue(WPD_OBJECT_FORMAT, Format); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_FORMAT")); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - // Add WPD_OBJECT_CAN_DELETE - hr = pStore->SetBoolValue(WPD_OBJECT_CAN_DELETE, CanDelete); - CHECK_HR(hr, ("Failed to set WPD_OBJECT_CAN_DELETE")); - } - else - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - CHECK_HR(hr, "Property {%ws}.%d is not supported", CComBSTR(Key.fmtid), Key.pid); - } - return hr; -} - -HRESULT FakeContent::WriteValue( - _In_ REFPROPERTYKEY Key, - _In_ REFPROPVARIANT Value) -{ - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - if(Value.vt == VT_LPWSTR) - { - if (Value.pwszVal != NULL && Value.pwszVal[0] != L'\0') - { - Name = Value.pwszVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME because value was an empty string"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME because type was not VT_LPWSTR"); - } - } - else - { - hr = E_ACCESSDENIED; - CHECK_HR(hr, "Property %ws.%d on [%ws] does not support set value operation", CComBSTR(Key.fmtid), Key.pid, ObjectID); - } - - return hr; -} - -HRESULT FakeContent::CreatePropertiesOnlyObject( - _In_ IPortableDeviceValues* pObjectProperties, - _Out_ DWORD* pdwLastObjectID, - _Outptr_result_nullonfailure_ FakeContent** ppNewObject) -{ - UNREFERENCED_PARAMETER(pObjectProperties); - UNREFERENCED_PARAMETER(pdwLastObjectID); - *ppNewObject = NULL; - return E_ACCESSDENIED; -} - -HRESULT FakeContent::GetSupportedResources( - _In_ IPortableDeviceKeyCollection* pResources) -{ - UNREFERENCED_PARAMETER(pResources); - return S_OK; -} - -HRESULT FakeContent::GetResourceAttributes( - _In_ REFPROPERTYKEY Resource, - _In_ IPortableDeviceValues* pAttributes) -{ - UNREFERENCED_PARAMETER(Resource); - UNREFERENCED_PARAMETER(pAttributes); - return S_OK; -} - -HRESULT FakeContent::OpenResource( - _In_ REFPROPERTYKEY Resource, - const DWORD dwMode, - _In_ WpdObjectResourceContext* pResourceContext) -{ - UNREFERENCED_PARAMETER(Resource); - UNREFERENCED_PARAMETER(dwMode); - UNREFERENCED_PARAMETER(pResourceContext); - return S_OK; -} - -HRESULT FakeContent::ReadResourceData( - _In_ WpdObjectResourceContext* pResourceContext, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - const DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) -{ - UNREFERENCED_PARAMETER(pResourceContext); - UNREFERENCED_PARAMETER(pBuffer); - UNREFERENCED_PARAMETER(dwNumBytesToRead); - *pdwNumBytesRead = 0; - return S_OK; -} - -bool FakeContent::CanAccess( - ACCESS_SCOPE Scope) -{ - return ((Scope & RequiredScope) == RequiredScope); -} - -HRESULT FakeContent::GetAllValues( - _In_ IPortableDeviceValues* pStore) -{ - HRESULT hr = S_OK; - DWORD cKeys = 0; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // CoCreate a collection to store the property keys we are going to use - // to request the property values of. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - if (hr == S_OK) - { - hr = GetSupportedProperties(pKeys); - CHECK_HR(hr, "Failed to get supported properties"); - } - - if (hr == S_OK) - { - hr = pKeys->GetCount(&cKeys); - CHECK_HR(hr, "Failed to get supported properties"); - } - - if (hr == S_OK) - { - for (DWORD i=0; i<cKeys; i++) - { - PROPERTYKEY Key = {0}; - hr = pKeys->GetAt(i, &Key); - CHECK_HR(hr, "Failed to get supported property at index %d", i); - if (hr == S_OK) - { - hr = GetValue(Key, pStore); - CHECK_HR(hr, "Failed to get property value at index %d", i); - } - } - } - - return hr; -} - -HRESULT FakeContent::WriteValues( - _In_ IPortableDeviceValues* pValues, - _In_ IPortableDeviceValues* pResults, - _Out_ bool* pbObjectChanged) -{ - HRESULT hr = S_OK; - DWORD cValues = 0; - bool hasFailedWrite = false; - - if (pValues == NULL || pResults == NULL || pbObjectChanged == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = pValues->GetCount(&cValues); - CHECK_HR(hr, "Failed to get total number of values"); - - (*pbObjectChanged) = false; - - for (DWORD dwIndex = 0; dwIndex < cValues; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - PROPVARIANT Value; - PropVariantInit(&Value); - - hr = pValues->GetAt(dwIndex, &Key, &Value); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d", dwIndex); - - if (hr == S_OK) - { - HRESULT hrWrite = WriteValue(Key, Value); - if (FAILED(hrWrite)) - { - CHECK_HR(hrWrite, "Failed to write value at index %d", dwIndex); - hasFailedWrite = true; - } - else - { - (*pbObjectChanged) = true; - } - - hr = pResults->SetErrorValue(Key, hrWrite); - CHECK_HR(hr, "Failed to set error result value at index %d", dwIndex); - } - - PropVariantClear(&Value); - } - - // Since we have set failures for the property set operations we must let the application - // know by returning S_FALSE. This will instruct the application to look at the - // property set operation results for failure values. - if ((hr == S_OK) && hasFailedWrite) - { - hr = S_FALSE; - } - - return hr; -} - -_Success_(return) -bool FakeContent::FindNext( - ACCESS_SCOPE Scope, - const DWORD dwIndex, - _Outptr_result_nullonfailure_ FakeContent** ppChild) -{ - HRESULT hr = S_OK; - bool bFound = false; - - if (ppChild == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return false; - } - - *ppChild = NULL; - - if (dwIndex < m_Children.GetCount()) - { - if (m_Children[dwIndex] && (m_Children[dwIndex]->CanAccess(Scope))) - { - *ppChild = m_Children[dwIndex]; - bFound = true; - } - } - - return bFound; -} - -HRESULT FakeContent::GetContent( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _Outptr_result_nullonfailure_ FakeContent** ppContent) -{ - HRESULT hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); - *ppContent = NULL; - - if (CanAccess(Scope)) - { - if (ObjectID.CompareNoCase(wszObjectID) == 0) - { - hr = S_OK; - *ppContent = this; - } - else - { - DWORD dwIndex = 0; - FakeContent* pChild = NULL; - while (FindNext(Scope, dwIndex, &pChild)) - { - hr = pChild->GetContent(Scope, wszObjectID, ppContent); - if (hr == S_OK || hr == E_ACCESSDENIED) - { - break; - } - dwIndex++; - } - } - } - else - { - hr = E_ACCESSDENIED; - CHECK_HR(hr, "GetContent: '%ws' was found but falls outside scope", wszObjectID); - } - - return hr; -} - -HRESULT FakeContent::GetObjectIDsByFormat( - ACCESS_SCOPE Scope, - _In_ REFGUID guidFormat, - const DWORD dwDepth, - _In_ IPortableDevicePropVariantCollection* pObjectIDs) -{ - HRESULT hr = S_OK; - - if (CanAccess(Scope)) - { - DWORD dwIndex = 0; - FakeContent* pChild = NULL; - - if (Format == guidFormat || guidFormat == WPD_OBJECT_FORMAT_ALL) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - pv.vt = VT_LPWSTR; - pv.pwszVal = ObjectID.GetBuffer(); - hr = pObjectIDs->Add(&pv); - CHECK_HR(hr, "Failed to add '%ws' to the list of object IDs by format", ObjectID); - } - - if (dwDepth > 0) - { - while ((hr == S_OK) && (FindNext(Scope, dwIndex, &pChild))) - { - hr = pChild->GetObjectIDsByFormat(Scope, guidFormat, dwDepth-1, pObjectIDs); - CHECK_HR(hr, "Failed to get object IDs by format for child at index %d", dwIndex); - dwIndex++; - } - } - } - else - { - hr = E_ACCESSDENIED; - } - - return hr; -} - -HRESULT FakeContent::GetObjectIDByPersistentID( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszPersistentID, - _In_ IPortableDevicePropVariantCollection* pObjectIDs) -{ - HRESULT hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); - - if (CanAccess(Scope)) - { - if (PersistentUniqueID.CompareNoCase(wszPersistentID) == 0) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - pv.vt = VT_LPWSTR; - pv.pwszVal = ObjectID.GetBuffer(); - - hr = pObjectIDs->Add(&pv); - CHECK_HR(hr, "Failed to add '%ws' to the list of object IDs", ObjectID); - } - else - { - DWORD dwIndex = 0; - FakeContent* pChild = NULL; - while (FindNext(Scope, dwIndex, &pChild)) - { - hr = pChild->GetObjectIDByPersistentID(Scope, wszPersistentID, pObjectIDs); - if (hr == S_OK || hr == E_ACCESSDENIED) - { - // Found the object or was denied access - break; - } - else if (hr != HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) - { - CHECK_HR(hr, "Failed to get object ID for child at index %d", dwIndex); - } - dwIndex++; - } - } - } - else - { - hr = E_ACCESSDENIED; - } - - return hr; -} - -HRESULT FakeContent::MarkForDelete( - const DWORD dwOptions) -{ - HRESULT hr = S_OK; - - if (CanDelete == false) - { - hr = E_ACCESSDENIED; - CHECK_HR(hr, "Object '%ws' is not deletable", ObjectID); - return hr; - } - - if (dwOptions == PORTABLE_DEVICE_DELETE_NO_RECURSION) - { - if (m_Children.GetCount() > 0) - { - hr = HRESULT_FROM_WIN32(ERROR_DIR_NOT_EMPTY); - } - } - else if (dwOptions == PORTABLE_DEVICE_DELETE_WITH_RECURSION) - { - // Mark children for delete - for (size_t Index = 0; Index < m_Children.GetCount(); Index++) - { - if (m_Children[Index]) - { - hr = m_Children[Index]->MarkForDelete(dwOptions); - CHECK_HR(hr, "Failed to mark child '%ws' for deletion", m_Children[Index]->ObjectID); - } - } - } - - if (hr == S_OK) - { - // All successful. Mark self for delete - MarkedForDeletion = true; - } - - return hr; -} - -HRESULT FakeContent::RemoveObjectsMarkedForDeletion( - ACCESS_SCOPE Scope) -{ - HRESULT hr = S_OK; - DWORD dwIndex = 0; - FakeContent* pChild = NULL; - - while (FindNext(Scope, dwIndex, &pChild)) - { - if (pChild != NULL) - { - hr = pChild->RemoveObjectsMarkedForDeletion(Scope); - CHECK_HR(hr, "Failed to remove children marked for deletion for object '%ws'", pChild->ObjectID); - - if ((hr == S_OK) && (pChild->MarkedForDeletion == true)) - { - m_Children.RemoveAt(dwIndex); - delete pChild; - pChild = NULL; - } - } - dwIndex++; - } - - m_Children.FreeExtra(); - - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/FakeContent.h b/wpd/WpdServiceSampleDriver/FakeContent.h deleted file mode 100644 index 3f1f7103..00000000 --- a/wpd/WpdServiceSampleDriver/FakeContent.h +++ /dev/null @@ -1,151 +0,0 @@ -#pragma once - -class FakeContent -{ -public: - FakeContent() : - CanDelete(false), - RequiredScope(FULL_DEVICE_ACCESS), - MarkedForDeletion(false) - { - Format = WPD_OBJECT_FORMAT_UNSPECIFIED; - ContentType = WPD_CONTENT_TYPE_UNSPECIFIED; - } - - FakeContent(const FakeContent& src) : - CanDelete(false) - { - *this = src; - } - - virtual ~FakeContent() - { - for(size_t index = 0; index < m_Children.GetCount(); index++) - { - if (m_Children[index]) - { - delete(m_Children[index]); - m_Children[index] = NULL; - } - } - m_Children.RemoveAll(); - } - - virtual FakeContent& operator= (const FakeContent& src) - { - ObjectID = src.ObjectID; - PersistentUniqueID = src.PersistentUniqueID; - ParentID = src.ParentID; - Name = src.Name; - ContentType = src.ContentType; - Format = src.Format; - CanDelete = src.CanDelete; - RequiredScope = src.RequiredScope; - ParentPersistentUniqueID = src.ParentPersistentUniqueID; - ContainerFunctionalObjectID = src.ContainerFunctionalObjectID; - - return *this; - } - - virtual HRESULT InitializeContent( - _Inout_ DWORD *pdwLastObjectID); - - virtual HRESULT InitializeEnumerationContext( - ACCESS_SCOPE Scope, - _In_ WpdObjectEnumeratorContext* pEnumeratorContext); - - virtual HRESULT GetSupportedProperties( - _In_ IPortableDeviceKeyCollection *pKeys); - - virtual HRESULT GetPropertyAttributes( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes); - - virtual HRESULT GetValue( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pStore); - - virtual HRESULT WriteValue( - _In_ REFPROPERTYKEY Key, - _In_ REFPROPVARIANT Value); - - virtual HRESULT CreatePropertiesOnlyObject( - _In_ IPortableDeviceValues* pObjectProperties, - _Out_ DWORD* pdwLastObjectID, - _Outptr_result_nullonfailure_ FakeContent** ppNewObject); - - virtual HRESULT GetSupportedResources( - _In_ IPortableDeviceKeyCollection* pResources); - - virtual HRESULT GetResourceAttributes( - _In_ REFPROPERTYKEY Resource, - _In_ IPortableDeviceValues* pAttributes); - - virtual HRESULT OpenResource( - _In_ REFPROPERTYKEY Resource, - const DWORD dwMode, - _In_ WpdObjectResourceContext* pResourceContext); - - virtual HRESULT ReadResourceData( - _In_ WpdObjectResourceContext* pResourceContext, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - const DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead); - - virtual HRESULT WriteValues( - _In_ IPortableDeviceValues* pValues, - _In_ IPortableDeviceValues* pResults, - _Out_ bool* pbObjectChanged); - -public: - bool CanAccess( - ACCESS_SCOPE Scope); - - HRESULT GetAllValues( - _In_ IPortableDeviceValues* pStore); - - _Success_(return) - bool FindNext( - ACCESS_SCOPE Scope, - const DWORD dwIndex, - _Outptr_result_nullonfailure_ FakeContent** ppChild); - - HRESULT GetContent( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _Outptr_result_nullonfailure_ FakeContent** ppContent); - - HRESULT GetObjectIDsByFormat( - ACCESS_SCOPE Scope, - _In_ REFGUID Format, - const DWORD dwDepth, - _In_ IPortableDevicePropVariantCollection* pObjectIDs); - - HRESULT GetObjectIDByPersistentID( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszPersistentID, - _In_ IPortableDevicePropVariantCollection* pObjectIDs); - - HRESULT MarkForDelete( - const DWORD dwOptions); - - HRESULT RemoveObjectsMarkedForDeletion( - ACCESS_SCOPE Scope); - -public: - CAtlStringW ObjectID; - CAtlStringW PersistentUniqueID; - CAtlStringW ParentID; - CAtlStringW Name; - CAtlStringW ParentPersistentUniqueID; - CAtlStringW ContainerFunctionalObjectID; - GUID ContentType; - GUID Format; - bool CanDelete; - bool MarkedForDeletion; - - // A bitmask of all the required scopes in order to access this object - ACCESS_SCOPE RequiredScope; - - CAtlArray<FakeContent*> m_Children; -}; diff --git a/wpd/WpdServiceSampleDriver/FakeDevice.cpp b/wpd/WpdServiceSampleDriver/FakeDevice.cpp deleted file mode 100644 index d5f8d4d4..00000000 --- a/wpd/WpdServiceSampleDriver/FakeDevice.cpp +++ /dev/null @@ -1,1122 +0,0 @@ -#include "stdafx.h" - -#include "FakeDevice.tmh" - -const PROPERTYKEY* g_SupportedCommands[] = -{ - // WPD_CATEGORY_OBJECT_ENUMERATION - &WPD_COMMAND_OBJECT_ENUMERATION_START_FIND, - &WPD_COMMAND_OBJECT_ENUMERATION_FIND_NEXT, - &WPD_COMMAND_OBJECT_ENUMERATION_END_FIND, - - // WPD_CATEGORY_OBJECT_PROPERTIES - &WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED, - &WPD_COMMAND_OBJECT_PROPERTIES_GET, - &WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL, - &WPD_COMMAND_OBJECT_PROPERTIES_SET, - &WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES, - &WPD_COMMAND_OBJECT_PROPERTIES_DELETE, - - // WPD_CATEGORY_OBJECT_RESOURCES - &WPD_COMMAND_OBJECT_RESOURCES_GET_SUPPORTED, - &WPD_COMMAND_OBJECT_RESOURCES_OPEN, - &WPD_COMMAND_OBJECT_RESOURCES_READ, - &WPD_COMMAND_OBJECT_RESOURCES_CLOSE, - &WPD_COMMAND_OBJECT_RESOURCES_GET_ATTRIBUTES, - - // WPD_CATEGORY_CAPABILITIES - &WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS, - &WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS, - &WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES, - &WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS, - &WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES, - &WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS, - &WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES, - &WPD_COMMAND_CAPABILITIES_GET_FIXED_PROPERTY_ATTRIBUTES, - - // WPD_CATEGORY_OBJECT_MANAGEMENT - &WPD_COMMAND_OBJECT_MANAGEMENT_CREATE_OBJECT_WITH_PROPERTIES_ONLY, - &WPD_COMMAND_OBJECT_MANAGEMENT_DELETE_OBJECTS, - - // WPD_CATEGORY_OBJECT_PROPERTIES_BULK - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_START, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_NEXT, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_END, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_START, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_NEXT, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_END, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_START, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_NEXT, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_END, - - // WPD_CATEGORY_COMMON - &WPD_COMMAND_COMMON_GET_OBJECT_IDS_FROM_PERSISTENT_UNIQUE_IDS, -}; - - -const GUID* g_SupportedFunctionalCategories[] = -{ - &WPD_FUNCTIONAL_CATEGORY_DEVICE, - &WPD_FUNCTIONAL_CATEGORY_STORAGE, - &SERVICE_Contacts, -}; - -const PROPERTYKEY* g_SupportedCommonProperties[] = -{ - &WPD_OBJECT_ID, - &WPD_OBJECT_PERSISTENT_UNIQUE_ID, - &WPD_OBJECT_PARENT_ID, - &WPD_OBJECT_NAME, - &WPD_OBJECT_FORMAT, - &WPD_OBJECT_CONTENT_TYPE, - &WPD_OBJECT_CAN_DELETE, - &WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, -}; - - -HRESULT FakeDevice::InitializeContent() -{ - HRESULT hr = m_DeviceContent.InitializeContent(&m_dwLastObjectID); - CHECK_HR(hr, "Failed to initialize device content"); - return hr; -} - -FakeContactsService* FakeDevice::GetContactsService() -{ - return &m_ContactsService; -} - -ACCESS_SCOPE FakeDevice::GetAccessScope( - _In_ IPortableDeviceValues* pParams) -{ - ACCESS_SCOPE Scope = FULL_DEVICE_ACCESS; - LPWSTR pszFileName = NULL; - - // For simplicity, our request filename is the same as the the service object ID - if (pParams && (pParams->GetStringValue(PRIVATE_SAMPLE_DRIVER_REQUEST_FILENAME, &pszFileName) == S_OK)) - { - CAtlStringW strRequestFilename = pszFileName; - // For simplicity, our request filename is the same as the the service object ID - // Case-insensitive comparison is required - if (strRequestFilename.CompareNoCase(m_ContactsService.GetRequestFilename()) == 0) - { - Scope = CONTACTS_SERVICE_ACCESS; - } - } - - CoTaskMemFree(pszFileName); - return Scope; -} - -HRESULT FakeDevice::GetSupportedCommands( - _In_ IPortableDeviceKeyCollection* pCommands) -{ - HRESULT hr = S_OK; - - if(pCommands == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedCommands); dwIndex++) - { - PROPERTYKEY key = *(g_SupportedCommands[dwIndex]); - hr = pCommands->Add(key); - CHECK_HR(hr, "Failed to add supported command at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - return hr; -} - -HRESULT FakeDevice::GetCommandOptions( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pOptions) -{ - HRESULT hr = S_OK; - - if(pOptions == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Check for command options - if (IsEqualPropertyKey(WPD_COMMAND_OBJECT_MANAGEMENT_DELETE_OBJECTS, Command)) - { - // This driver does not support recursive deletion - hr = pOptions->SetBoolValue(WPD_OPTION_OBJECT_MANAGEMENT_RECURSIVE_DELETE_SUPPORTED, TRUE); - CHECK_HR(hr, "Failed to set WPD_OPTION_OBJECT_MANAGEMENT_RECURSIVE_DELETE_SUPPORTED"); - } - if (IsEqualPropertyKey(WPD_COMMAND_OBJECT_RESOURCES_READ, Command)) - { - // For better read performance, tell the API not to provide the input buffer parameter - // when issuing a WPD_COMMAND_OBJECT_RESOURCES_READ command. - hr = pOptions->SetBoolValue(WPD_OPTION_OBJECT_RESOURCES_NO_INPUT_BUFFER_ON_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_OPTION_OBJECT_RESOURCES_NO_INPUT_BUFFER_ON_READ"); - } - - return hr; -} - -HRESULT FakeDevice::GetSupportedFunctionalCategories( - _In_ IPortableDevicePropVariantCollection* pFunctionalCategories) -{ - HRESULT hr = S_OK; - - if(pFunctionalCategories == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Device-wide command - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedFunctionalCategories); dwIndex++) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - // Don't call PropVariantClear, since we did not allocate the memory for these GUIDs - - pv.vt = VT_CLSID; - pv.puuid = (CLSID*)g_SupportedFunctionalCategories[dwIndex]; - - hr = pFunctionalCategories->Add(&pv); - CHECK_HR(hr, "Failed to add supported functional category at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - - return hr; -} - -HRESULT FakeDevice::GetFunctionalObjects( - _In_ REFGUID guidFunctionalCategory, - _In_ IPortableDevicePropVariantCollection* pFunctionalObjects) -{ - HRESULT hr = S_OK; - PROPVARIANT pv = {0}; - - if(pFunctionalObjects == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - PropVariantInit(&pv); - // Don't call PropVariantClear, since we did not allocate the memory for these object identifiers - - // Add WPD_DEVICE_OBJECT_ID to the functional object identifiers collection - if ((guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_DEVICE) || - (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_ALL)) - { - pv.vt = VT_LPWSTR; - pv.pwszVal = WPD_DEVICE_OBJECT_ID; - hr = pFunctionalObjects->Add(&pv); - CHECK_HR(hr, "Failed to add device object ID"); - } - - // Add CONTACTS_SERVICE_OBJECT_ID to the functional object identifiers collection - if (hr == S_OK) - { - if ((guidFunctionalCategory == SERVICE_Contacts) || - (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_ALL)) - { - pv.vt = VT_LPWSTR; - pv.pwszVal = CONTACTS_SERVICE_OBJECT_ID; - hr = pFunctionalObjects->Add(&pv); - CHECK_HR(hr, "Failed to add contacts service object ID"); - } - } - - // Add STORAGE_OBJECT_ID to the functional object identifiers collection - // if request is not scoped by the contacts service - if ((guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_STORAGE) || - (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_ALL)) - { - pv.vt = VT_LPWSTR; - pv.pwszVal = STORAGE_OBJECT_ID; - hr = pFunctionalObjects->Add(&pv); - CHECK_HR(hr, "Failed to add storage object ID"); - } - - return hr; -} - -HRESULT FakeDevice::GetSupportedContentTypes( - _In_ REFGUID guidFunctionalCategory, - _In_ IPortableDevicePropVariantCollection* pContentTypes) -{ - HRESULT hr = S_OK; - - if(pContentTypes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - // Don't call PropVariantClear, since we did not allocate the memory for these GUIDs - - // Add supported content types for known functional categories - if (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_STORAGE) - { - // Add WPD_CONTENT_TYPE_DOCUMENT to the supported content type collection - pv.vt = VT_CLSID; - pv.puuid = (CLSID*)&WPD_CONTENT_TYPE_DOCUMENT; - hr = pContentTypes->Add(&pv); - CHECK_HR(hr, "Failed to add WPD_CONTENT_TYPE_DOCUMENT"); - - if (hr == S_OK) - { - // Add WPD_CONTENT_TYPE_FOLDER to the supported content type collection - pv.vt = VT_CLSID; - pv.puuid = (CLSID*)&WPD_CONTENT_TYPE_FOLDER; - hr = pContentTypes->Add(&pv); - CHECK_HR(hr, "Failed to add WPD_CONTENT_TYPE_FOLDER"); - } - } - - return hr; -} - -HRESULT FakeDevice::GetSupportedFormats( - _In_ REFGUID guidContentType, - _In_ IPortableDevicePropVariantCollection* pFormats) -{ - HRESULT hr = S_OK; - - if(pFormats == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - pv.vt = VT_CLSID; - - // Don't call PropVariantClear, since we did not allocate the memory for these GUIDs - - if ((guidContentType == WPD_CONTENT_TYPE_CONTACT) || - (guidContentType == WPD_CONTENT_TYPE_ALL)) - { - pv.puuid = (CLSID*)&FORMAT_AbstractContact; - hr = pFormats->Add(&pv); - CHECK_HR(hr, "Failed to add FORMAT_AbstractContact"); - - pv.puuid = (CLSID*)&FORMAT_VCard2Contact; - hr = pFormats->Add(&pv); - CHECK_HR(hr, "Failed to add FORMAT_VCard2Contact"); - } - - return hr; -} - -HRESULT FakeDevice::GetSupportedFormatProperties( - _In_ REFGUID guidObjectFormat, - _In_ IPortableDeviceKeyCollection* pKeys) -{ - HRESULT hr = S_OK; - - if(pKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - if (guidObjectFormat == WPD_OBJECT_FORMAT_ALL) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedCommonProperties); dwIndex++) - { - PROPERTYKEY key = *g_SupportedCommonProperties[dwIndex]; - hr = pKeys->Add(key); - CHECK_HR(hr, "Failed to add common property"); - } - } - - return hr; -} - -HRESULT FakeDevice::GetFixedPropertyAttributes( - _In_ REFGUID guidObjectFormat, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes) -{ - UNREFERENCED_PARAMETER(guidObjectFormat); - UNREFERENCED_PARAMETER(Key); - - HRESULT hr = S_OK; - - if(pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // - // Since ALL of our properties have the same attributes, we are ignoring the - // passed in guidObjectFormat and Key parameters. These parameters allow you to - // customize fixed property attributes for properties for specific formats. - // - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_DELETE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_READ"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_WRITE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_WRITE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_FORM, WPD_PROPERTY_ATTRIBUTE_FORM_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FORM"); - } - - return hr; -} - -HRESULT FakeDevice::GetSupportedEvents( - _In_ IPortableDevicePropVariantCollection* pEvents) -{ - UNREFERENCED_PARAMETER(pEvents); - - HRESULT hr = S_OK; - - if(pEvents == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - return hr; -} - -HRESULT FakeDevice::GetEventOptions( - _In_ IPortableDeviceValues* pOptions) -{ - UNREFERENCED_PARAMETER(pOptions); - - HRESULT hr = S_OK; - - if(pOptions == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - return hr; -} - -void FakeDevice::InitializeEnumerationContext( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszParentID, - _In_ WpdObjectEnumeratorContext* pEnumContext) -{ - if (pEnumContext == NULL) - { - return; - } - - pEnumContext->m_Scope = Scope; - pEnumContext->m_strParentObjectID = wszParentID; - - if (pEnumContext->m_strParentObjectID.GetLength() == 0) - { - // Clients passing an 'empty' string for the parent are asking for the - // 'DEVICE' object. We should return 1 child in this case. - pEnumContext->m_TotalChildren = 1; - } - else - { - FakeContent* pContent = NULL; - HRESULT hr = GetContent(Scope, wszParentID, &pContent); - if (hr == S_OK) - { - hr = pContent->InitializeEnumerationContext(Scope, pEnumContext); - CHECK_HR(hr, "Failed to initialize enuemration context for '%ws'", wszParentID); - } - - if (hr != S_OK) - { - // Invalid, or non-existing objects contain no children. - pEnumContext->m_TotalChildren = 0; - } - } -} - -HRESULT FakeDevice::FindNext( - const DWORD dwNumObjectsRequested, - _In_ WpdObjectEnumeratorContext* pEnumContext, - _In_ IPortableDevicePropVariantCollection* pObjectIDCollection, - _Out_opt_ DWORD* pdwNumObjectsEnumerated) -{ - HRESULT hr = S_OK; - DWORD NumObjectsEnumerated = 0; - - if ((pEnumContext == NULL) || - (pObjectIDCollection == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - if (pdwNumObjectsEnumerated) - { - *pdwNumObjectsEnumerated = 0; - } - - // If the enumeration context reports that their are more objects to return, then continue, if not, - // return an empty results set. - if (pEnumContext->HasMoreChildrenToEnumerate()) - { - if (pEnumContext->m_strParentObjectID.CompareNoCase(L"") == 0) - { - // We are being asked for the device - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, m_DeviceContent.ObjectID); - CHECK_HR(hr, "Failed to add 'DEVICE' object ID to enumeration collection"); - - // Update the the number of children we are returning for this enumeration call - NumObjectsEnumerated++; - } - else - { - FakeContent* pContent = NULL; - HRESULT hrGet = GetContent(pEnumContext->m_Scope, pEnumContext->m_strParentObjectID, &pContent); - CHECK_HR(hrGet, "Failed to get content '%ws'", pEnumContext->m_strParentObjectID); - - if (hrGet == S_OK) - { - DWORD dwStartIndex = pEnumContext->m_ChildrenEnumerated; - for (DWORD i=0; i<dwNumObjectsRequested; i++) - { - FakeContent* pChild = NULL; - if (pContent->FindNext(pEnumContext->m_Scope, dwStartIndex, &pChild)) - { - hr = AddStringValueToPropVariantCollection(pObjectIDCollection, pChild->ObjectID); - CHECK_HR(hr, "Failed to add object [%ws]", pChild->ObjectID); - - if (hr == S_OK) - { - // Update the the number of children we are returning for this enumeration call - dwStartIndex++; - NumObjectsEnumerated++; - } - } - else - { - // no more children - break; - } - } - } - } - } - - if (hr == S_OK && pdwNumObjectsEnumerated) - { - *pdwNumObjectsEnumerated = NumObjectsEnumerated; - } - - return hr; -} - -HRESULT FakeDevice::GetObjectIDsByFormat( - ACCESS_SCOPE Scope, - _In_ REFGUID guidObjectFormat, - _In_ LPCWSTR wszParentObjectID, - const DWORD dwDepth, - _In_ IPortableDevicePropVariantCollection* pObjectIDs) -{ - HRESULT hr = S_OK; - FakeContent* pContent = NULL; - - if(pObjectIDs == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - hr = GetContent(Scope, wszParentObjectID, &pContent); - CHECK_HR(hr, "Failed to get content '%ws'", wszParentObjectID); - - if (hr == S_OK) - { - hr = pContent->GetObjectIDsByFormat(Scope, guidObjectFormat, dwDepth, pObjectIDs); - CHECK_HR(hr, "Failed to get object IDs by format"); - } - - return hr; -} - -HRESULT FakeDevice::GetObjectIDsFromPersistentUniqueIDs( - ACCESS_SCOPE Scope, - _In_ IPortableDevicePropVariantCollection* pPersistentIDs, - _In_ IPortableDevicePropVariantCollection* pObjectIDs) -{ - HRESULT hr = S_OK; - DWORD dwCount = 0; - - if ((pPersistentIDs == NULL) || - (pObjectIDs == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - // Iterate through the persistent ID list and add the equivalent object ID for each element. - hr = pPersistentIDs->GetCount(&dwCount); - CHECK_HR(hr, "Failed to get count from persistent ID collection"); - - if (hr == S_OK) - { - PROPVARIANT pvPersistentID = {0}; - - for(DWORD dwIndex = 0; dwIndex < dwCount; dwIndex++) - { - PropVariantInit(&pvPersistentID); - - hr = pPersistentIDs->GetAt(dwIndex, &pvPersistentID); - CHECK_HR(hr, "Failed to get persistent ID at index %d", dwIndex); - - if (hr == S_OK) - { - hr = m_DeviceContent.GetObjectIDByPersistentID(Scope, pvPersistentID.pwszVal, pObjectIDs); - CHECK_HR(hr, "Failed to get object ID from persistent unique ID '%ws'", pvPersistentID.pwszVal); - } - - if (hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)) - { - PROPVARIANT pvEmptyObjectID = {0}; - pvEmptyObjectID.vt = VT_LPWSTR; - pvEmptyObjectID.pwszVal = L""; - - // Insert empty string when object cannot be found - hr = pObjectIDs->Add(&pvEmptyObjectID); - CHECK_HR(hr, "Failed to set empty string for persistent unique ID '%ws' when object cannot be found", pvPersistentID.pwszVal); - } - - PropVariantClear(&pvPersistentID); - - if(FAILED(hr)) - { - break; - } - } - } - - return hr; -} - -HRESULT FakeDevice::GetSupportedProperties( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys) -{ - HRESULT hr = S_OK; - FakeContent* pContent = NULL; - - if ((wszObjectID == NULL) || - (pKeys == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = GetContent(Scope, wszObjectID, &pContent); - CHECK_HR(hr, "Failed to get content '%ws'", wszObjectID); - - if (hr == S_OK) - { - hr = pContent->GetSupportedProperties(pKeys); - CHECK_HR(hr, "Failed to get supported properties for '%ws'", wszObjectID); - } - - return hr; -} - -HRESULT FakeDevice::GetAllPropertyValues( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceValues* pValues) -{ - HRESULT hr = S_OK; - FakeContent* pContent = NULL; - - if ((wszObjectID == NULL) || - (pValues == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = GetContent(Scope, wszObjectID, &pContent); - CHECK_HR(hr, "Failed to get content '%ws'", wszObjectID); - - if (hr == S_OK) - { - hr = pContent->GetAllValues(pValues); - CHECK_HR(hr, "Failed to get all property values for '%ws'", wszObjectID); - } - return hr; -} - - -HRESULT FakeDevice::GetPropertyValues( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys, - _In_ IPortableDeviceValues* pValues) -{ - HRESULT hrReturn = S_OK; - HRESULT hr = S_OK; - DWORD cKeys = 0; - FakeContent* pContent = NULL; - - if ((wszObjectID == NULL) || - (pKeys == NULL) || - (pValues == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = GetContent(Scope, wszObjectID, &pContent); - CHECK_HR(hr, "Failed to get content '%ws'", wszObjectID); - - if (hr == S_OK) - { - hr = pKeys->GetCount(&cKeys); - CHECK_HR(hr, "Failed to number of PROPERTYKEYs in collection"); - } - - if (hr == S_OK) - { - for (DWORD dwIndex = 0; dwIndex < cKeys; dwIndex++) - { - PROPERTYKEY Key = WPD_PROPERTY_NULL; - hr = pKeys->GetAt(dwIndex, &Key); - CHECK_HR(hr, "Failed to get PROPERTYKEY at index %d in collection", dwIndex); - - if (hr == S_OK) - { - hr = pContent->GetValue(Key, pValues); - CHECK_HR(hr, "Failed to get property at index %d", dwIndex); - if (FAILED(hr)) - { - // Mark the property as failed by setting the error value - // hrReturn is marked as S_FALSE indicating that at least one property has failed. - hr = pValues->SetErrorValue(Key, hr); - hrReturn = S_FALSE; - } - } - } - } - - if (FAILED(hr)) - { - // A general error has occurred (rather than failure to set one or more properties) - hrReturn = hr; - } - - return hrReturn; -} - -HRESULT FakeDevice::SetPropertyValues( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceValues* pValues, - _In_ IPortableDeviceValues* pResults, - _In_ IPortableDeviceValues* pEventParams, - _Out_ bool* pbObjectChanged) -{ - HRESULT hr = S_OK; - FakeContent* pContent = NULL; - - if ((wszObjectID == NULL) || - (pValues == NULL) || - (pResults == NULL) || - (pEventParams == NULL) || - (pbObjectChanged == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *pbObjectChanged = false; - - hr = GetContent(Scope, wszObjectID, &pContent); - CHECK_HR(hr, "Failed to get content '%ws'", wszObjectID); - - if (hr == S_OK) - { - hr = pContent->WriteValues(pValues, pResults, pbObjectChanged); - CHECK_HR(hr, "Failed to write value for '%ws'", wszObjectID); - - if (SUCCEEDED(hr) && (*pbObjectChanged)) // hr can be S_OK or S_FALSE (if one or more property writes failed) - { - HRESULT hrEvent = pEventParams->SetGuidValue(WPD_EVENT_PARAMETER_EVENT_ID, WPD_EVENT_OBJECT_UPDATED); - CHECK_HR(hrEvent, "Failed to add WPD_EVENT_PARAMETER_EVENT_ID"); - - if (hrEvent == S_OK) - { - hrEvent = pEventParams->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, pContent->PersistentUniqueID); - CHECK_HR(hrEvent, "Failed to add WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - - if (hrEvent == S_OK) - { - hrEvent = pEventParams->SetStringValue(WPD_EVENT_PARAMETER_OBJECT_PARENT_PERSISTENT_UNIQUE_ID, pContent->ParentPersistentUniqueID); - CHECK_HR(hrEvent, "Failed to add WPD_EVENT_PARAMETER_OBJECT_PARENT_PERSISTENT_UNIQUE_ID"); - } - - if (hrEvent == S_OK) - { - // Adding this event parameter will allow WPD to scope this event to the container functional object - hrEvent = pEventParams->SetStringValue(WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, pContent->ContainerFunctionalObjectID); - CHECK_HR(hrEvent, "Failed to add WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID"); - } - } - - } - - return hr; -} - -HRESULT FakeDevice::GetPropertyAtributes( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - FakeContent* pContent = NULL; - - if ((wszObjectID == NULL) || - (pAttributes == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = GetContent(Scope, wszObjectID, &pContent); - CHECK_HR(hr, "Failed to get content '%ws'", wszObjectID); - - if (hr == S_OK) - { - hr = pContent->GetPropertyAttributes(Key, pAttributes); - CHECK_HR(hr, "Failed to get property attributes for '%ws'", wszObjectID); - } - - return hr; -} - -HRESULT FakeDevice::CreatePropertiesOnlyObject( - ACCESS_SCOPE Scope, - _In_ IPortableDeviceValues* pObjectProperties, - _In_ IPortableDeviceValues* pEventParams, - _Outptr_result_nullonfailure_ LPWSTR* ppszNewObjectID) -{ - HRESULT hr; - LPWSTR pszParentID = NULL; - FakeContent* pParent = NULL; - FakeContent* pNewObject = NULL; - - if ((pObjectProperties == NULL) || - (pEventParams == NULL) || - (ppszNewObjectID == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *ppszNewObjectID = NULL; - - // Get WPD_OBJECT_PARENT_ID - hr = pObjectProperties->GetStringValue(WPD_OBJECT_PARENT_ID, &pszParentID); - CHECK_HR(hr, "Failed to get WPD_OBJECT_PARENT_ID"); - - // Check if it is within our current access scope - if (SUCCEEDED(hr)) - { - hr = GetContent(Scope, pszParentID, &pParent); - CHECK_HR(hr, "Failed to get content '%ws'", pszParentID); - } - - if (SUCCEEDED(hr)) - { - hr = pParent->CreatePropertiesOnlyObject(pObjectProperties, &m_dwLastObjectID, &pNewObject); - CHECK_HR(hr, "Failed to create properties only object with parent '%ws'", pszParentID); - } - - if (SUCCEEDED(hr)) - { - *ppszNewObjectID = AtlAllocTaskWideString(pNewObject->ObjectID); - if (*ppszNewObjectID == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate memory for created object ID"); - } - - HRESULT hrEvent = pEventParams->SetGuidValue(WPD_EVENT_PARAMETER_EVENT_ID, WPD_EVENT_OBJECT_ADDED); - CHECK_HR(hrEvent, "Failed to add WPD_EVENT_PARAMETER_EVENT_ID"); - - if (hrEvent == S_OK) - { - hrEvent = pEventParams->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, pNewObject->PersistentUniqueID); - CHECK_HR(hrEvent, "Failed to add WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - - if (hrEvent == S_OK) - { - hrEvent = pEventParams->SetStringValue(WPD_EVENT_PARAMETER_OBJECT_PARENT_PERSISTENT_UNIQUE_ID, pNewObject->ParentPersistentUniqueID); - CHECK_HR(hrEvent, "Failed to add WPD_EVENT_PARAMETER_OBJECT_PARENT_PERSISTENT_UNIQUE_ID"); - } - - if (hrEvent == S_OK) - { - // Adding this event parameter will allow WPD to scope this event to the container functional object - hrEvent = pEventParams->SetStringValue(WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, pNewObject->ContainerFunctionalObjectID); - CHECK_HR(hrEvent, "Failed to add WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID"); - } - } - - CoTaskMemFree(pszParentID); - return hr; -} - -HRESULT FakeDevice::DeleteObject( - ACCESS_SCOPE Scope, - const DWORD dwDeleteOptions, - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceValues* pEventParams) -{ - HRESULT hr = S_OK; - FakeContent* pContent = NULL; - - if ((wszObjectID == NULL) || - (pEventParams == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = GetContent(Scope, wszObjectID, &pContent); - CHECK_HR(hr, "Failed to get content '%ws'", wszObjectID); - - if (hr == S_OK) - { - hr = pContent->MarkForDelete(dwDeleteOptions); - CHECK_HR(hr, "Failed to mark '%ws' for delete with option %d", wszObjectID, dwDeleteOptions); - } - - if (hr == S_OK) - { - HRESULT hrEvent = pEventParams->SetGuidValue(WPD_EVENT_PARAMETER_EVENT_ID, WPD_EVENT_OBJECT_REMOVED); - CHECK_HR(hrEvent, "Failed to add WPD_EVENT_PARAMETER_EVENT_ID"); - - if (hrEvent == S_OK) - { - hrEvent = pEventParams->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, pContent->PersistentUniqueID); - CHECK_HR(hrEvent, "Failed to add WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - - if (hrEvent == S_OK) - { - hrEvent = pEventParams->SetStringValue(WPD_EVENT_PARAMETER_OBJECT_PARENT_PERSISTENT_UNIQUE_ID, pContent->ParentPersistentUniqueID); - CHECK_HR(hrEvent, "Failed to add WPD_EVENT_PARAMETER_OBJECT_PARENT_PERSISTENT_UNIQUE_ID"); - } - - if (hrEvent == S_OK) - { - // Adding this event parameter will allow WPD to scope this event to the container functional object - hrEvent = pEventParams->SetStringValue(WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, pContent->ContainerFunctionalObjectID); - CHECK_HR(hrEvent, "Failed to add WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID"); - } - - hr = m_DeviceContent.RemoveObjectsMarkedForDeletion(Scope); - CHECK_HR(hr, "Failed to remove all objects marked for deletion"); - } - - return hr; -} - -HRESULT FakeDevice::GetSupportedResources( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pResources) -{ - HRESULT hr = S_OK; - FakeContent* pContent = NULL; - - if ((wszObjectID == NULL) || - (pResources == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = GetContent(Scope, wszObjectID, &pContent); - CHECK_HR(hr, "Failed to get content '%ws'", wszObjectID); - - if (hr == S_OK) - { - hr = pContent->GetSupportedResources(pResources); - CHECK_HR(hr, "Failed to get the supported resources for '%ws'", wszObjectID); - } - - return hr; -} - -HRESULT FakeDevice::GetResourceAttributes( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Resource, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - FakeContent* pContent = NULL; - - if ((wszObjectID == NULL) || - (pAttributes == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = GetContent(Scope, wszObjectID, &pContent); - CHECK_HR(hr, "Failed to get content '%ws'", wszObjectID); - - if (hr == S_OK) - { - hr = pContent->GetResourceAttributes(Resource, pAttributes); - CHECK_HR(hr, "Failed to get the supported resources for '%ws'", wszObjectID); - } - - return hr; -} - -HRESULT FakeDevice::OpenResource( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Resource, - const DWORD dwMode, - _In_ WpdObjectResourceContext* pResourceContext) -{ - HRESULT hr = S_OK; - FakeContent* pContent = NULL; - - if ((wszObjectID == NULL) || - (pResourceContext == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = GetContent(Scope, wszObjectID, &pContent); - CHECK_HR(hr, "Failed to get content '%ws'", wszObjectID); - - if (hr == S_OK) - { - pResourceContext->m_Scope = Scope; - hr = pContent->OpenResource(Resource, dwMode, pResourceContext); - CHECK_HR(hr, "Failed to open resource for '%ws'", wszObjectID); - } - - return hr; -} - -HRESULT FakeDevice::ReadResourceData( - _In_ WpdObjectResourceContext* pResourceContext, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - const DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) -{ - HRESULT hr = S_OK; - FakeContent* pContent = NULL; - - if ((pResourceContext == NULL) || - (pBuffer == NULL) || - (pdwNumBytesRead == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - *pdwNumBytesRead = 0; - - hr = GetContent(pResourceContext->m_Scope, pResourceContext->m_strObjectID, &pContent); - CHECK_HR(hr, "Failed to get content '%ws'", pResourceContext->m_strObjectID); - - if (hr == S_OK) - { - hr = pContent->ReadResourceData(pResourceContext, pBuffer, dwNumBytesToRead, pdwNumBytesRead); - CHECK_HR(hr, "Failed to read resource data for '%ws'", pResourceContext->m_strObjectID); - } - - return hr; -} - -HRESULT FakeDevice::GetContent( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _Outptr_result_nullonfailure_ FakeContent** ppContent) -{ - HRESULT hr = S_OK; - - if (ppContent == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - } - - *ppContent = NULL; - - hr = m_DeviceContent.GetContent(Scope, wszObjectID, ppContent); - CHECK_HR(hr, "Failed to get content '%ws'", wszObjectID); - - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/FakeDevice.h b/wpd/WpdServiceSampleDriver/FakeDevice.h deleted file mode 100644 index 22b23082..00000000 --- a/wpd/WpdServiceSampleDriver/FakeDevice.h +++ /dev/null @@ -1,182 +0,0 @@ -#pragma once - -/** - * This class represents an abstraction of a real device. - * Driver implementors should replace this with their own - * device I/O classes/libraries. - */ - -class FakeDevice -{ -public: - FakeDevice() : m_dwLastObjectID(0) - { - } - - ~FakeDevice() - { - } - - HRESULT InitializeContent(); - - FakeContactsService* GetContactsService(); - - ACCESS_SCOPE GetAccessScope( - _In_ IPortableDeviceValues* pParams); - - // Device Capabilities - // These are legacy commands that apply to the whole device, no access scope is required - HRESULT GetSupportedCommands( - _In_ IPortableDeviceKeyCollection* pCommands); - - HRESULT GetCommandOptions( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pOptions); - - HRESULT GetSupportedFunctionalCategories( - _In_ IPortableDevicePropVariantCollection* pFunctionalCategories); - - HRESULT GetFunctionalObjects( - _In_ REFGUID guidFunctionalCategory, - _In_ IPortableDevicePropVariantCollection* pFunctionalObjects); - - HRESULT GetSupportedContentTypes( - _In_ REFGUID guidFunctionalCategory, - _In_ IPortableDevicePropVariantCollection* pContentTypes); - - HRESULT GetSupportedFormats( - _In_ REFGUID guidContentType, - _In_ IPortableDevicePropVariantCollection* pFormats); - - HRESULT GetSupportedFormatProperties( - _In_ REFGUID guidObjectFormat, - _In_ IPortableDeviceKeyCollection* pKeys); - - HRESULT GetFixedPropertyAttributes( - _In_ REFGUID guidObjectFormat, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes); - - HRESULT GetSupportedEvents( - _In_ IPortableDevicePropVariantCollection* pEvents); - - HRESULT GetEventOptions( - _In_ IPortableDeviceValues* pOptions); - - // Enumeration - // Depending on the access scope, the driver can display only objects within the current - // scoped hierarchy tree - void InitializeEnumerationContext( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszParentID, - _In_ WpdObjectEnumeratorContext* pEnumContext); - - HRESULT FindNext( - const DWORD dwNumObjectsRequested, - _In_ WpdObjectEnumeratorContext* pEnumContext, - _In_ IPortableDevicePropVariantCollection* pObjectIDCollection, - _Out_opt_ DWORD* pdwNumObjectsEnumerated); - - HRESULT GetObjectIDsByFormat( - ACCESS_SCOPE Scope, - _In_ REFGUID guidObjectFormat, - _In_ LPCWSTR wszParentObjectID, - const DWORD dwDepth, - _In_ IPortableDevicePropVariantCollection* pObjectIDs); - - HRESULT GetObjectIDsFromPersistentUniqueIDs( - ACCESS_SCOPE Scope, - _In_ IPortableDevicePropVariantCollection* pPersistentIDs, - _In_ IPortableDevicePropVariantCollection* pObjectIDs); - - // Property Management - // Depending on the access scope, the driver can allow access to properties of objects within the current - // scoped hierarchy tree - HRESULT GetSupportedProperties( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys); - - HRESULT GetAllPropertyValues( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceValues* pValues); - - HRESULT GetPropertyValues( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys, - _In_ IPortableDeviceValues* pValues); - - HRESULT SetPropertyValues( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceValues* pValues, - _In_ IPortableDeviceValues* pResults, - _In_ IPortableDeviceValues* pEventParams, - _Out_ bool* pbObjectChanged); - - HRESULT GetPropertyAtributes( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes); - - // Object Management - // Depending on the access scope, the driver can limit access only to objects within the current - // scoped hierarchy tree - HRESULT CreatePropertiesOnlyObject( - ACCESS_SCOPE Scope, - _In_ IPortableDeviceValues* pObjectProperties, - _In_ IPortableDeviceValues* pEventParams, - _Outptr_result_nullonfailure_ LPWSTR* ppszNewObjectID); - - HRESULT DeleteObject( - ACCESS_SCOPE Scope, - const DWORD dwDeleteOptions, - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceValues* pEventParams); - - // Resources - HRESULT GetSupportedResources( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ IPortableDeviceKeyCollection* pResources); - - HRESULT GetResourceAttributes( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Resource, - _In_ IPortableDeviceValues* pAttributes); - - HRESULT OpenResource( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _In_ REFPROPERTYKEY Resource, - const DWORD dwMode, - _In_ WpdObjectResourceContext* pResourceContext); - - HRESULT ReadResourceData( - _In_ WpdObjectResourceContext* pResourceContext, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - const DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead); - -private: - HRESULT GetContent( - ACCESS_SCOPE Scope, - _In_ LPCWSTR wszObjectID, - _Outptr_result_nullonfailure_ FakeContent** ppContent); - - HRESULT RemoveObjectsMarkedForDeletion(); - -private: - - // Simulates content on the device - FakeDeviceContent m_DeviceContent; - - // Simulates contacts service functionality - FakeContactsService m_ContactsService; - - DWORD m_dwLastObjectID; -}; diff --git a/wpd/WpdServiceSampleDriver/FakeDeviceContent.cpp b/wpd/WpdServiceSampleDriver/FakeDeviceContent.cpp deleted file mode 100644 index 3770d1ed..00000000 --- a/wpd/WpdServiceSampleDriver/FakeDeviceContent.cpp +++ /dev/null @@ -1,428 +0,0 @@ -#include "stdafx.h" - -#include "FakeDeviceContent.tmh" - -const PropertyAttributeInfo g_SupportedDeviceProperties[] = -{ - {&WPD_OBJECT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_PERSISTENT_UNIQUE_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_PARENT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_NAME, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_FORMAT, VT_CLSID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_CONTENT_TYPE, VT_CLSID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_CAN_DELETE, VT_BOOL, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_FUNCTIONAL_OBJECT_CATEGORY, VT_CLSID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_DEVICE_FIRMWARE_VERSION, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_DEVICE_POWER_LEVEL, VT_UI4, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_DEVICE_POWER_SOURCE, VT_UI4, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_DEVICE_PROTOCOL, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_DEVICE_MODEL, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_DEVICE_SERIAL_NUMBER, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_DEVICE_SUPPORTS_NON_CONSUMABLE, VT_BOOL, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_DEVICE_MANUFACTURER, VT_CLSID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_DEVICE_FRIENDLY_NAME, VT_CLSID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_DEVICE_TYPE, VT_UI4, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, -}; - -HRESULT FakeDeviceContent::InitializeContent( - _Inout_ DWORD *pdwLastObjectID) -{ - HRESULT hr = S_OK; - - if (pdwLastObjectID == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Add top level object: Contacts Service - CAutoPtr<FakeContactsServiceContent> pContactsService(new FakeContactsServiceContent()); - if (pContactsService) - { - hr = pContactsService->InitializeContent(pdwLastObjectID); - if (hr == S_OK) - { - _ATLTRY - { - m_Children.Add(pContactsService); - pContactsService.Detach(); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeContactsServiceContent"); - } - } - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate contacts service content"); - } - - // Add top level object: Storage - CAutoPtr<FakeStorage> pFakeStorage(new FakeStorage()); - if (pFakeStorage) - { - _ATLTRY - { - m_Children.Add(pFakeStorage); - pFakeStorage.Detach(); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeStorage"); - } - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate storage content"); - } - - return hr; -} - -HRESULT FakeDeviceContent::InitializeEnumerationContext( - ACCESS_SCOPE Scope, - _In_ WpdObjectEnumeratorContext* pEnumeratorContext) -{ - HRESULT hr = S_OK; - - if (pEnumeratorContext == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Initialize the enumeration context - if (Scope == CONTACTS_SERVICE_ACCESS) - { - // scoped by contacts service, so only the contacts service is visible - pEnumeratorContext->m_TotalChildren = 1; - } - else - { - // default device wide enumeration, all children are visible - pEnumeratorContext->m_TotalChildren = static_cast<DWORD>(m_Children.GetCount()); - } - - return hr; -} - -HRESULT FakeDeviceContent::GetSupportedProperties( - _In_ IPortableDeviceKeyCollection* pKeys) -{ - HRESULT hr = S_OK; - if (pKeys == NULL) - { - hr = E_INVALIDARG; - return hr; - } - - // Add the PROPERTYKEYs for the 'DEVICE' object - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedDeviceProperties); dwIndex++) - { - hr = pKeys->Add(*g_SupportedDeviceProperties[dwIndex].pKey); - CHECK_HR(hr, "Failed to add device property"); - } - - return hr; -} - -HRESULT FakeDeviceContent::GetValue( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pStore) -{ - HRESULT hr = S_OK; - - if (pStore == NULL) - { - hr = E_INVALIDARG; - return hr; - } - - // Set DEVICE object properties - if (IsEqualPropertyKey(Key, WPD_DEVICE_FIRMWARE_VERSION)) - { - hr = pStore->SetStringValue(WPD_DEVICE_FIRMWARE_VERSION, FirmwareVersion); - CHECK_HR(hr, "Failed to set WPD_DEVICE_FIRMWARE_VERSION"); - } - else if (IsEqualPropertyKey(Key, WPD_DEVICE_POWER_LEVEL)) - { - hr = pStore->SetUnsignedIntegerValue(WPD_DEVICE_POWER_LEVEL, PowerLevel); - CHECK_HR(hr, "Failed to set WPD_DEVICE_POWER_LEVEL"); - } - else if (IsEqualPropertyKey(Key, WPD_DEVICE_POWER_SOURCE)) - { - hr = pStore->SetUnsignedIntegerValue(WPD_DEVICE_POWER_SOURCE, PowerSource); - CHECK_HR(hr, "Failed to set WPD_DEVICE_POWER_SOURCE"); - } - else if (IsEqualPropertyKey(Key, WPD_DEVICE_PROTOCOL)) - { - hr = pStore->SetStringValue(WPD_DEVICE_PROTOCOL, Protocol); - CHECK_HR(hr, "Failed to set WPD_DEVICE_PROTOCOL"); - } - else if (IsEqualPropertyKey(Key, WPD_DEVICE_MODEL)) - { - hr = pStore->SetStringValue(WPD_DEVICE_MODEL, Model); - CHECK_HR(hr, "Failed to set WPD_DEVICE_MODEL"); - } - else if (IsEqualPropertyKey(Key, WPD_DEVICE_SERIAL_NUMBER)) - { - hr = pStore->SetStringValue(WPD_DEVICE_SERIAL_NUMBER, SerialNumber); - CHECK_HR(hr, "Failed to set WPD_DEVICE_SERIAL_NUMBER"); - } - else if (IsEqualPropertyKey(Key, WPD_DEVICE_MANUFACTURER)) - { - hr = pStore->SetStringValue(WPD_DEVICE_MANUFACTURER, Manufacturer); - CHECK_HR(hr, "Failed to set WPD_DEVICE_MANUFACTURER"); - } - else if (IsEqualPropertyKey(Key, WPD_DEVICE_FRIENDLY_NAME)) - { - hr = pStore->SetStringValue(WPD_DEVICE_FRIENDLY_NAME, FriendlyName); - CHECK_HR(hr, "Failed to set WPD_DEVICE_FRIENDLY_NAME"); - } - else if (IsEqualPropertyKey(Key, WPD_DEVICE_TYPE)) - { - hr = pStore->SetUnsignedIntegerValue(WPD_DEVICE_TYPE, DeviceType); - CHECK_HR(hr, "Failed to set WPD_DEVICE_TYPE"); - } - - // Set general properties for DEVICE - else if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - hr = pStore->SetStringValue(WPD_OBJECT_ID, ObjectID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - hr = pStore->SetStringValue(WPD_OBJECT_NAME, Name); - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - hr = pStore->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, PersistentUniqueID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - hr = pStore->SetStringValue(WPD_OBJECT_PARENT_ID, ParentID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PARENT_ID"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - hr = pStore->SetGuidValue(WPD_OBJECT_FORMAT, Format); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - hr = pStore->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, ContentType); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CONTENT_TYPE"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - hr = pStore->SetBoolValue(WPD_OBJECT_CAN_DELETE, CanDelete); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CAN_DELETE"); - } - else if (IsEqualPropertyKey(Key, WPD_FUNCTIONAL_OBJECT_CATEGORY)) - { - hr = pStore->SetGuidValue(WPD_FUNCTIONAL_OBJECT_CATEGORY, FunctionalCategory); - CHECK_HR(hr, "Failed to set WPD_FUNCTIONAL_OBJECT_CATEGORY"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID)) - { - hr = pStore->SetStringValue(WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, ContainerFunctionalObjectID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID"); - } - else if (IsEqualPropertyKey(Key, WPD_DEVICE_SUPPORTS_NON_CONSUMABLE)) - { - hr = pStore->SetBoolValue(WPD_DEVICE_SUPPORTS_NON_CONSUMABLE, SupportsNonConsumable); - CHECK_HR(hr, "Failed to set WPD_DEVICE_SUPPORTS_NON_CONSUMABLE"); - } - else - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - CHECK_HR(hr, "Property %ws.%d is not supported", CComBSTR(Key.fmtid), Key.pid); - } - - return hr; -} - - -HRESULT FakeDeviceContent::GetSupportedResources( - _In_ IPortableDeviceKeyCollection* pResources) -{ - HRESULT hr = S_OK; - - if (pResources == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - if (hr == S_OK) - { - hr = pResources->Add(WPD_RESOURCE_ICON); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ICON for the Device object"); - } - - return hr; -} - -HRESULT FakeDeviceContent::GetResourceAttributes( - _In_ REFPROPERTYKEY Resource, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if (pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - if (IsEqualPropertyKey(Resource, WPD_RESOURCE_ICON)) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_DELETE"); - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedLargeIntegerValue(WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE, GetResourceSize(IDR_WPD_SAMPLEDRIVER_DEVICE_ICON)); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_READ"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_WRITE, FALSE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_WRITE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_DELETE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetGuidValue(WPD_RESOURCE_ATTRIBUTE_FORMAT, WPD_OBJECT_FORMAT_ICON); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_FORMAT"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_OPTIMAL_READ_BUFFER_SIZE, FILE_OPTIMAL_READ_BUFFER_SIZE_VALUE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_OPTIMAL_READ_BUFFER_SIZE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_OPTIMAL_WRITE_BUFFER_SIZE, FILE_OPTIMAL_WRITE_BUFFER_SIZE_VALUE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_OPTIMAL_WRITE_BUFFER_SIZE"); - } - } - - return hr; -} - -HRESULT FakeDeviceContent::OpenResource( - _In_ REFPROPERTYKEY Resource, - const DWORD dwMode, - _In_ WpdObjectResourceContext* pResourceContext) -{ - HRESULT hr = S_OK; - - if (pResourceContext == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Validate whether the params given to us are correct. In this case, we need to check that the object - // supports the resource requested, and can be opened in the requested access mode. - - // In this sample, we only support one resource (WPD_RESOURCE_ICON) for reading only. - // So if any resource or dwMode is specified, it must be invalid. - if (!IsEqualPropertyKey(Resource, WPD_RESOURCE_ICON)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Only WPD_RESOURCE_DEFAULT is supported in this sample driver"); - } - - if ((hr == S_OK) && ((dwMode & STGM_WRITE) != 0)) - { - hr = E_ACCESSDENIED; - CHECK_HR(hr, "This resource is not available for write access"); - } - - if (hr == S_OK) - { - // Initialize the resource context with ... - pResourceContext->m_strObjectID = ObjectID; - pResourceContext->m_Resource = Resource; - pResourceContext->m_BytesTransferred = 0; - pResourceContext->m_BytesTotal = GetResourceSize(IDR_WPD_SAMPLEDRIVER_DEVICE_ICON); - } - - return hr; -} - -HRESULT FakeDeviceContent::ReadResourceData( - _In_ WpdObjectResourceContext* pResourceContext, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - const DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) -{ - HRESULT hr = S_OK; - PBYTE pResource = NULL; - DWORD dwBytesToTransfer = 0; - - if ((pResourceContext == NULL) || - (pBuffer == NULL) || - (pdwNumBytesRead == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - *pdwNumBytesRead = 0; - - pResource = GetResourceData(IDR_WPD_SAMPLEDRIVER_DEVICE_ICON); - if (pResource == NULL) - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Failed to get the resource representing device icon data"); - } - - // Calculate how many bytes to transfer - if (hr == S_OK) - { - if (pResourceContext->m_BytesTotal >= pResourceContext->m_BytesTransferred) - { - dwBytesToTransfer = (DWORD)min((ULONGLONG)dwNumBytesToRead, (pResourceContext->m_BytesTotal - pResourceContext->m_BytesTransferred)); - - // Copy the embedded icon file data. - memcpy(pBuffer, pResource + pResourceContext->m_BytesTransferred, dwBytesToTransfer); - - // set the number of bytes actually read into to pBuffer - *pdwNumBytesRead = dwBytesToTransfer; - } - } - - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/FakeDeviceContent.h b/wpd/WpdServiceSampleDriver/FakeDeviceContent.h deleted file mode 100644 index 7558a4f8..00000000 --- a/wpd/WpdServiceSampleDriver/FakeDeviceContent.h +++ /dev/null @@ -1,95 +0,0 @@ -#pragma once - -#define DEVICE_PROTOCOL_VALUE L"Contacts Services Sample Protocol ver 1.00" -#define DEVICE_FIRMWARE_VERSION_VALUE L"1.0.0.0" -#define DEVICE_POWER_LEVEL_VALUE 100 -#define DEVICE_MODEL_VALUE L"Contacts Service Device 2000" -#define DEVICE_FRIENDLY_NAME_VALUE L"Sample Device" -#define DEVICE_MANUFACTURER_VALUE L"Windows Portable Devices Group" -#define DEVICE_SERIAL_NUMBER_VALUE L"01234567890123-45676890123456" -#define DEVICE_SUPPORTS_NONCONSUMABLE_VALUE FALSE - -class FakeDeviceContent : public FakeContent -{ -public: - FakeDeviceContent() - { - ObjectID = WPD_DEVICE_OBJECT_ID; - PersistentUniqueID = WPD_DEVICE_OBJECT_ID; - ParentID = L""; - ParentPersistentUniqueID = L""; - ContainerFunctionalObjectID = L""; - Name = WPD_DEVICE_OBJECT_ID; - Protocol = DEVICE_PROTOCOL_VALUE; - FirmwareVersion = DEVICE_FIRMWARE_VERSION_VALUE; - Model = DEVICE_MODEL_VALUE; - Manufacturer = DEVICE_MANUFACTURER_VALUE; - FriendlyName = DEVICE_FRIENDLY_NAME_VALUE; - SerialNumber = DEVICE_SERIAL_NUMBER_VALUE; - PowerLevel = DEVICE_POWER_LEVEL_VALUE; - PowerSource = WPD_POWER_SOURCE_EXTERNAL; - DeviceType = WPD_DEVICE_TYPE_GENERIC; - Format = WPD_OBJECT_FORMAT_UNSPECIFIED; - ContentType = WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT; - FunctionalCategory = WPD_FUNCTIONAL_CATEGORY_DEVICE; - RequiredScope = CONTACTS_SERVICE_ACCESS; - SupportsNonConsumable = DEVICE_SUPPORTS_NONCONSUMABLE_VALUE; - } - - virtual ~FakeDeviceContent() - { - } - - FakeDeviceContent(const FakeContent& src) - { - *this = src; - } - - virtual HRESULT FakeDeviceContent::InitializeContent( - _Inout_ DWORD *pdwLastObjectID); - - virtual HRESULT InitializeEnumerationContext( - ACCESS_SCOPE Scope, - _In_ WpdObjectEnumeratorContext* pEnumeratorContext); - - // Property Management - virtual HRESULT GetSupportedProperties( - _In_ IPortableDeviceKeyCollection* pKeys); - - virtual HRESULT GetValue( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pStore); - - // Resources - virtual HRESULT GetSupportedResources( - _In_ IPortableDeviceKeyCollection* pResources); - - virtual HRESULT GetResourceAttributes( - _In_ REFPROPERTYKEY Resource, - _In_ IPortableDeviceValues* pAttributes); - - virtual HRESULT OpenResource( - _In_ REFPROPERTYKEY Resource, - const DWORD dwMode, - _In_ WpdObjectResourceContext* pResourceContext); - - virtual HRESULT ReadResourceData( - _In_ WpdObjectResourceContext* pResourceContext, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - const DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead); - -public: - CAtlStringW Protocol; - CAtlStringW FirmwareVersion; - CAtlStringW Model; - CAtlStringW FriendlyName; - CAtlStringW SerialNumber; - CAtlStringW Manufacturer; - - GUID FunctionalCategory; - BOOL SupportsNonConsumable; - DWORD PowerLevel; - DWORD PowerSource; - DWORD DeviceType; -}; diff --git a/wpd/WpdServiceSampleDriver/FakeStorage.cpp b/wpd/WpdServiceSampleDriver/FakeStorage.cpp deleted file mode 100644 index 0d54e671..00000000 --- a/wpd/WpdServiceSampleDriver/FakeStorage.cpp +++ /dev/null @@ -1,217 +0,0 @@ -#include "stdafx.h" - -#include "FakeStorage.tmh" - -const PropertyAttributeInfo g_SupportedStorageProperties[] = -{ - {&WPD_OBJECT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_PERSISTENT_UNIQUE_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_PARENT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_NAME, VT_LPWSTR, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_FORMAT, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_CONTENT_TYPE, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_CAN_DELETE, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_STORAGE_TYPE, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_STORAGE_FILE_SYSTEM_TYPE, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_STORAGE_CAPACITY, VT_UI8, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_STORAGE_FREE_SPACE_IN_BYTES, VT_UI8, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_STORAGE_SERIAL_NUMBER, VT_LPWSTR, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, - {&WPD_STORAGE_DESCRIPTION, VT_LPWSTR, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast, NULL}, - {&WPD_FUNCTIONAL_OBJECT_CATEGORY, VT_CLSID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, NULL}, -}; - -HRESULT FakeStorage::GetSupportedProperties( - _In_ IPortableDeviceKeyCollection *pKeys) -{ - HRESULT hr = S_OK; - - if (pKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedStorageProperties); dwIndex++) - { - hr = pKeys->Add(*g_SupportedStorageProperties[dwIndex].pKey); - CHECK_HR(hr, "Failed to add storage property"); - } - - return hr; -} - -HRESULT FakeStorage::GetValue( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pStore) -{ - HRESULT hr = S_OK; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - if (IsEqualPropertyKey(Key, WPD_STORAGE_SERIAL_NUMBER)) - { - hr = pStore->SetStringValue(WPD_STORAGE_SERIAL_NUMBER, SerialNumber); - CHECK_HR(hr, "Failed to set WPD_STORAGE_SERIAL_NUMBER"); - } - else if (IsEqualPropertyKey(Key, WPD_STORAGE_FREE_SPACE_IN_BYTES)) - { - hr = pStore->SetUnsignedLargeIntegerValue(WPD_STORAGE_FREE_SPACE_IN_BYTES, FreeSpace); - CHECK_HR(hr, "Failed to set WPD_STORAGE_FREE_SPACE_IN_BYTES"); - } - else if (IsEqualPropertyKey(Key, WPD_STORAGE_CAPACITY)) - { - hr = pStore->SetUnsignedLargeIntegerValue(WPD_STORAGE_CAPACITY, Capacity); - CHECK_HR(hr, "Failed to set WPD_STORAGE_CAPACITY"); - } - else if (IsEqualPropertyKey(Key, WPD_STORAGE_TYPE)) - { - hr = pStore->SetUnsignedIntegerValue(WPD_STORAGE_TYPE, StorageType); - CHECK_HR(hr, "Failed to set WPD_STORAGE_TYPE"); - } - else if (IsEqualPropertyKey(Key, WPD_STORAGE_FILE_SYSTEM_TYPE)) - { - hr = pStore->SetStringValue(WPD_STORAGE_FILE_SYSTEM_TYPE, FileSystemType); - CHECK_HR(hr, "Failed to set WPD_STORAGE_FILE_SYSTEM_TYPE"); - } - else if (IsEqualPropertyKey(Key, WPD_STORAGE_DESCRIPTION)) - { - hr = pStore->SetStringValue(WPD_STORAGE_DESCRIPTION, Description); - CHECK_HR(hr, "Failed to set WPD_STORAGE_DESCRIPTION"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_ID)) - { - hr = pStore->SetStringValue(WPD_OBJECT_ID, ObjectID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - hr = pStore->SetStringValue(WPD_OBJECT_NAME, Name); - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_PERSISTENT_UNIQUE_ID)) - { - hr = pStore->SetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, PersistentUniqueID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_PARENT_ID)) - { - hr = pStore->SetStringValue(WPD_OBJECT_PARENT_ID, ParentID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_PARENT_ID"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_FORMAT)) - { - hr = pStore->SetGuidValue(WPD_OBJECT_FORMAT, Format); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTENT_TYPE)) - { - hr = pStore->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, ContentType); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CONTENT_TYPE"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CAN_DELETE)) - { - hr = pStore->SetBoolValue(WPD_OBJECT_CAN_DELETE, CanDelete); - CHECK_HR(hr, "Failed to set WPD_OBJECT_CAN_DELETE"); - } - else if (IsEqualPropertyKey(Key, WPD_FUNCTIONAL_OBJECT_CATEGORY)) - { - hr = pStore->SetGuidValue(WPD_FUNCTIONAL_OBJECT_CATEGORY, FunctionalCategory); - CHECK_HR(hr, "Failed to set WPD_FUNCTIONAL_OBJECT_CATEGORY"); - } - else if (IsEqualPropertyKey(Key, WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID)) - { - hr = pStore->SetStringValue(WPD_OBJECT_CONTAINER_FUNCTIONAL_OBJECT_ID, ContainerFunctionalObjectID); - CHECK_HR(hr, "Failed to set WPD_STORAGE_DESCRIPTION"); - } - else - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - CHECK_HR(hr, "Property {%ws}.%d is not supported", CComBSTR(Key.fmtid), Key.pid); - } - - return hr; -} - -HRESULT FakeStorage::WriteValue( - _In_ REFPROPERTYKEY Key, - _In_ REFPROPVARIANT Value) -{ - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - if(Value.vt == VT_LPWSTR) - { - if (Value.pwszVal != NULL && Value.pwszVal[0] != L'\0') - { - Name = Value.pwszVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME because value was an empty string"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME because type was not VT_LPWSTR"); - } - } - else if(IsEqualPropertyKey(Key, WPD_STORAGE_DESCRIPTION)) - { - if(Value.vt == VT_LPWSTR) - { - if (Value.pwszVal != NULL && Value.pwszVal[0] != L'\0') - { - Description = Value.pwszVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_STORAGE_DESCRIPTION because value was an empty string"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_STORAGE_DESCRIPTION because type was not VT_LPWSTR"); - } - } - else - { - hr = E_ACCESSDENIED; - CHECK_HR(hr, "Property %ws.%d on [%ws] does not support set value operation", CComBSTR(Key.fmtid), Key.pid, ObjectID); - } - - return hr; -} - - -HRESULT FakeStorage::GetPropertyAttributes( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if(pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - hr = SetPropertyAttributes(Key, &g_SupportedStorageProperties[0], ARRAYSIZE(g_SupportedStorageProperties), pAttributes); - CHECK_HR(hr, "Failed to set storage property attributes"); - - return hr; -} - diff --git a/wpd/WpdServiceSampleDriver/FakeStorage.h b/wpd/WpdServiceSampleDriver/FakeStorage.h deleted file mode 100644 index bb83d683..00000000 --- a/wpd/WpdServiceSampleDriver/FakeStorage.h +++ /dev/null @@ -1,76 +0,0 @@ -#pragma once - -/** - * This class represents an abstraction of a storage content object. - * Driver implementors should replace this with their own - * device I/O classes/libraries. - */ - -#define STORAGE_OBJECT_ID L"123ABC" -#define STORAGE_CAPACITY_VALUE 1024 * 1024 -#define STORAGE_FREE_SPACE_IN_BYTES_VALUE STORAGE_CAPACITY_VALUE -#define STORAGE_SERIAL_NUMBER_VALUE L"98765432109876-54321098765432" -#define STORAGE_OBJECT_NAME_VALUE L"Internal Memory" -#define STORAGE_FILE_SYSTEM_TYPE_VALUE L"FAT32" -#define STORAGE_DESCRIPTION_VALUE L"Phone Memory Storage System" -#define STORAGE_CONTAINER_FUNCTIONAL_OBJECT_ID WPD_DEVICE_OBJECT_ID -#define STORAGE_TYPE WPD_STORAGE_TYPE_FIXED_ROM - -class FakeStorage : public FakeContent -{ -public: - FakeStorage() - { - ObjectID = STORAGE_OBJECT_ID; - PersistentUniqueID = STORAGE_OBJECT_ID; - ParentID = WPD_DEVICE_OBJECT_ID; - Name = STORAGE_OBJECT_NAME_VALUE; - ContentType = WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT; - Format = WPD_OBJECT_FORMAT_UNSPECIFIED; - FunctionalCategory = WPD_FUNCTIONAL_CATEGORY_STORAGE; - ContainerFunctionalObjectID = WPD_DEVICE_OBJECT_ID; - ParentPersistentUniqueID = WPD_DEVICE_OBJECT_ID; - - Description = STORAGE_DESCRIPTION_VALUE; - Capacity = STORAGE_CAPACITY_VALUE; - FreeSpace = STORAGE_CAPACITY_VALUE; - SerialNumber = STORAGE_SERIAL_NUMBER_VALUE; - FileSystemType = STORAGE_FILE_SYSTEM_TYPE_VALUE; - StorageType = STORAGE_TYPE; - } - - FakeStorage(const FakeContent& src) - { - *this = src; - } - - virtual ~FakeStorage() - { - } - - virtual HRESULT GetSupportedProperties( - _In_ IPortableDeviceKeyCollection* pKeys); - - virtual HRESULT GetValue( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pStore); - - virtual HRESULT WriteValue( - _In_ REFPROPERTYKEY Key, - _In_ REFPROPVARIANT Value); - - virtual HRESULT GetPropertyAttributes( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pAttributes); - -public: - // Standard WPD properties - CAtlStringW Description; - CAtlStringW SerialNumber; - CAtlStringW FileSystemType; - - GUID FunctionalCategory; - ULONGLONG FreeSpace; - ULONGLONG Capacity; - DWORD StorageType; -}; diff --git a/wpd/WpdServiceSampleDriver/Queue.cpp b/wpd/WpdServiceSampleDriver/Queue.cpp deleted file mode 100644 index 77981b5f..00000000 --- a/wpd/WpdServiceSampleDriver/Queue.cpp +++ /dev/null @@ -1,425 +0,0 @@ -// Queue.cpp : Implementation of CQueue - -#include "stdafx.h" -#include "Queue.h" -#include <devioctl.h> - -#include "Queue.tmh" - -// Add table used to lookup the Access required for Wpd Commands -BEGIN_WPD_COMMAND_ACCESS_MAP(g_WpdCommandAccessMap) - DECLARE_WPD_STANDARD_COMMAND_ACCESS_ENTRIES - // Add any custom commands here e.g. - // WPD_COMMAND_ACCESS_ENTRY(MyCustomCommand, WPD_COMMAND_ACCESS_READWRITE) -END_WPD_COMMAND_ACCESS_MAP - -// This enables use to use VERIFY_WPD_COMMAND_ACCESS to check command access function for us. -DECLARE_VERIFY_WPD_COMMAND_ACCESS; - -/****************************************************************************** - * This function calls the WpdBaseDriver to handle the WPD message. In order - * to do this it does the following: - * - * - Deserializes pBuffer into an IPortableDeviceValues which holds the command - * input parameters from the WPD application. - * - Creates an IPortableDeviceValues for the results. - * - Calls the WpdBaseDriver to handle the message. (The results of this - * operation are put into the previously created results IPortableDeviceValues.) - * - The results IPortableDeviceValues is then serialized back into pBuffer, making - * sure that it does not overrun ulOutputBufferLength. - * - *****************************************************************************/ -HRESULT CQueue::ProcessWpdMessage( - ULONG ControlCode, - _In_ ContextMap* pClientContextMap, - _In_opt_ LPCWSTR pszFileName, - _In_ IWDFDevice* pDevice, - _In_reads_bytes_(ulInputBufferLength) PVOID pInBuffer, - ULONG ulInputBufferLength, - _Out_writes_bytes_to_(ulOutputBufferLength, *pdwBytesWritten) PVOID pOutBuffer, - ULONG ulOutputBufferLength, - _Out_ DWORD* pdwBytesWritten) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<WpdBaseDriver> pWpdBaseDriver; - - *pdwBytesWritten = 0; - - if (hr == S_OK) - { - hr = m_pWpdSerializer->GetIPortableDeviceValuesFromBuffer((BYTE*)pInBuffer, - ulInputBufferLength, - &pParams); - CHECK_HR(hr, "Failed to deserialize command parameters from input buffer"); - } - - // Verify that that command was sent with the appropriate access - if (hr == S_OK) - { - hr = VERIFY_WPD_COMMAND_ACCESS(ControlCode, pParams, g_WpdCommandAccessMap); - CHECK_HR(hr, "Wpd Command was sent with incorrect access flags"); - } - - // Create the WPD results collection - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Insert the client context map as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the context map. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, pClientContextMap); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Insert the IWDFDevice interface as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the WUDF Device object. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT, pDevice); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT"); - } - - // Insert the IWpdSerializer interface as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the WPD Serializer object. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT, m_pWpdSerializer); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT"); - } - - // Insert the Service Object ID as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the Service Object ID. - if ((hr == S_OK) && (pszFileName != NULL)) - { - hr = pParams->SetStringValue(PRIVATE_SAMPLE_DRIVER_REQUEST_FILENAME, pszFileName); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_REQUEST_FILENAME"); - } - - // Get the WpdBaseDriver so we can dispatch the message - if (hr == S_OK) - { - hr = GetWpdBaseDriver(pDevice, &pWpdBaseDriver); - CHECK_HR(hr, "Failed to get WpdBaseDriver"); - } - - if (hr == S_OK) - { - hr = pWpdBaseDriver->DispatchWpdMessage(pParams, pResults); - CHECK_HR(hr, "Failed to handle WPD command"); - } - - if (hr == S_OK) - { - hr = m_pWpdSerializer->WriteIPortableDeviceValuesToBuffer(ulOutputBufferLength, - pResults, - (BYTE*)pOutBuffer, - pdwBytesWritten); - CHECK_HR(hr, "Failed to serialize results to output buffer"); - } - - return hr; -} - -/****************************************************************************** - * This method gets the WpdBaseDriver associated with the UMDF device object. - * The caller should Release *ppWpdBaseDriver when it is done. - * - * When this device was created, we assigned the WpdBaseDriver as the context. - * So, in order to retrieve the correct WpdBaseDriver for this device, we simply - * get the device context. - *****************************************************************************/ -HRESULT CQueue::GetWpdBaseDriver( - _In_ IWDFDevice* pDevice, - _Outptr_result_nullonfailure_ WpdBaseDriver** ppWpdBaseDriver) -{ - HRESULT hr = S_OK; - WpdBaseDriver* pContext = NULL; - - if((pDevice == NULL) || (ppWpdBaseDriver == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter for pDevice or ppWpdBaseDriver"); - return hr; - } - - *ppWpdBaseDriver = NULL; - - if(SUCCEEDED(hr)) - { - hr = pDevice->RetrieveContext((void**)&pContext); - if(SUCCEEDED(hr)) - { - if(pContext != NULL) - { - pContext->AddRef(); - *ppWpdBaseDriver = pContext; - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Device context is NULL"); - } - } - } - - return hr; -} - - -/****************************************************************************** - * This method gets the Filename associated with the Request object - * The caller should CoTaskMemFree *ppszFileName when it is done. - *****************************************************************************/ -HRESULT CQueue::GetFileName( - _In_ IWDFFile* pFileObject, - _Outptr_result_maybenull_ LPWSTR* ppszFileName) -{ - HRESULT hr = S_OK; - DWORD cchFileName = 0; - LPWSTR pszFileName = NULL; - - if((pFileObject == NULL) || (ppszFileName == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter for pFileObject or ppszFileName"); - return hr; - } - - *ppszFileName = NULL; - - if (hr == S_OK) - { - hr = pFileObject->RetrieveFileName(NULL, &cchFileName); - CHECK_HR(hr, "Failed to get the filename size from WDF File Object"); - - if (hr == S_OK && cchFileName > 1) - { - pszFileName = (LPWSTR)CoTaskMemAlloc(cchFileName * sizeof(WCHAR)); - if (pszFileName == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate memory to hold the filename"); - } - else - { - hr = pFileObject->RetrieveFileName(pszFileName, &cchFileName); - CHECK_HR(hr, "Failed to get the filename from WDF File Object"); - } - - // The expected filename contains '\' + ServiceObjectID - if (hr == S_OK && (pszFileName != NULL) && (cchFileName > 1)) - { - // Check that the leading character is '\' - if (pszFileName[0] == L'\\') - { - // Skip the leading \\ character - *ppszFileName = AtlAllocTaskWideString(pszFileName + 1); - if (*ppszFileName == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate memory to hold the result filename"); - } - } - else - { - hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); - } - } - } - } - - CoTaskMemFree(pszFileName); - - return hr; -} - - -// CQueue - -STDMETHODIMP_ (void) -CQueue::OnCreateFile( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - _In_ IWDFFile* pFileObject - ) -{ - UNREFERENCED_PARAMETER(pQueue); - // This critical section protects the section of code where we - // Create the serializer and results interfaces used in handling I/O messages. - // We only need to create them once, then we hang on to them for the lifetime of this - // queue object. - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - HRESULT hr = S_OK; - - // Create the WPD serializer - if ((hr == S_OK) && - (m_pWpdSerializer == NULL)) - { - hr = CoCreateInstance(CLSID_WpdSerializer, - NULL, - CLSCTX_INPROC_SERVER, - IID_IWpdSerializer, - (VOID**)&m_pWpdSerializer); - - CHECK_HR(hr, "Failed to CoCreate CLSID_WpdSerializer"); - } - - // Create the client context map and associate it with the File Object - // so we can obtain it on a per-client basis. - if (hr == S_OK) - { - ContextMap* pClientContextMap = new ContextMap(); - - if(pClientContextMap != NULL) - { - hr = pFileObject->AssignContext(this, (void*)pClientContextMap); - CHECK_HR(hr, "Failed to set client context map"); - - // Release the client context map if we cannot set it - // properly - if(FAILED(hr)) - { - pClientContextMap->Release(); - pClientContextMap = NULL; - } - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to create client context map"); - } - } - - pRequest->Complete(hr); - return; -} - -STDMETHODIMP_ (void) -CQueue::OnDeviceIoControl( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - ULONG ControlCode, - SIZE_T InputBufferSizeInBytes, - SIZE_T OutputBufferSizeInBytes - ) -{ - UNREFERENCED_PARAMETER(InputBufferSizeInBytes); - UNREFERENCED_PARAMETER(OutputBufferSizeInBytes); - - HRESULT hr = S_OK; - DWORD dwBytesWritten = 0; - - if(IS_WPD_IOCTL(ControlCode)) - { - BYTE* pInputBuffer = NULL; - SIZE_T cbInputBuffer = 0; - BYTE* pOutputBuffer = NULL; - SIZE_T cbOutputBuffer = 0; - ContextMap* pClientContextMap = NULL; - LPWSTR pszFileName = NULL; - - CComPtr<IWDFMemory> pMemoryIn; - CComPtr<IWDFMemory> pMemoryOut; - CComPtr<IWDFDevice> pDevice; - CComPtr<IWDFFile> pFileObject; - - // - // Get input memory buffer, the memory object is always returned even if the - // underlying buffer is NULL - // - pRequest->GetInputMemory(&pMemoryIn); - pInputBuffer = (BYTE*) pMemoryIn->GetDataBuffer(&cbInputBuffer); - - // - // Get output memory buffer, the memory object is always returned even if the - // underlying buffer is NULL - // - pRequest->GetOutputMemory(&pMemoryOut); - pOutputBuffer = (BYTE*) pMemoryOut->GetDataBuffer(&cbOutputBuffer); - - // Get the Context map for this client - pRequest->GetFileObject(&pFileObject); - if (pFileObject != NULL) - { - hr = pFileObject->RetrieveContext((void**)&pClientContextMap); - CHECK_HR(hr, "Failed to get Contextmap from WDF File Object"); - - if (hr == S_OK) - { - hr = GetFileName(pFileObject, &pszFileName); - CHECK_HR(hr, "Failed to get Filename from WDF File Object"); - } - - if (hr == S_OK) - { - // Get the device object - pQueue->GetDevice(&pDevice); - hr = ProcessWpdMessage(ControlCode, - pClientContextMap, - pszFileName, - pDevice, - pInputBuffer, - (DWORD)cbInputBuffer, - pOutputBuffer, - (DWORD)cbOutputBuffer, - &dwBytesWritten); - } - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "WDF File Object is NULL"); - } - - CoTaskMemFree(pszFileName); - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Received invalid/unsupported IOCTL code '0x%lx'",ControlCode); - } - - // Complete the request - if (hr == S_OK) - { - pRequest->CompleteWithInformation(hr, dwBytesWritten); - } - else - { - pRequest->Complete(hr); - } - - return; -} - -STDMETHODIMP_ (void) -CQueue::OnCleanup( - _In_ IWDFObject* pWdfObject - ) -{ - // Destroy the client context map - HRESULT hr = S_OK; - ContextMap* pClientContextMap = NULL; - - hr = pWdfObject->RetrieveContext((void**)&pClientContextMap); - if((hr == S_OK) && (pClientContextMap != NULL)) - { - pClientContextMap->Release(); - pClientContextMap = NULL; - } -} - diff --git a/wpd/WpdServiceSampleDriver/Queue.h b/wpd/WpdServiceSampleDriver/Queue.h deleted file mode 100644 index dceb3e29..00000000 --- a/wpd/WpdServiceSampleDriver/Queue.h +++ /dev/null @@ -1,98 +0,0 @@ -// Queue.h : Declaration of the CQueue - -#pragma once -#include "resource.h" // main symbols -#include "WpdServiceSampleDriver.h" - -class ATL_NO_VTABLE CQueue : - public CComObjectRootEx<CComMultiThreadModel>, - public IQueueCallbackDeviceIoControl, - public IQueueCallbackCreate, - public IObjectCleanup -{ -public: - CQueue() - { - - } - - DECLARE_NOT_AGGREGATABLE(CQueue) - - BEGIN_COM_MAP(CQueue) - COM_INTERFACE_ENTRY(IQueueCallbackDeviceIoControl) - COM_INTERFACE_ENTRY(IQueueCallbackCreate) - END_COM_MAP() - -public: - static - HRESULT CreateInstance( - _COM_Outptr_ IUnknown** ppUkwn) - { - *ppUkwn = NULL; - CComObject< CQueue> *pMyQueue = NULL; - HRESULT hr = CComObject<CQueue>::CreateInstance( &pMyQueue ); - if( SUCCEEDED (hr) ) - { - pMyQueue->AddRef(); - hr = pMyQueue->QueryInterface( __uuidof(IUnknown), (void **) ppUkwn ); - pMyQueue->Release(); - pMyQueue = NULL; - } - - return hr; - } - - // - // Wdf Callbacks - // - - // IQueueCallbackCreateClose - // - STDMETHOD_ (void, OnCreateFile)( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - _In_ IWDFFile* pFileObject - ); - - // - // IQueueCallbackDeviceIoControl - // - STDMETHOD_ (void, OnDeviceIoControl)( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - ULONG ControlCode, - SIZE_T InputBufferSizeInBytes, - SIZE_T OutputBufferSizeInBytes - ); - - // - // IObjectCleanup - // - STDMETHOD_ (void, OnCleanup)( - _In_ IWDFObject* pWdfObject - ); - -private: - HRESULT ProcessWpdMessage( - ULONG ControlCode, - _In_ ContextMap* pClientContextMap, - _In_opt_ LPCWSTR pszFileName, - _In_ IWDFDevice* pDevice, - _In_reads_bytes_(ulInputBufferLength) PVOID pInBuffer, - ULONG ulInputBufferLength, - _Out_writes_bytes_to_(ulOutputBufferLength, *pdwBytesWritten) PVOID pOutBuffer, - ULONG ulOutputBufferLength, - _Out_ DWORD* pdwBytesWritten); - - HRESULT GetWpdBaseDriver( - _In_ IWDFDevice* pDevice, - _Outptr_result_nullonfailure_ WpdBaseDriver** ppWpdBaseDriver); - - HRESULT GetFileName( - _In_ IWDFFile* pFileObject, - _Outptr_result_maybenull_ LPWSTR* ppszFilename); - - CComPtr<IWpdSerializer> m_pWpdSerializer; - CComAutoCriticalSection m_CriticalSection; -}; - diff --git a/wpd/WpdServiceSampleDriver/README.md b/wpd/WpdServiceSampleDriver/README.md deleted file mode 100644 index 4cd6b4dc..00000000 --- a/wpd/WpdServiceSampleDriver/README.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -page_type: sample -description: "Demonstrates how to extend the WpdHelloWorldDriver sample so that it supports a simulated device with a Contacts device service." -languages: -- cpp -products: -- windows -- windows-wdk ---- - -# WPD service sample driver - -Demonstrates how to extend the WpdHelloWorldDriver sample so that it supports a simulated device with a Contacts device service. - -## Related topics - -[WPD Design Guide](https://docs.microsoft.com/windows-hardware/drivers/portable/wpd-design-guide) - -[WPD Driver Development Tools](https://docs.microsoft.com/windows-hardware/drivers/portable/familiarizing-yourself-with-the-sample-driver) - -[WPD Programming Guide](https://docs.microsoft.com/windows-hardware/drivers/portable/wpd-programming-guide) diff --git a/wpd/WpdServiceSampleDriver/SampleContactsServiceIcon.ico b/wpd/WpdServiceSampleDriver/SampleContactsServiceIcon.ico Binary files differdeleted file mode 100644 index 28648294..00000000 --- a/wpd/WpdServiceSampleDriver/SampleContactsServiceIcon.ico +++ /dev/null diff --git a/wpd/WpdServiceSampleDriver/SampleDeviceIcon.ico b/wpd/WpdServiceSampleDriver/SampleDeviceIcon.ico Binary files differdeleted file mode 100644 index 33a1d1a5..00000000 --- a/wpd/WpdServiceSampleDriver/SampleDeviceIcon.ico +++ /dev/null diff --git a/wpd/WpdServiceSampleDriver/Stdafxsrc.cpp b/wpd/WpdServiceSampleDriver/Stdafxsrc.cpp deleted file mode 100644 index 5105a28d..00000000 --- a/wpd/WpdServiceSampleDriver/Stdafxsrc.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Stdafx.h"
\ No newline at end of file diff --git a/wpd/WpdServiceSampleDriver/WpdBaseDriver.cpp b/wpd/WpdServiceSampleDriver/WpdBaseDriver.cpp deleted file mode 100644 index adb9d3b3..00000000 --- a/wpd/WpdServiceSampleDriver/WpdBaseDriver.cpp +++ /dev/null @@ -1,393 +0,0 @@ -#include "stdafx.h" - -#include "WpdBaseDriver.tmh" - -WpdBaseDriver::WpdBaseDriver() : - m_cRef(1) -{ -} - -WpdBaseDriver::~WpdBaseDriver() -{ - -} - -ULONG __stdcall WpdBaseDriver::AddRef() -{ - InterlockedIncrement((long*) &m_cRef); - return m_cRef; -} - -_At_(this, __drv_freesMem(Mem)) -ULONG __stdcall WpdBaseDriver::Release() -{ - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; -} - -HRESULT __stdcall WpdBaseDriver::QueryInterface( - REFIID riid, - void** ppv) -{ - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - return hr; -} - -/** - * This method is called to initialize the driver object. - * This is where the driver would set up it's I/O libraries - * and so on. - */ -HRESULT WpdBaseDriver::Initialize() -{ - HRESULT hr = m_Device.InitializeContent(); - CHECK_HR(hr, ("Failed to initialize content")); - - if (hr == S_OK) - { - hr = m_Service.Initialize(&m_Device); - CHECK_HR(hr, ("Failed to initialize WpdService")); - } - - if (hr == S_OK) - { - hr = m_ObjectEnum.Initialize(&m_Device); - CHECK_HR(hr, ("Failed to initialize WpdObjectEnum")); - } - - if (hr == S_OK) - { - m_Capabilities.Initialize(&m_Device); - CHECK_HR(hr, ("Failed to initialize WpdCapabilities")); - } - - if (hr == S_OK) - { - m_ObjectManagement.Initialize(&m_Device); - CHECK_HR(hr, ("Failed to initialize WpdObjectManagement")); - } - - if (hr == S_OK) - { - m_ObjectProperties.Initialize(&m_Device); - CHECK_HR(hr, ("Failed to initialize WpdObjectProperties")); - } - - if (hr == S_OK) - { - m_ObjectResources.Initialize(&m_Device); - CHECK_HR(hr, ("Failed to initialize WpdObjectResources")); - } - - if (hr == S_OK) - { - m_ObjectPropertiesBulk.Initialize(&m_Device); - CHECK_HR(hr, ("Failed to initialize WpdObjectPropertiesBulk")); - } - - return hr; -} - -/** - * This method is called to uninitialize the driver object. - * In a real driver, this is where the driver would clean up - * any resources held by this driver. - */ -VOID WpdBaseDriver::Uninitialize() -{ -} - -HRESULT WpdBaseDriver::DispatchWpdMessage(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - - HRESULT hr = S_OK; - GUID guidCommandCategory = {0}; - DWORD dwCommandID = 0; - PROPERTYKEY CommandKey = WPD_PROPERTY_NULL; - - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, &guidCommandCategory); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_CATEGORY from input parameters"); - } - - if (hr == S_OK) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, &dwCommandID); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_ID from input parameters"); - } - - // If WPD_PROPERTY_COMMON_COMMAND_CATEGORY or WPD_PROPERTY_COMMON_COMMAND_ID could not be extracted - // properly then we should return E_INVALIDARG to the client. - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_CATEGORY or WPD_PROPERTY_COMMON_COMMAND_ID from input parameters"); - } - - if (hr == S_OK) - { - CommandKey.fmtid = guidCommandCategory; - CommandKey.pid = dwCommandID; - - if (CommandKey.fmtid == WPD_CATEGORY_OBJECT_ENUMERATION) - { - hr = m_ObjectEnum.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_OBJECT_PROPERTIES) - { - hr = m_ObjectProperties.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_OBJECT_RESOURCES) - { - hr = m_ObjectResources.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_CAPABILITIES) - { - hr = m_Capabilities.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if(CommandKey.fmtid == WPD_CATEGORY_OBJECT_MANAGEMENT) - { - hr = m_ObjectManagement.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if(CommandKey.fmtid == WPD_CATEGORY_OBJECT_PROPERTIES_BULK) - { - hr = m_ObjectPropertiesBulk.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (IsEqualPropertyKey(CommandKey, WPD_COMMAND_COMMON_GET_OBJECT_IDS_FROM_PERSISTENT_UNIQUE_IDS)) - { - hr = OnGetObjectIDsFromPersistentUniqueIDs(pParams, pResults); - } - else if(IsEqualPropertyKey(CommandKey, WPD_COMMAND_COMMON_SAVE_CLIENT_INFORMATION)) - { - hr = OnSaveClientInfo(pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_SERVICE_COMMON || - CommandKey.fmtid == WPD_CATEGORY_SERVICE_METHODS || - CommandKey.fmtid == WPD_CATEGORY_SERVICE_CAPABILITIES) - { - hr = m_Service.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "Unknown command %ws.%d received",CComBSTR(CommandKey.fmtid), CommandKey.pid); - } - } - - HRESULT hrTemp = pResults->SetErrorValue(WPD_PROPERTY_COMMON_HRESULT, hr); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_COMMON_HRESULT")); - - // Set to a success code, to indicate that the message was received. - // the return code for the actual command's results is stored in the - // WPD_PROPERTY_COMMON_HRESULT property. - hr = S_OK; - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_COMMON_GET_OBJECT_IDS_FROM_PERSISTENT_UNIQUE_IDS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS: Contains an IPortableDevicePropVariantCollection of VT_LPWSTR, - * indicating the PersistentUniqueIDs. - * - * The driver should: - * - Iterate through the PersistentUniqueIDs, and convert to a currently valid object id. - * This object ID list should be returned as an IPortableDevicePropVariantCollection of VT_LPWSTR - * in WPD_PROPERTY_COMMON_OBJECT_IDS. - * Order is implicit, i.e. the first element in the Persistent Unique ID list corresponds to the - * to the first element of the ObjectID list and so on. - * - * For those elements where an existing ObjectID could not be found (e.g. the - * object is no longer present on the device), the element will contain the - * empty string (L""). - */ -HRESULT WpdBaseDriver::OnGetObjectIDsFromPersistentUniqueIDs( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - - HRESULT hr = S_OK; - CComPtr<IPortableDevicePropVariantCollection> pPersistentIDs; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - - if((pParams == NULL) || - (pResults == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Get the list of Persistent IDs - if (hr == S_OK) - { - hr = pParams->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS, &pPersistentIDs); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS"); - } - - // Create the collection to hold the ObjectIDs - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pObjectIDs); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - - if (hr == S_OK) - { - ACCESS_SCOPE Scope = m_Device.GetAccessScope(pParams); - hr = m_Device.GetObjectIDsFromPersistentUniqueIDs(Scope, pPersistentIDs, pObjectIDs); - CHECK_HR(hr, "Failed to get object IDs from persistent IDs"); - } - - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_COMMON_OBJECT_IDS, pObjectIDs); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_COMMON_OBJECT_IDS"); - } - - return hr; -} - - -/** - * This method is called when we receive a WPD_COMMAND_COMMON_SAVE_CLIENT_INFORMATION - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_COMMON_CLIENT_INFORMATION: Contains information about the client, including version - * and optionally the client event cookie. - * - * The driver should: - * - Save the client information and return an LPWSTR context for this client. - * The client can be identified using this context for subsequent commands to the driver. - */ -HRESULT WpdBaseDriver::OnSaveClientInfo( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - - HRESULT hr = S_OK; - GUID guidContext = GUID_NULL; - CComBSTR bstrContext; - ClientContext* pContext = NULL; - ContextMap* pContextMap = NULL; - - CComPtr<IPortableDeviceValues> pClientInfo; - - if((pParams == NULL) || - (pResults == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = CoCreateGuid(&guidContext); - if (hr == S_OK) - { - bstrContext = guidContext; - if(bstrContext.Length() == 0) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to create BSTR from GUID"); - } - } - - // Get the client info - if (hr == S_OK) - { - hr = pParams->GetIPortableDeviceValuesValue(WPD_PROPERTY_COMMON_CLIENT_INFORMATION, &pClientInfo); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_CLIENT_INFORMATION"); - } - - // Get the context map which the driver stored in pParams for convenience - if (hr == S_OK) - { - hr = GetClientContextMap(pParams, &pContextMap); - CHECK_HR(hr, "Failed to get client context map"); - } - - // Create the new client info context we will save in the context map - if (hr == S_OK) - { - pContext = new ClientContext(); - if(pContext == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, ("Could not allocate memory for client info context")); - } - } - - // Save the client info. Since these are optional, none of this is fatal if - // they don't exist. - if (hr == S_OK) - { - LPWSTR pszClientName = NULL; - LPWSTR pszEventCookie = NULL; - - pClientInfo->GetStringValue(WPD_CLIENT_NAME, &pszClientName); - if(pszClientName != NULL) - { - pContext->ClientName = pszClientName; - } - pClientInfo->GetUnsignedIntegerValue(WPD_CLIENT_MAJOR_VERSION, &(pContext->MajorVersion)); - pClientInfo->GetUnsignedIntegerValue(WPD_CLIENT_MINOR_VERSION, &(pContext->MinorVersion)); - pClientInfo->GetUnsignedIntegerValue(WPD_CLIENT_REVISION, &(pContext->Revision)); - - pClientInfo->GetStringValue(WPD_CLIENT_EVENT_COOKIE, &pszEventCookie); - if (pszEventCookie != NULL) - { - pContext->EventCookie = pszEventCookie; - } - - CoTaskMemFree(pszClientName); - CoTaskMemFree(pszEventCookie); - } - - if ((hr == S_OK) && - (pContext->ClientName.GetLength() > 0) && - (pContextMap != NULL)) - { - CAtlStringW strContext; - hr = pContextMap->Add(pContext, strContext); - CHECK_HR(hr, "Failed to add client info context to context map"); - - if (hr == S_OK) - { - hr = pResults->SetStringValue(WPD_PROPERTY_COMMON_CLIENT_INFORMATION_CONTEXT, strContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_COMMON_CLIENT_INFORMATION_CONTEXT"); - } - } - - SAFE_RELEASE(pContext); - SAFE_RELEASE(pContextMap); - - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/WpdBaseDriver.h b/wpd/WpdServiceSampleDriver/WpdBaseDriver.h deleted file mode 100644 index 3e731f52..00000000 --- a/wpd/WpdServiceSampleDriver/WpdBaseDriver.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -class WpdBaseDriver : - public IUnknown -{ -public: - WpdBaseDriver(); - virtual ~WpdBaseDriver(); - - HRESULT Initialize(); - VOID Uninitialize(); - - HRESULT DispatchWpdMessage(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - HRESULT OnGetObjectIDsFromPersistentUniqueIDs(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - - HRESULT OnSaveClientInfo(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -public: // IUnknown - ULONG __stdcall AddRef(); - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release(); - - HRESULT __stdcall QueryInterface(REFIID riid, void** ppv); - -public: - WpdObjectEnumerator m_ObjectEnum; - WpdObjectManagement m_ObjectManagement; - WpdObjectProperties m_ObjectProperties; - WpdObjectResources m_ObjectResources; - WpdObjectPropertiesBulk m_ObjectPropertiesBulk; - WpdCapabilities m_Capabilities; - WpdService m_Service; - -private: - FakeDevice m_Device; - ULONG m_cRef; -}; - diff --git a/wpd/WpdServiceSampleDriver/WpdCapabilities.cpp b/wpd/WpdServiceSampleDriver/WpdCapabilities.cpp deleted file mode 100644 index 0e5055bc..00000000 --- a/wpd/WpdServiceSampleDriver/WpdCapabilities.cpp +++ /dev/null @@ -1,674 +0,0 @@ -#include "stdafx.h" - -#include "WpdCapabilities.tmh" - -WpdCapabilities::WpdCapabilities() : m_pDevice(NULL) -{ - -} - -WpdCapabilities::~WpdCapabilities() -{ - -} - -HRESULT WpdCapabilities::Initialize(_In_ FakeDevice* pDevice) -{ - if (pDevice == NULL) - { - return E_POINTER; - } - m_pDevice = pDevice; - return S_OK; -} - -HRESULT WpdCapabilities::DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (hr == S_OK) - { - if (Command.fmtid != WPD_CATEGORY_CAPABILITIES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS)) - { - hr = OnGetSupportedCommands(pParams, pResults); - CHECK_HR(hr, "Failed to get supported commands"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS)) - { - hr = OnGetCommandOptions(pParams, pResults); - CHECK_HR(hr, "Failed to get command options"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES)) - { - hr = OnGetFunctionalCategories(pParams, pResults); - CHECK_HR(hr, "Failed to get functional categories"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS)) - { - hr = OnGetFunctionalObjects(pParams, pResults); - CHECK_HR(hr, "Failed to get functional objects"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES)) - { - hr = OnGetSupportedContentTypes(pParams, pResults); - CHECK_HR(hr, "Failed to get supported content types"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS)) - { - hr = OnGetSupportedFormats(pParams, pResults); - CHECK_HR(hr, "Failed to get supported formats"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES)) - { - hr = OnGetSupportedFormatProperties(pParams, pResults); - CHECK_HR(hr, "Failed to get supported format properties"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_FIXED_PROPERTY_ATTRIBUTES)) - { - hr = OnGetFixedPropertyAttributes(pParams, pResults); - CHECK_HR(hr, "Failed to get fixed property attributes"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_EVENTS)) - { - hr = OnGetSupportedEvents(pParams, pResults); - CHECK_HR(hr, "Failed to get supported events"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_EVENT_OPTIONS)) - { - hr = OnGetEventOptions(pParams, pResults); - CHECK_HR(hr, "Failed to get event options"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return all commands supported by this driver as an - * IPortableDeviceKeyCollection in WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS. - * This includes custom commands, if any. - * - * Note that certain commands require a "command target" to function correctly. - * (e.g. delete object command) It is understood that not all objects are necessarily - * valid targets (e.g. you cannot delete the device object). - */ -HRESULT WpdCapabilities::OnGetSupportedCommands( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - UNREFERENCED_PARAMETER(pParams); - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pCommands; - - // CoCreate a collection to store the supported commands. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pCommands); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // Add the supported commands to the collection. - if (hr == S_OK) - { - hr = m_pDevice->GetSupportedCommands(pCommands); - CHECK_HR(hr, "Failed to get the supported commands"); - } - - // Set the WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS, pCommands); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_COMMAND: a collection of property keys containing a single value, - * which identifies the specific command options are requested to return. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS, containing - * the relevant options. If no options are available for this command, the driver should - * return an IPortableDeviceValues with no elements in it. - */ -HRESULT WpdCapabilities::OnGetCommandOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - PROPERTYKEY Command = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pOptions; - - // Get the command whose options have been requested - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_CAPABILITIES_COMMAND, &Command); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_COMMAND"); - } - - // CoCreate a collection to store the command options. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pOptions); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Add command options to the collection - if (hr == S_OK) - { - hr = m_pDevice->GetCommandOptions(Command, pOptions); - CHECK_HR(hr, "Failed to get the command options"); - } - - // Set the WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS, pOptions); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_CLSID) in - * WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES, containing - * the supported functional categories for this device. - */ -HRESULT WpdCapabilities::OnGetFunctionalCategories( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDevicePropVariantCollection> pFunctionalCategories; - - UNREFERENCED_PARAMETER(pParams); - - // CoCreate a collection to store the supported functional categories. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFunctionalCategories); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported functional categories to the collection. - if (hr == S_OK) - { - hr = m_pDevice->GetSupportedFunctionalCategories(pFunctionalCategories); - CHECK_HR(hr, "Failed to get the supported functional categories"); - } - - // Set the WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES, pFunctionalCategories); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS - * command. It is sent when the caller is interesting in finding the object IDs for all - * functional objects belonging to the specified functional category. - * Note: the number of functional objects is expected to be very small (less than 8 for the - * whole device). - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY - a GUID value containing the category - * the caller is looking for. If the value is WPD_FUNCTIONAL_CATEGORY_ALL, then the driver - * must return all functional objects, no matter which category they belong to. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_LPWSTR) in - * WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS, containing - * the ids of the functional objects who belong to the specified functional category. - * If there are no objects in the specified category, the driver should return an - * empty collection. - */ -HRESULT WpdCapabilities::OnGetFunctionalObjects( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidFunctionalCategory = GUID_NULL; - CComPtr<IPortableDevicePropVariantCollection> pFunctionalObjects; - - // Get the functional category whose functional object identifiers have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY, &guidFunctionalCategory); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY"); - } - - // CoCreate a collection to store the supported functional object identifiers. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFunctionalObjects); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported functional object identifiers for the specified functional - // category to the collection. - if (hr == S_OK) - { - hr = m_pDevice->GetFunctionalObjects(guidFunctionalCategory, pFunctionalObjects); - CHECK_HR(hr, "Failed to get the functional objects"); - } - - // Set the WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS, pFunctionalObjects); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES - * command. This message is sent when the client needs to know the possible content types supported - * by the specified functional category. - * If the driver has multiple functional objects that may support different content types, - * the driver should simply merge them together and report all possible types in one list here. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY - a GUID value containing the functional category - * whose content types the caller is interested in. If the value is WPD_FUNCTIONAL_CATEGORY_ALL, then the driver - * must return a list of all content types supported by the device. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_CLSID) in - * WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES, containing - * the content types supported by the specified functional category. - * If there are no objects in the specified category, the driver should return an - * empty collection. - */ -HRESULT WpdCapabilities::OnGetSupportedContentTypes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidFunctionalCategory = GUID_NULL; - CComPtr<IPortableDevicePropVariantCollection> pContentTypes; - - // Get the functional category whose supported content types have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY, &guidFunctionalCategory); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY"); - } - - // CoCreate a collection to store the supported content types. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pContentTypes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported content types for the specified functional - // category to the collection. - // Note that the contacts service does not support any content types - if (hr == S_OK) - { - hr = m_pDevice->GetSupportedContentTypes(guidFunctionalCategory, pContentTypes); - CHECK_HR(hr, "Failed to get the content types"); - } - - // Set the WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES, pContentTypes); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS - * command. This message is sent when the client needs to know the possible formats supported - * by the specified content type (e.g. for image objects, the driver may choose to support JPEG and BMP files). - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_CONTENT_TYPE - a GUID value containing the content type - * whose formats the caller is interested in. If the value is WPD_CONTENT_TYPE_ALL, then the driver - * must return a list of all formats supported by the device. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_CLSID) in - * WPD_PROPERTY_CAPABILITIES_FORMATS, indicating the formats supported by the - * specified content type. - * If there are no formats supported by the specified content type, the driver should return an - * empty collection. - */ -HRESULT WpdCapabilities::OnGetSupportedFormats( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidContentType = GUID_NULL; - CComPtr<IPortableDevicePropVariantCollection> pFormats; - - // Get the content type whose supported formats have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_CONTENT_TYPE, &guidContentType); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_CONTENT_TYPE"); - } - - // CoCreate a collection to store the supported formats. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFormats); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported formats for the specified content type to the collection. - if (hr == S_OK) - { - hr = m_pDevice->GetSupportedFormats(guidContentType, pFormats); - CHECK_HR(hr, "Failed to get the content types"); - } - - // Set the WPD_PROPERTY_CAPABILITIES_FORMATS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_FORMATS, pFormats); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_FORMATS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES - * command. This message is sent when the client needs to know the typical properties for objects of - * a given format. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FORMAT - a GUID value specifying the format the caller is interested in. - * - * The driver should: - * - Return an IPortableDeviceKeyCollection in WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS, - * containing the property keys. - */ -HRESULT WpdCapabilities::OnGetSupportedFormatProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidObjectFormat = GUID_NULL; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // Get the object format whose supported properties have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FORMAT, &guidObjectFormat); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FORMAT"); - } - - // CoCreate a collection to store the supported properties. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // Add the supported properties for the specified object format to the collection. - if (hr == S_OK) - { - hr = m_pDevice->GetSupportedFormatProperties(guidObjectFormat, pKeys); - CHECK_HR(hr, "Failed to get supported properties for a format"); - } - - // Set the WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS, pKeys); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_FIXED_PROPERTY_ATTRIBUTES - * command. This message is sent when the client needs to know the property attributes that - * are the same for all objects of the given format. - * - * Typically, a driver treats objects of a given format the same. Many properties therefore will - * have attributes that are identical across all objects of that format. - * These can be returned here. There are some attributes which may be differ per object instance, - * which are not returned here. - * See WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FORMAT - a GUID value specifying the format the caller is interested in. - * - WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS - a collection of property keys containing a single value, - * which is the key identifying the specific property attributes we are requested to return. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES - * containing the fixed property attributes. - */ -HRESULT WpdCapabilities::OnGetFixedPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidObjectFormat = GUID_NULL; - PROPERTYKEY key = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pAttributes; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object format whose fixed property attributes have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FORMAT, &guidObjectFormat); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FORMAT"); - } - - // Get the property whose fixed property attributes have been requested - if(hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS, &key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS"); - } - - // CoCreate a collection to store the fixed property attributes. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Add the fixed property attributes for the specified object format and property - if (hr == S_OK) - { - hr = m_pDevice->GetFixedPropertyAttributes(guidObjectFormat, key, pAttributes); - CHECK_HR(hr, "Failed to get fixed property attributes"); - } - - // Set the WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES, pAttributes); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_EVENTS - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return all events supported by this driver should be returned as an - * IPortableDeviceKeyCollection in WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS. - * That includes custom commands, if any. - */ -HRESULT WpdCapabilities::OnGetSupportedEvents( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDevicePropVariantCollection> pEvents; - UNREFERENCED_PARAMETER(pParams); - - // CoCreate a collection to store the supported events. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pEvents); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Add the supported events to the collection. - if (hr == S_OK) - { - hr = m_pDevice->GetSupportedEvents(pEvents); - CHECK_HR(hr, "Failed to get supported events"); - } - - // Set the WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS, pEvents); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_EVENT_OPTIONS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_EVENT: a GUID value indicating the Event whose options should be returned. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS, containing - * the relevant options. - */ -HRESULT WpdCapabilities::OnGetEventOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID Event = GUID_NULL; - CComPtr<IPortableDeviceValues> pOptions; - - // Get the event whose options have been requested - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_EVENT, &Event); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_EVENT"); - } - - // CoCreate a collection to store the event options. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pOptions); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Add event options to the collection - if (hr == S_OK) - { - hr = m_pDevice->GetEventOptions(pOptions); - CHECK_HR(hr, "Failed to get event options"); - } - - // Set the WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS, pOptions); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS"); - } - - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/WpdCapabilities.h b/wpd/WpdServiceSampleDriver/WpdCapabilities.h deleted file mode 100644 index 2f13d3d9..00000000 --- a/wpd/WpdServiceSampleDriver/WpdCapabilities.h +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once - -class WpdCapabilities -{ -public: - WpdCapabilities(); - virtual ~WpdCapabilities(); - - HRESULT Initialize(_In_ FakeDevice* pDevice); - - HRESULT DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedCommands( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetCommandOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFunctionalCategories( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFunctionalObjects( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedContentTypes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedFormats( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedFormatProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFixedPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedEvents( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetEventOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - FakeDevice* m_pDevice; -}; - diff --git a/wpd/WpdServiceSampleDriver/WpdObjectEnum.cpp b/wpd/WpdServiceSampleDriver/WpdObjectEnum.cpp deleted file mode 100644 index 58f5faba..00000000 --- a/wpd/WpdServiceSampleDriver/WpdObjectEnum.cpp +++ /dev/null @@ -1,311 +0,0 @@ -#include "stdafx.h" - -#include "WpdObjectEnum.tmh" - -WpdObjectEnumerator::WpdObjectEnumerator() : m_pDevice(NULL) -{ - -} - -WpdObjectEnumerator::~WpdObjectEnumerator() -{ - -} - -HRESULT WpdObjectEnumerator::Initialize(_In_ FakeDevice* pDevice) -{ - if (pDevice == NULL) - { - return E_POINTER; - } - m_pDevice = pDevice; - return S_OK; -} - -HRESULT WpdObjectEnumerator::DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (hr == S_OK) - { - if (Command.fmtid != WPD_CATEGORY_OBJECT_ENUMERATION) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - } - - if (hr == S_OK) - { - if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_START_FIND.pid) - { - hr = OnStartFind(pParams, pResults); - CHECK_HR(hr, "Failed to begin enumeration"); - } - else if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_FIND_NEXT.pid) - { - hr = OnFindNext(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to find next object"); - } - } - else if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_END_FIND.pid) - { - hr = OnEndFind(pParams, pResults); - CHECK_HR(hr, "Failed to end enumeration"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_ENUMERATION_START_FIND - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID: the parent where we should start - * the enumeration. - * - WPD_PROPERTY_OBJECT_ENUMERATION_FILTER: the filter to use when doing - * enumeration. Since this parameter is optional, it may not exist. - * This driver currently ignores the filter parameter. - * - * The driver should: - * - Create a new context for this enumeration. - * - Set the string identifier in WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT for the newly created enumeration context. - * This value will be passed back during OnFindNext and OnEndFind. - */ -HRESULT WpdObjectEnumerator::OnStartFind( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszParentID = NULL; - ContextMap* pContextMap = NULL; - CAtlStringW strEnumContext; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier of the parent where the enumeration is starting from. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID, &wszParentID); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID"); - } - - // Get the client context map so we can store an enumeration context for this enumeration - // operation. - if (SUCCEEDED(hr)) - { - hr = GetClientContextMap(pParams, &pContextMap); - CHECK_HR(hr, "Failed to get client context map"); - } - - // Create and initialize a new enumeration context. - // Add the new enumertion context to the client context map. This context is used to - // keep track of this particular enumeration operation. - if (SUCCEEDED(hr)) - { - WpdObjectEnumeratorContext* pEnumeratorContext = new WpdObjectEnumeratorContext(); - - if (pEnumeratorContext != NULL) - { - ACCESS_SCOPE Scope = m_pDevice->GetAccessScope(pParams); - m_pDevice->InitializeEnumerationContext(Scope, wszParentID, pEnumeratorContext); - - // Add the enumeration context to the client context map. This calls AddRef() on pEnumeratorContext - hr = pContextMap->Add(pEnumeratorContext, strEnumContext); - CHECK_HR(hr, "Failed to add the enumeration context"); - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate enumeration context"); - } - - SAFE_RELEASE(pEnumeratorContext); - } - - // Set the WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT value in the results. - // This context identifier will be passed back during OnFindNext and OnEndFind to allow the driver to access it. - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, strEnumContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszParentID); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -HRESULT WpdObjectEnumerator::OnFindNext( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszEnumContext = NULL; - DWORD dwNumObjectsRequested = 0; - DWORD dwNumObjectsEnumerated = 0; - WpdObjectEnumeratorContext* pEnumeratorContext = NULL; - - CComPtr<IPortableDevicePropVariantCollection> pObjectIDCollection; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the enumeration context identifier for this enumeration operation. - // The enumeration context identifier is needed to lookup the specific - // enumeration context in the client context map for this enumeration operation. - // NOTE that more than one enumeration may be in progress. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, &wszEnumContext); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - // Get the number of objects requested for this enumeration call. - // The driver should always attempt to meet this requested value. - // If there are fewer children than requested, the driver should return the remaining - // children and a return code of S_FALSE. - if (SUCCEEDED(hr)) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_ENUMERATION_NUM_OBJECTS_REQUESTED, &dwNumObjectsRequested); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_NUM_OBJECTS_REQUESTED"); - } - } - - // Get the enumeration context for this enumeration operation. - if (SUCCEEDED(hr)) - { - hr = GetClientContext(pParams, wszEnumContext, (IUnknown**)&pEnumeratorContext); - CHECK_HR(hr, "Failed to get the enumeration context"); - } - - // CoCreate a collection to store the object identifiers being returned for this enumeration call. - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pObjectIDCollection); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - if (SUCCEEDED(hr)) - { - hr = m_pDevice->FindNext(dwNumObjectsRequested, pEnumeratorContext, pObjectIDCollection, &dwNumObjectsEnumerated); - CHECK_HR(hr, "Failed to get the next object"); - } - - // Set the collection of object identifiers enumerated in the results - if (SUCCEEDED(hr)) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_ENUMERATION_OBJECT_IDS, pObjectIDCollection); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_ENUMERATION_OBJECT_IDS"); - } - - // If the enumeration context reports that their are no more objects to return then return S_FALSE indicating to the - // caller that we are finished. - if (SUCCEEDED(hr)) - { - // Update the number of children we have enumerated and returned to the caller - pEnumeratorContext->m_ChildrenEnumerated += dwNumObjectsEnumerated; - - // Check the number requested against the number enumerated and set the HRESULT - // accordingly. - if (dwNumObjectsEnumerated < dwNumObjectsRequested) - { - // We returned less than the number of objects requested to the caller - hr = S_FALSE; - } - else - { - // We returned exactly the number of objects requested to the caller - hr = S_OK; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszEnumContext); - - SAFE_RELEASE(pEnumeratorContext); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_ENUMERATION_END_FIND - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT: the context the driver returned to - * the client in OnStartFind. - * - * The driver should: - * - Destroy any data associated with this context. - */ -HRESULT WpdObjectEnumerator::OnEndFind( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszEnumContext = NULL; - ContextMap* pContextMap = NULL; - - UNREFERENCED_PARAMETER(pResults); - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the enumeration context identifier for this enumeration operation. We will - // need this to lookup the specific enumeration context in the client context map. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, &wszEnumContext); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - // Get the client context map so we can retrieve the enumeration context for this enumeration - // operation using the WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT property value obtained above. - if (SUCCEEDED(hr)) - { - hr = GetClientContextMap(pParams, &pContextMap); - CHECK_HR(hr, "Failed to get the client context map"); - } - - // Destroy any data allocated/associated with the enumeration context and then remove it from the context map. - // We no longer need to keep this context around because the enumeration has been ended. - if (SUCCEEDED(hr)) - { - pContextMap->Remove(wszEnumContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszEnumContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - diff --git a/wpd/WpdServiceSampleDriver/WpdObjectEnum.h b/wpd/WpdServiceSampleDriver/WpdObjectEnum.h deleted file mode 100644 index 2b140242..00000000 --- a/wpd/WpdServiceSampleDriver/WpdObjectEnum.h +++ /dev/null @@ -1,105 +0,0 @@ -#pragma once - -// This class is used to store the context for a specific enumeration. -class WpdObjectEnumeratorContext : public IUnknown -{ -public: - WpdObjectEnumeratorContext() : - m_cRef(1), - m_TotalChildren(0), - m_ChildrenEnumerated(0), - m_Scope(FULL_DEVICE_ACCESS) - { - - } - - ~WpdObjectEnumeratorContext() - { - - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -private: - DWORD m_cRef; - -public: - bool HasMoreChildrenToEnumerate() - { - return ((m_TotalChildren - m_ChildrenEnumerated) > 0); - } - -// WpdObjectEnumeratorContext specific data -public: - ACCESS_SCOPE m_Scope; - CAtlStringW m_strParentObjectID; // object identifier of the object whose children are being enumerated - DWORD m_TotalChildren; // number of bytes transferred from the resource to the caller - DWORD m_ChildrenEnumerated; // number of children returned during the enumeration operation -}; - -class WpdObjectEnumerator -{ -public: - WpdObjectEnumerator(); - virtual ~WpdObjectEnumerator(); - - HRESULT Initialize(_In_ FakeDevice* pDevice); - - HRESULT DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnStartFind( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnFindNext( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnEndFind( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - FakeDevice* m_pDevice; -}; diff --git a/wpd/WpdServiceSampleDriver/WpdObjectManagement.cpp b/wpd/WpdServiceSampleDriver/WpdObjectManagement.cpp deleted file mode 100644 index 932735ae..00000000 --- a/wpd/WpdServiceSampleDriver/WpdObjectManagement.cpp +++ /dev/null @@ -1,297 +0,0 @@ -#include "stdafx.h" - -#include "WpdObjectManagement.tmh" - -WpdObjectManagement::WpdObjectManagement() : m_pDevice(NULL) -{ - -} - -WpdObjectManagement::~WpdObjectManagement() -{ - -} - -HRESULT WpdObjectManagement::Initialize(_In_ FakeDevice* pDevice) -{ - if (pDevice == NULL) - { - return E_POINTER; - } - m_pDevice = pDevice; - return S_OK; -} - -HRESULT WpdObjectManagement::DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - - HRESULT hr = S_OK; - - if (hr == S_OK) - { - if (Command.fmtid != WPD_CATEGORY_OBJECT_MANAGEMENT) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - } - - if (hr == S_OK) - { - if (Command.pid == WPD_COMMAND_OBJECT_MANAGEMENT_CREATE_OBJECT_WITH_PROPERTIES_ONLY.pid) - { - hr = OnCreateObjectWithPropertiesOnly(pParams, pResults); - CHECK_HR(hr, "Failed to create object"); - } - else if (Command.pid == WPD_COMMAND_OBJECT_MANAGEMENT_DELETE_OBJECTS.pid) - { - hr = OnDelete(pParams, pResults); - CHECK_HR(hr, "Failed to delete object"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - - return hr; -} - - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_MANAGEMENT_CREATE_OBJECT_WITH_PROPERTIES_ONLY - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_MANAGEMENT_CREATION_PROPERTIES: Contains an IPortableDeviceValues, describing - * properties of the new object. At the very least, it will contain: - * - WPD_OBJECT_NAME: The object name. - * - WPD_PARENT_ID: Identifies the parent object. The object should be inserted as a child of - * this parent (e.g. this would be the target directory in a file system based device). - * - * The driver should: - * - Create the object, and return its ID in WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID. - */ -HRESULT WpdObjectManagement::OnCreateObjectWithPropertiesOnly( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszObjectID = NULL; - - CComPtr<IPortableDeviceValues> pObjectProperties; - CComPtr<IPortableDeviceValues> pEventParams; - - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pEventParams); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - - // Get the Object Properties - if (SUCCEEDED(hr)) - { - hr = pParams->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_MANAGEMENT_CREATION_PROPERTIES, &pObjectProperties); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_CREATION_PROPERTIES"); - } - - // Save the object to the device here. - if (SUCCEEDED(hr)) - { - ACCESS_SCOPE Scope = m_pDevice->GetAccessScope(pParams); - hr = m_pDevice->CreatePropertiesOnlyObject(Scope, pObjectProperties, pEventParams, &pszObjectID); - CHECK_HR(hr, "Failed to save new (properties only) object to device"); - } - - if (SUCCEEDED(hr)) - { - // Create is successful, so we post an event. - // This is best effort, so errors are ignored - HRESULT hrEvent = PostWpdEvent(pParams, pEventParams); - CHECK_HR(hrEvent, "Failed post event for new object [%ws] (errors ignored)", pszObjectID); - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID, pszObjectID); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_MANAGEMENT_DELETE_OBJECTS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS: the ObjectIDs, indicating which objects to delete. These may - * contain children. - * - WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_OPTIONS: Flag parameter indicating delete options. Must be one - * of the following: - * - PORTABLE_DEVICE_DELETE_NO_RECURSION - Deletes the - * object only. This should fail if children exist. - * - PORTABLE_DEVICE_DELETE_WITH_RECURSION - Deletes this - * object and all children. - * - * The driver should: - * - If the flag is PORTABLE_DEVICE_DELETE_NO_RECURSION the driver should delete the - * specified object only. If the object still has children the driver should not delete - * the object and instead return HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION). - * - If the flag is PORTABLE_DEVICE_DELETE_WITH_RECURSION the driver should delete the - * specified object and all of its children. - * - Fill out the operation results in WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_RESULTS. It contains an IPortableDevicePropVariantCollection of - * VT_ERROR values indicating the success or failure of the operation for that element. - * Order is implicit, i.e. the first element of WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_RESULTS corresponds to the first element of WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS and so on. - * - The driver should return: - * - S_OK if all objects were deleted successfully. - * - S_FALSE if any object delete failed. - * - An error return indicates that the driver did not delete any objects, and - * WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_RESULTS is ignored. - */ -HRESULT WpdObjectManagement::OnDelete( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - - HRESULT hr = S_OK; - DWORD dwOptions = PORTABLE_DEVICE_DELETE_NO_RECURSION; - BOOL bDeleteFailed = FALSE; - VARTYPE vt = VT_EMPTY; - - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - CComPtr<IPortableDevicePropVariantCollection> pDeleteResults; - CComPtr<IPortableDeviceValues> pEventParams; - - if (hr == S_OK) - { - hr = pParams->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS, &pObjectIDs); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS"); - } - - // Ensure that this is a collection of VT_LPWSTR - if (hr == S_OK) - { - hr = pObjectIDs->GetType(&vt); - CHECK_HR(hr, "Failed to get the VARTYP of WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS"); - if (hr == S_OK) - { - if (vt != VT_LPWSTR) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS is not a collection of VT_LPWSTR"); - } - } - } - - if (hr == S_OK) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_OPTIONS, &dwOptions); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_OPTIONS"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pDeleteResults); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDevicePropVariantCollection"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pEventParams); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - DWORD cObjects = 0; - // Loop through the object list and attempt to delete - hr = pObjectIDs->GetCount(&cObjects); - CHECK_HR(hr, "Failed to get number of objects to delete"); - - if (hr == S_OK) - { - ACCESS_SCOPE Scope = m_pDevice->GetAccessScope(pParams); - - for(DWORD dwIndex = 0; dwIndex < cObjects; dwIndex++) - { - HRESULT hrTemp = S_OK; - PROPVARIANT pv = {0}; - - PropVariantInit(&pv); - // Get the next Object to delete - hr = pObjectIDs->GetAt(dwIndex, &pv); - CHECK_HR(hr, "Failed to get next object id at index %d", dwIndex); - if (hr == S_OK) - { - HRESULT hrDelete = S_OK; - PROPVARIANT pvResult = {0}; - - PropVariantInit(&pvResult); - - hrDelete = m_pDevice->DeleteObject(Scope, dwOptions, pv.pwszVal, pEventParams); - CHECK_HR(hrDelete, "Failed to delete object [%ws]", pv.pwszVal); - - if(FAILED(hrDelete)) - { - bDeleteFailed = TRUE; - } - else - { - // Delete is successful, so we post an event. - // This is best effort, so errors are ignored - HRESULT hrEvent = PostWpdEvent(pParams, pEventParams); - CHECK_HR(hrEvent, "Failed post event for deleted object [%ws] (errors ignored)", pv.pwszVal); - } - - // Clear event parameters for reuse - pEventParams->Clear(); - - // Save this result - pvResult.vt = VT_ERROR; - pvResult.scode = hrDelete; - hrTemp = pDeleteResults->Add(&pvResult); - PropVariantClear(&pvResult); - CHECK_HR(hrTemp, "Failed to add result for [%ws] to list of results", pv.pwszVal); - - PropVariantClear(&pv); - } - else - { - break; - } - } - } - } - - // Set the results - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_RESULTS, pDeleteResults); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_RESULTS"); - } - - // If an object failed to delete, make sure we return S_FALSE - if ((hr == S_OK) && (bDeleteFailed)) - { - hr = S_FALSE; - } - - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/WpdObjectManagement.h b/wpd/WpdServiceSampleDriver/WpdObjectManagement.h deleted file mode 100644 index b7a8413c..00000000 --- a/wpd/WpdServiceSampleDriver/WpdObjectManagement.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -class WpdObjectManagement -{ -public: - WpdObjectManagement(); - ~WpdObjectManagement(); - - HRESULT Initialize(_In_ FakeDevice* m_pDevice); - - HRESULT DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - - HRESULT OnCreateObjectWithPropertiesOnly( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnDelete( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - FakeDevice* m_pDevice; -}; diff --git a/wpd/WpdServiceSampleDriver/WpdObjectProperties.cpp b/wpd/WpdServiceSampleDriver/WpdObjectProperties.cpp deleted file mode 100644 index c9509f47..00000000 --- a/wpd/WpdServiceSampleDriver/WpdObjectProperties.cpp +++ /dev/null @@ -1,543 +0,0 @@ -#include "stdafx.h" - -#include "WpdObjectProperties.tmh" - -WpdObjectProperties::WpdObjectProperties() : m_pDevice(NULL) -{ -} - -WpdObjectProperties::~WpdObjectProperties() -{ - -} - -HRESULT WpdObjectProperties::Initialize(_In_ FakeDevice* pDevice) -{ - if (pDevice == NULL) - { - return E_POINTER; - } - m_pDevice = pDevice; - return S_OK; -} - -HRESULT WpdObjectProperties::DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (hr == S_OK) - { - if (Command.fmtid != WPD_CATEGORY_OBJECT_PROPERTIES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED)) - { - hr = OnGetSupportedProperties(pParams, pResults); - CHECK_HR(hr, "Failed to get supported properties"); - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET)) - { - hr = OnGetPropertyValues(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to get properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL)) - { - hr = OnGetAllPropertyValues(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to get all properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_SET)) - { - hr = OnSetPropertyValues(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to set properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES)) - { - hr = OnGetPropertyAttributes(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to get property attributes"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_DELETE)) - { - hr = OnDeleteProperties(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to delete properties"); - } - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose supported properties have - * been requested. - * - * - WPD_PROPERTY_OBJECT_PROPERTIES_FILTER: the filter to use when returning supported properties. - * Since this parameter is optional, it may not exist. - * ! This driver currently ignores the filter parameter. ! - * - * The driver should: - * - Return supported property keys for the specified object in WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS - */ -HRESULT WpdObjectProperties::OnGetSupportedProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose supported properties have been requested - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing string value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // CoCreate a collection to store the supported property keys. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // Add supported property keys for the specified object to the collection - if (hr == S_OK) - { - ACCESS_SCOPE Scope = m_pDevice->GetAccessScope(pParams); - hr = m_pDevice->GetSupportedProperties(Scope, wszObjectID, pKeys); - CHECK_HR(hr, "Failed to add supported property keys for object '%ws'", wszObjectID); - } - - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, pKeys); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values have been requested. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys, identifying which - * specific property values we are requested to return. - * - * The driver should: - * - Return all requested property values in WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES. If any property read failed, the corresponding value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were read successfully. - * - S_FALSE should be returned if any property read failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property values have been requested - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // Get the list of property keys for the property values the caller wants to retrieve from the specified object - if (hr == S_OK) - { - hr = pParams->GetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, &pKeys); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - // CoCreate a collection to store the property values. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Read the specified properties on the specified object and add the property values to the collection. - if (hr == S_OK) - { - ACCESS_SCOPE Scope = m_pDevice->GetAccessScope(pParams); - hr = m_pDevice->GetPropertyValues(Scope, wszObjectID, pKeys, pValues); - CHECK_HR(hr, "Failed to get property values for object '%ws'", wszObjectID); - } - - // S_OK or S_FALSE can be returned from GetPropertyValues( ). - // S_FALSE means that 1 or more property values could not be retrieved successfully. - // The value for the specified property should be set to an error HRESULT of - // the reason why the property could not be read. - // (e.g. If the property being requested is not supported on the object then an error of - // HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) should be set as the value. - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES value in the results. - HRESULT hrTemp = S_OK; - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, pValues); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values have been requested. - * - * The driver should: - * - Return all property values in WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES. If any property read failed, the corresponding value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were read successfully. - * - S_FALSE should be returned if any property read failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetAllPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property values have been requested - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // CoCreate a collection to store the property values. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // First we make a request for ALL supported property keys for the specified object. - // Next, we delegate to our helper function GetPropertyValuesForObject( ) passing - // the entire property key collection. This will reuse existing implementation - // in our driver to perform the GetAllPropertyValues operation. - if (hr == S_OK) - { - ACCESS_SCOPE Scope = m_pDevice->GetAccessScope(pParams); - hr = m_pDevice->GetAllPropertyValues(Scope, wszObjectID, pValues); - CHECK_HR(hr, "Failed to get all property values for object '%ws'", wszObjectID); - } - - // S_OK or S_FALSE can be returned from GetAllPropertyValues( ). - // S_FALSE means that 1 or more property values could not be retrieved successfully. - // The value for the specified property key should be set to the error HRESULT of - // the reason why the property could not be read. - // (i.e. an error of HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) if a property value was - // requested and is not supported by the specified object.) - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES value in the results - HRESULT hrTemp = S_OK; - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, pValues); - CHECK_HR(hrTemp, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES"); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_SET - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values we want to return. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES: an IPortableDeviceValues of values, identifying which - * specific property values we are requested to write. - * - * The driver should: - * - Write all requested property values. For each property, a write result should be returned in the - * write result property store. - * - If any property write failed, the corresponding write result value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were written successfully. - * - S_FALSE should be returned if any property write failed. - * - Any error return indicates that the driver did not write any results, and the caller will - * not attempt to unpack any property write results. - */ -HRESULT WpdObjectProperties::OnSetPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - bool bObjectChanged = false; - - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceValues> pWriteResults; - CComPtr<IPortableDeviceValues> pEventParams; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property values are being set - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // Get the caller-supplied property values requested to be set on the object - if (hr == S_OK) - { - hr = pParams->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, &pValues); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES"); - } - - // CoCreate a collection to store the property set operation results. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pWriteResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // CoCreate a collection to store the property set event parameters. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pEventParams); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Set the property values on the specified object - if (hr == S_OK) - { - ACCESS_SCOPE Scope = m_pDevice->GetAccessScope(pParams); - hr = m_pDevice->SetPropertyValues(Scope, wszObjectID, pValues, pWriteResults, pEventParams, &bObjectChanged); - CHECK_HR(hr, "Failed to set property values on object '%ws'", wszObjectID); - } - - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_WRITE_RESULTS value in the results - HRESULT hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_WRITE_RESULTS, pWriteResults); - CHECK_HR(hrTemp, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_WRITE_RESULTS"); - - if (FAILED(hrTemp)) - { - hr = hrTemp; - } - - if (SUCCEEDED(hr) && bObjectChanged) - { - // Post the event indicating the object has changed - hrTemp = PostWpdEvent(pParams, pEventParams); - CHECK_HR(hrTemp, "Failed post event for updated object [%ws] (errors ignored)", wszObjectID); - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property attributes we want to return. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys containing a single value, - * which is the key identifying the specific property attributes we are requested to return. - * - * The driver should: - * - Return the requested property attributes. If any property attributes failed to be retrieved, - * the corresponding value should be set to type VT_ERROR with the 'scode' member holding the - * HRESULT reason for the failure. - * - S_OK should be returned if all property attributes were read successfully. - * - S_FALSE should be returned if any property attribute failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - PROPERTYKEY Key = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pAttributes; - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the object identifier whose property attributes have been requested - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // Get the list of property keys whose attributes are being requested - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, &Key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - // CoCreate a collection to store the property attributes. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Get the attributes for the specified properties on the specified object and add them - // to the collection. - if (hr == S_OK) - { - ACCESS_SCOPE Scope = m_pDevice->GetAccessScope(pParams); - hr = m_pDevice->GetPropertyAtributes(Scope, wszObjectID, Key, pAttributes); - CHECK_HR(hr, "Failed to get property attributes"); - } - - if (SUCCEEDED(hr)) - { - // Set the WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_ATTRIBUTES value in the results - HRESULT hrTemp = S_OK; - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_ATTRIBUTES, pAttributes); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_ATTRIBUTES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_DELETE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose properties should be deleted. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys indicating which - * properties to delete. - * - * The driver should: - * - Delete the specified properties from the object. - * - S_OK should be returned if all specified properties were successfully deleted. - * - E_ACCESSDENIED should be returned if the client attempts to delete a property which is not deletable (i.e. - * WPD_PROPERTY_ATTRIBUTE_CAN_DELETE is FALSE for that property.) - */ -HRESULT WpdObjectProperties::OnDeleteProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = E_ACCESSDENIED; - - UNREFERENCED_PARAMETER(pParams); - UNREFERENCED_PARAMETER(pResults); - - // This driver has no properties which can be deleted. - - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/WpdObjectProperties.h b/wpd/WpdServiceSampleDriver/WpdObjectProperties.h deleted file mode 100644 index 95a0f94c..00000000 --- a/wpd/WpdServiceSampleDriver/WpdObjectProperties.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -class WpdObjectProperties -{ -public: - WpdObjectProperties(); - virtual ~WpdObjectProperties(); - - HRESULT Initialize(_In_ FakeDevice* pDevice); - - HRESULT DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetAllPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnSetPropertyValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnDeleteProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - FakeDevice* m_pDevice; -}; diff --git a/wpd/WpdServiceSampleDriver/WpdObjectPropertiesBulk.cpp b/wpd/WpdServiceSampleDriver/WpdObjectPropertiesBulk.cpp deleted file mode 100644 index a972d2cb..00000000 --- a/wpd/WpdServiceSampleDriver/WpdObjectPropertiesBulk.cpp +++ /dev/null @@ -1,1068 +0,0 @@ -#include "stdafx.h" - -#include "WpdObjectPropertiesBulk.tmh" - -#define MAX_OBJECTS_TO_RETURN 20 - -WpdObjectPropertiesBulk::WpdObjectPropertiesBulk() -{ - -} - -WpdObjectPropertiesBulk::~WpdObjectPropertiesBulk() -{ - -} - -HRESULT WpdObjectPropertiesBulk::Initialize(_In_ FakeDevice *pDevice) -{ - HRESULT hr = S_OK; - - if(pDevice == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - m_pDevice = pDevice; - return hr; -} - - -HRESULT WpdObjectPropertiesBulk::DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (Command.fmtid != WPD_CATEGORY_OBJECT_PROPERTIES_BULK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - - if (hr == S_OK) - { - if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_START)) - { - hr = OnGetValuesByObjectListStart(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to start bulk property operation"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_NEXT)) - { - hr = OnGetValuesByObjectListNext(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to do next bulk property operation"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_END)) - { - hr = OnGetValuesByObjectListEnd(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to end bulk property operation"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_START)) - { - hr = OnGetValuesByObjectFormatStart(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to start bulk property operation"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_NEXT)) - { - hr = OnGetValuesByObjectFormatNext(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to do next bulk property operation"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_END)) - { - hr = OnGetValuesByObjectFormatEnd(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to end bulk property operation "); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_START)) - { - hr = OnSetValuesByObjectListStart(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to set bulk property operation"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_NEXT)) - { - hr = OnSetValuesByObjectListNext(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to set bulk property operation"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_END)) - { - hr = OnSetValuesByObjectListEnd(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to set bulk property operation"); - } - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_START - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_OBJECT_IDS: identifies the objects whose property - * values we want to return. - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_PROPERTY_KEYS: a collection of property keys, identifying which - * specific property values we are requested to return. If this property doesn't exist, - * then the client is asking for all values. - * - * The driver should: - * - Create a new context for this bulk property operation. - * - Return an identifier for the context in WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT. - */ -HRESULT WpdObjectPropertiesBulk::OnGetValuesByObjectListStart( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - CComPtr<IPortableDeviceKeyCollection> pKeys; - ContextMap* pContextMap = NULL; - - // Get the IPortableDevicePropVariantCollection which contains the collection - // of object identifiers the bulk operation is being performed on. - hr = pParams->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_OBJECT_IDS, &pObjectIDs); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_BULK_OBJECT_IDS"); - - // Get the IPortableDeviceKeyCollection which contains the collection - // keys of properties being read on the multiple objects. - if (SUCCEEDED(hr)) - { - hr = pParams->GetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_PROPERTY_KEYS, &pKeys); - if (FAILED(hr)) - { - // Client is asking for all properties. - pKeys = NULL; - hr = S_OK; - } - } - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - LPWSTR pwszContext = NULL; - ACCESS_SCOPE Scope = m_pDevice->GetAccessScope(pParams); - hr = CreateBulkPropertiesContext(Scope, pContextMap, pObjectIDs, pKeys, &pwszContext); - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, pwszContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - } - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_NEXT - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT: the context the driver returned to - * the client in OnGetValuesByObjectListStart. - * - * The driver should: - * - Return the next set of property values in WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES. - * If there are no more properties to be read an - * empty collection should be returned. - * - It is up to the driver to return as many object property values as it wants. If zero values are returned - * it is assumed the bulk operation is complete and the WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_END - * will be called next. - * - * - S_OK should be returned if the collection can be returned successfully. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectPropertiesBulk::OnGetValuesByObjectListNext( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pwszContext = NULL; - BulkPropertiesContext* pContext = NULL; - DWORD cObjects = 0; - CComPtr<IPortableDeviceValuesCollection> pCollection; - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, &pwszContext); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT from IPortableDeviceValues"); - - // Get the bulk property operation context - if (SUCCEEDED(hr)) - { - hr = GetClientContext(pParams, pwszContext, (IUnknown**) &pContext); - CHECK_HR(hr, "Failed to get bulk property context"); - } - - if (SUCCEEDED(hr)) - { - hr = pContext->ObjectIDs->GetCount(&cObjects); - CHECK_HR(hr, "Failed to get number of objectIDs from bulk properties context"); - } - - if (SUCCEEDED(hr)) - { - cObjects = cObjects - pContext->NextObject; - if(cObjects > MAX_OBJECTS_TO_RETURN) - { - cObjects = MAX_OBJECTS_TO_RETURN; - } - } - - // Make sure the the collection holds VT_LPWSTR values. - if (SUCCEEDED(hr)) - { - hr = pContext->ObjectIDs->ChangeType(VT_LPWSTR); - CHECK_HR(hr, "Failed to change objectIDs collection to VT_LPWSTR"); - } - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValuesCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValuesCollection, - (VOID**) &pCollection); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValuesCollection"); - } - - if (SUCCEEDED(hr)) - { - for (DWORD dwIndex = pContext->NextObject, dwCount = 0; dwCount < cObjects; dwCount++, dwIndex++) - { - CComPtr<IPortableDeviceValues> pValues; - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - hr = pContext->ObjectIDs->GetAt(dwIndex, &pv); - CHECK_HR(hr, "Failed to get next object ID from bulk properties context"); - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValuesCollection"); - } - - if (SUCCEEDED(hr)) - { - // If a key list was supplied, get the specified object properties, otherwise get all - // properties. - if(pContext->Properties != NULL) - { - hr = m_pDevice->GetPropertyValues(pContext->Scope, pv.pwszVal, pContext->Properties, pValues); - CHECK_HR(hr, "Failed to get property values for [%ws]", pv.pwszVal); - } - else - { - hr = m_pDevice->GetAllPropertyValues(pContext->Scope, pv.pwszVal, pValues); - CHECK_HR(hr, "Failed to get property values for [%ws]", pv.pwszVal); - } - } - - // Add the ObjectID to the returned results - if (SUCCEEDED(hr)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ID, pv.pwszVal); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID for %ws", pv.pwszVal); - } - - if (SUCCEEDED(hr)) - { - hr = pCollection->Add(pValues); - CHECK_HR(hr, "Failed to add IPortableDeviceValues to IPortableDeviceValuesCollection"); - } - - PropVariantClear(&pv); - - pContext->NextObject += 1; - } - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES, pCollection); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - - SAFE_RELEASE(pContext); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_END - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT: the context the driver returned to - * the client in OnGetValuesByObjectListStart. - * - * The driver should: - * - Destroy any resources associated with this context. - */ -HRESULT WpdObjectPropertiesBulk::OnGetValuesByObjectListEnd( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pwszContext = NULL; - ContextMap* pContextMap = NULL; - UNREFERENCED_PARAMETER(pResults); - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, &pwszContext); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT from IPortableDeviceValues"); - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - hr = DestroyBulkPropertiesContext(pContextMap, pwszContext); - CHECK_HR(hr, "Failed to destroy bulk property context %ws", pwszContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_START - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_OBJECT_FORMAT: Identifies the format of the objects the - * client is interested in. - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_PARENT_OBJECT_ID: Identifies the parent object from which the - * operation should start. - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_DEPTH: Indicates the hierarchical depth of the operation - * from the parent object. - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_PROPERTY_KEYS: a collection of property keys, identifying which - * specific property values we are requested to return. If this doesn't exist, then - * ALL object proeprties should be returned for the specified objects. - * - * The driver should: - * - Create a new context for this bulk property operation. - * - Return an identifier for the context in WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT. - */ -HRESULT WpdObjectPropertiesBulk::OnGetValuesByObjectFormatStart( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - GUID guidObjectFormat = GUID_NULL; - LPWSTR pszParentObjectID = NULL; - DWORD dwDepth = 0; - ContextMap* pContextMap = NULL; - - // Get the object format. - hr = pParams->GetGuidValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_OBJECT_FORMAT, &guidObjectFormat); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_BULK_OBJECT_FORMAT"); - - // Get the parent object id. - if (SUCCEEDED(hr)) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_PARENT_OBJECT_ID, &pszParentObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_BULK_PARENT_OBJECT_ID"); - } - - // Get the depth. - if (SUCCEEDED(hr)) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_DEPTH, &dwDepth); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_BULK_DEPTH"); - } - - // Get the IPortableDeviceKeyCollection which contains the collection - // keys of properties being read on the multiple objects. - if (SUCCEEDED(hr)) - { - hr = pParams->GetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_PROPERTY_KEYS, &pKeys); - if (FAILED(hr)) - { - // Client is asking for all properties. - pKeys = NULL; - hr = S_OK; - } - } - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - LPWSTR pwszContext = NULL; - ACCESS_SCOPE Scope = m_pDevice->GetAccessScope(pParams); - hr = CreateBulkPropertiesContext(Scope, pContextMap, guidObjectFormat, pszParentObjectID, dwDepth, pKeys, &pwszContext); - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, pwszContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszParentObjectID); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_NEXT - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT: the context the driver returned to - * the client in OnGetValuesByObjectFormatStart. - * - * The driver should: - * - Return the next set of property values in WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES. - * If there are no more properties to be read an - * empty collection should be returned. - * - It is up to the driver to return as many object property values as it wants. If zero values are returned - * it is assumed the bulk operation is complete and the WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_END - * will be called next. - * - * - S_OK should be returned if the collection can be returned successfully. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectPropertiesBulk::OnGetValuesByObjectFormatNext( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pwszContext = NULL; - BulkPropertiesContext* pContext = NULL; - DWORD cObjects = 0; - CComPtr<IPortableDeviceValuesCollection> pCollection; - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, &pwszContext); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT from IPortableDeviceValues"); - - // Get the bulk property operation context - if (SUCCEEDED(hr)) - { - hr = GetClientContext(pParams, pwszContext, (IUnknown**) &pContext); - CHECK_HR(hr, "Failed to get bulk property context"); - } - - // Make sure the the collection holds VT_LPWSTR values. - if (SUCCEEDED(hr)) - { - hr = pContext->ObjectIDs->ChangeType(VT_LPWSTR); - CHECK_HR(hr, "Failed to change objectIDs collection to VT_LPWSTR"); - } - - if (SUCCEEDED(hr)) - { - hr = pContext->ObjectIDs->GetCount(&cObjects); - CHECK_HR(hr, "Failed to get number of objectIDs from bulk properties context"); - } - - if (SUCCEEDED(hr)) - { - cObjects = cObjects - pContext->NextObject; - if(cObjects > MAX_OBJECTS_TO_RETURN) - { - cObjects = MAX_OBJECTS_TO_RETURN; - } - } - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValuesCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValuesCollection, - (VOID**) &pCollection); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValuesCollection"); - } - - if (SUCCEEDED(hr)) - { - for (DWORD dwIndex = pContext->NextObject, dwCount = 0; dwCount < cObjects; dwCount++, dwIndex++) - { - CComPtr<IPortableDeviceValues> pValues; - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - hr = pContext->ObjectIDs->GetAt(dwIndex, &pv); - CHECK_HR(hr, "Failed to get next object ID from bulk properties context"); - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValuesCollection"); - } - - if (SUCCEEDED(hr)) - { - // If a key list was supplied, get the specified object properties, other get all - // properties. - if(pContext->Properties != NULL) - { - hr = m_pDevice->GetPropertyValues(pContext->Scope, pv.pwszVal, pContext->Properties, pValues); - CHECK_HR(hr, "Failed to get property values for [%ws]", pv.pwszVal); - } - else - { - hr = m_pDevice->GetAllPropertyValues(pContext->Scope,pv.pwszVal, pValues); - CHECK_HR(hr, "Failed to get property values for [%ws]", pv.pwszVal); - } - } - - // Add the ObjectID to the returned results - if (SUCCEEDED(hr)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ID, pv.pwszVal); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID for %ws", pv.pwszVal); - } - - if (SUCCEEDED(hr)) - { - hr = pCollection->Add(pValues); - CHECK_HR(hr, "Failed to add IPortableDeviceValues to IPortableDeviceValuesCollection"); - } - - PropVariantClear(&pv); - pContext->NextObject++; - } - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES, pCollection); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - SAFE_RELEASE(pContext); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_END - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT: the context the driver returned to - * the client in OnGetValuesByObjectFormatStart. - * - * The driver should: - * - Destroy any resources associated with this context. - */ -HRESULT WpdObjectPropertiesBulk::OnGetValuesByObjectFormatEnd( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pwszContext = NULL; - ContextMap* pContextMap = NULL; - UNREFERENCED_PARAMETER(pResults); - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, &pwszContext); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT from IPortableDeviceValues"); - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - hr = DestroyBulkPropertiesContext(pContextMap, pwszContext); - CHECK_HR(hr, "Failed to destroy bulk property context %ws", pwszContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_START - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES: holds a collection of IPortableDeviceValues which - * indicate which object properties to set. - * - * The driver should: - * - Create a new context for this bulk property operation. - * - Return an identifier for the context in WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT. - */ -HRESULT WpdObjectPropertiesBulk::OnSetValuesByObjectListStart( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValuesCollection> pValuesCollection; - ContextMap* pContextMap = NULL; - - // Get the IPortableDevicePropVariantCollection which contains the collection - // of object identifiers the bulk operation is being performed on. - hr = pParams->GetIPortableDeviceValuesCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES, &pValuesCollection); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES"); - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - LPWSTR pwszContext = NULL; - ACCESS_SCOPE Scope = m_pDevice->GetAccessScope(pParams); - hr = CreateBulkPropertiesContext(Scope, pContextMap, pValuesCollection, &pwszContext); - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, pwszContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - } - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_NEXT - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT: the context the driver returned to - * the client in OnGetValuesByObjectListStart. - * - * The driver should: - * - Write the next set of property values, and return the write results in WPD_PROPERTY_OBJECT_PROPERTIES_BULK_WRITE_RESULTS. - * If there are no more properties to be written, an empty collection should be returned. - * - It is up to the driver to write as many object property values as it wants. If zero write results are returned - * it is assumed the bulk operation is complete and the WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_END - * will be called next. - * - * - S_OK should be returned if the collection can be returned successfully. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectPropertiesBulk::OnSetValuesByObjectListNext( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pwszContext = NULL; - BulkPropertiesContext* pContext = NULL; - DWORD cObjects = 0; - CComPtr<IPortableDeviceValues> pEventParams; - CComPtr<IPortableDeviceValuesCollection> pWriteResults; - CComPtr<IPortableDeviceValuesCollection> pValuesCollection; - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, &pwszContext); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT from IPortableDeviceValues"); - - // Get the bulk property operation context - if (SUCCEEDED(hr)) - { - hr = GetClientContext(pParams, pwszContext, (IUnknown**) &pContext); - CHECK_HR(hr, "Failed to get bulk property context"); - } - - // Make sure the the collection holds a ValuesCollection, then get the number of elements. - if (SUCCEEDED(hr)) - { - if(pContext->ValuesCollection != NULL) - { - hr = pContext->ValuesCollection->GetCount(&cObjects); - CHECK_HR(hr, "Failed to get number of objectIDs from bulk properties context"); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Incorrect context specified - this context does not contain a values collection"); - } - } - - // Create the collection to hold the write results - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValuesCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValuesCollection, - (VOID**) &pWriteResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValuesCollection"); - } - - // Create the collection to hold the event parameters - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pEventParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (SUCCEEDED(hr)) - { - for (DWORD dwIndex = pContext->NextObject; dwIndex < cObjects; dwIndex++) - { - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceValues> pSetResults; - - bool bObjectChanged = false; - - hr = pContext->ValuesCollection->GetAt(dwIndex, &pValues); - CHECK_HR(hr, "Failed to get next values from bulk properties context"); - - // CoCreate a collection to store the per object results. - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pSetResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (SUCCEEDED(hr)) - { - LPWSTR pszObjectID = NULL; - - // Get which object this is for - hr = pValues->GetStringValue(WPD_OBJECT_ID, &pszObjectID); - if (SUCCEEDED(hr)) - { - hr = m_pDevice->SetPropertyValues(pContext->Scope, pszObjectID, pValues, pSetResults, pEventParams, &bObjectChanged); - CHECK_HR(hr, "Failed to get count of values"); - } - - if (SUCCEEDED(hr)) - { - // Ensure the write results contain which ObjectID this was for - hr = pSetResults->SetStringValue(WPD_OBJECT_ID, pszObjectID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID in write results"); - - if (SUCCEEDED(hr) && bObjectChanged) - { - // set property values is successful and object has changed, so we post an event. - // This is best effort, so errors are ignored - HRESULT hrEvent = PostWpdEvent(pParams, pEventParams); - CHECK_HR(hrEvent, "Failed post event for updated object [%ws] (errors ignored)", pszObjectID); - } - pEventParams->Clear(); - } - - CoTaskMemFree(pszObjectID); - } - - if (SUCCEEDED(hr)) - { - hr = pWriteResults->Add(pSetResults); - CHECK_HR(hr, "Failed to add IPortableDeviceValues to IPortableDeviceValuesCollection"); - } - - pContext->NextObject++; - } - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_WRITE_RESULTS, pWriteResults); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_BULK_WRITE_RESULTS"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - - SAFE_RELEASE(pContext); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_END - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT: the context the driver returned to - * the client in OnSetValuesByObjectListStart. - * - * The driver should: - * - Destroy any resources associated with this context. - */ -HRESULT WpdObjectPropertiesBulk::OnSetValuesByObjectListEnd( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pwszContext = NULL; - ContextMap* pContextMap = NULL; - UNREFERENCED_PARAMETER(pResults); - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, &pwszContext); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT from IPortableDeviceValues"); - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - hr = DestroyBulkPropertiesContext(pContextMap, pwszContext); - CHECK_HR(hr, "Failed to destroy bulk property context %ws", pwszContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -HRESULT WpdObjectPropertiesBulk::CreateBulkPropertiesContext( - _In_ ACCESS_SCOPE Scope, - _In_ ContextMap* pContextMap, - _In_ IPortableDevicePropVariantCollection* pObjectIDs, - _In_ IPortableDeviceKeyCollection* pProperties, - _Outptr_result_nullonfailure_ LPWSTR* ppszBulkPropertiesContext) -{ - HRESULT hr = S_OK; - BulkPropertiesContext* pContext = NULL; - CAtlStringW strKey; - - if((pContextMap == NULL) || - (pObjectIDs == NULL) || - (ppszBulkPropertiesContext == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *ppszBulkPropertiesContext = NULL; - - pContext = new BulkPropertiesContext(); - if(pContext == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new bulk properties context"); - } - - if (SUCCEEDED(hr)) - { - pContext->ObjectIDs = pObjectIDs; - pContext->Properties = pProperties; - pContext->Scope = Scope; - - hr = pContextMap->Add(pContext, strKey); - CHECK_HR(hr, "Failed to insert bulk property operation context into our context Map"); - } - - if (SUCCEEDED(hr)) - { - *ppszBulkPropertiesContext = AtlAllocTaskWideString(strKey); - if (*ppszBulkPropertiesContext == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate bulk properties context"); - } - } - - SAFE_RELEASE(pContext); - - return hr; -} - -HRESULT WpdObjectPropertiesBulk::CreateBulkPropertiesContext( - _In_ ACCESS_SCOPE Scope, - _In_ ContextMap* pContextMap, - _In_ REFGUID guidObjectFormat, - _In_ LPCWSTR pszParentObjectID, - _In_ DWORD dwDepth, - _In_ IPortableDeviceKeyCollection* pProperties, - _Outptr_result_nullonfailure_ LPWSTR* ppszBulkPropertiesContext) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - - if((pContextMap == NULL) || - (pszParentObjectID == NULL) || - (ppszBulkPropertiesContext == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *ppszBulkPropertiesContext = NULL; - - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pObjectIDs); - CHECK_HR(hr, "Failed to CoCreate CLSID_IPortableDevicePropVariantCollection"); - - if (SUCCEEDED(hr)) - { - hr = m_pDevice->GetObjectIDsByFormat(Scope, guidObjectFormat, pszParentObjectID, dwDepth, pObjectIDs); - CHECK_HR(hr, "Faield to get list of object ids by format"); - } - - if (SUCCEEDED(hr)) - { - hr = CreateBulkPropertiesContext(Scope, pContextMap, pObjectIDs, pProperties, ppszBulkPropertiesContext); - } - - return hr; -} - -HRESULT WpdObjectPropertiesBulk::CreateBulkPropertiesContext( - _In_ ACCESS_SCOPE Scope, - _In_ ContextMap* pContextMap, - _In_ IPortableDeviceValuesCollection* pValuesCollection, - _Outptr_result_nullonfailure_ LPWSTR* ppszBulkPropertiesContext) -{ - HRESULT hr = S_OK; - BulkPropertiesContext* pContext = NULL; - CAtlStringW strKey; - - if((pContextMap == NULL) || - (pValuesCollection == NULL) || - (ppszBulkPropertiesContext == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *ppszBulkPropertiesContext = NULL; - - pContext = new BulkPropertiesContext(); - if(pContext == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new bulk properties context"); - } - - if (SUCCEEDED(hr)) - { - pContext->ValuesCollection = pValuesCollection; - pContext->Scope = Scope; - - hr = pContextMap->Add(pContext, strKey); - CHECK_HR(hr, "Failed to insert bulk property operation context into our context Map"); - } - - if (SUCCEEDED(hr)) - { - *ppszBulkPropertiesContext = AtlAllocTaskWideString(strKey); - if (*ppszBulkPropertiesContext == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate bulk properties context"); - } - } - - SAFE_RELEASE(pContext); - - return hr; -} - -HRESULT WpdObjectPropertiesBulk::DestroyBulkPropertiesContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszBulkPropertiesContext) -{ - HRESULT hr = S_OK; - - CAtlStringW strKey = pszBulkPropertiesContext; - pContextMap->Remove(strKey); - - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/WpdObjectPropertiesBulk.h b/wpd/WpdServiceSampleDriver/WpdObjectPropertiesBulk.h deleted file mode 100644 index 52ec7ed1..00000000 --- a/wpd/WpdServiceSampleDriver/WpdObjectPropertiesBulk.h +++ /dev/null @@ -1,148 +0,0 @@ -#pragma once - -// This class is used to store the context for a specific enumeration. -// Currently, this is done by storing the object index. -class BulkPropertiesContext : public IUnknown -{ -public: - BulkPropertiesContext() : - Scope(FULL_DEVICE_ACCESS), - NextObject(0), - m_cRef(1) - { - - } - - ~BulkPropertiesContext() - { - - } - - ACCESS_SCOPE Scope; - CComPtr<IPortableDevicePropVariantCollection> ObjectIDs; - DWORD NextObject; - CComPtr<IPortableDeviceKeyCollection> Properties; - CComPtr<IPortableDeviceValuesCollection> ValuesCollection; - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -private: - DWORD m_cRef; -}; - -class WpdObjectPropertiesBulk -{ -public: - WpdObjectPropertiesBulk(); - ~WpdObjectPropertiesBulk(); - - HRESULT Initialize(_In_ FakeDevice *pDevice); - - HRESULT DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetValuesByObjectListStart( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetValuesByObjectListNext( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetValuesByObjectListEnd( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetValuesByObjectFormatStart( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetValuesByObjectFormatNext( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetValuesByObjectFormatEnd( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnSetValuesByObjectListStart( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnSetValuesByObjectListNext( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnSetValuesByObjectListEnd( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - HRESULT CreateBulkPropertiesContext( - _In_ ACCESS_SCOPE Scope, - _In_ ContextMap* pContextMap, - _In_ IPortableDevicePropVariantCollection* pObjectIDs, - _In_ IPortableDeviceKeyCollection* pProperties, - _Outptr_result_nullonfailure_ LPWSTR* ppszBulkPropertiesContext); - - HRESULT CreateBulkPropertiesContext( - _In_ ACCESS_SCOPE Scope, - _In_ ContextMap* pContextMap, - _In_ REFGUID guidObjectFormat, - _In_ LPCWSTR pszParentObjectID, - _In_ DWORD dwDepth, - _In_ IPortableDeviceKeyCollection* pProperties, - _Outptr_result_nullonfailure_ LPWSTR* ppszBulkPropertiesContext); - - HRESULT CreateBulkPropertiesContext( - _In_ ACCESS_SCOPE Scope, - _In_ ContextMap* pContextMap, - _In_ IPortableDeviceValuesCollection* pValuesCollection, - _Outptr_result_nullonfailure_ LPWSTR* ppszBulkPropertiesContext); - - HRESULT DestroyBulkPropertiesContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszBulkPropertiesContext); - - FakeDevice* m_pDevice; -}; diff --git a/wpd/WpdServiceSampleDriver/WpdObjectResources.cpp b/wpd/WpdServiceSampleDriver/WpdObjectResources.cpp deleted file mode 100644 index 4f6341ac..00000000 --- a/wpd/WpdServiceSampleDriver/WpdObjectResources.cpp +++ /dev/null @@ -1,465 +0,0 @@ -#include "stdafx.h" - -#include "WpdObjectResources.tmh" - -WpdObjectResources::WpdObjectResources() : m_pDevice(NULL) -{ - -} - -WpdObjectResources::~WpdObjectResources() -{ - -} - -HRESULT WpdObjectResources::Initialize(_In_ FakeDevice* pDevice) -{ - if (pDevice == NULL) - { - return E_POINTER; - } - m_pDevice = pDevice; - return S_OK; -} - -HRESULT WpdObjectResources::DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (hr == S_OK) - { - if (Command.fmtid != WPD_CATEGORY_OBJECT_RESOURCES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_GET_SUPPORTED)) - { - hr = OnGetSupportedResources(pParams, pResults); - CHECK_HR(hr, "Failed to get supported resources"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_OPEN)) - { - hr = OnOpenResource(pParams, pResults); - CHECK_HR(hr, "Failed to open resource"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_READ)) - { - hr = OnReadResource(pParams, pResults); - CHECK_HR(hr, "Failed to read resource"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_CLOSE)) - { - hr = OnCloseResource(pParams, pResults); - CHECK_HR(hr, "Failed to close resource"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_GET_ATTRIBUTES)) - { - hr = OnGetResourceAttributes(pParams, pResults); - CHECK_HR(hr, "Failed to get resource attributes"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_GET_SUPPORTED - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID: identifies the object whose resources we want to return. - * - * The driver should: - * - Return all resources for this object in WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS. - */ -HRESULT WpdObjectResources::OnGetSupportedResources( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // Get the Object ID - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID, &wszObjectID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID"); - } - - // Create the collection to hold the resource keys - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - if (hr == S_OK) - { - ACCESS_SCOPE Scope = m_pDevice->GetAccessScope(pParams); - hr = m_pDevice->GetSupportedResources(Scope, wszObjectID, pKeys); - CHECK_HR(hr, "Failed to get supported resources for object '%ws'", wszObjectID); - } - - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS, pKeys); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_GET_ATTRIBUTES - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID: identifies the object whose resource attributes we want to return. - * - WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS: a collection of property keys containing a single value, - * which is the key identifying the specific resource we are requested to return attributes for. - * - * The driver should: - * - Return the requested property attributes in WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_ATTRIBUTES. - * If any resource attributes failed to be retrieved, - * the corresponding value should be set to type VT_ERROR with the 'scode' member holding the - * HRESULT reason for the failure. - * - S_OK should be returned if all resource attributes were read successfully. - * - S_FALSE should be returned if any resource attribute failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - * - */ -HRESULT WpdObjectResources::OnGetResourceAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - PROPERTYKEY Key = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pAttributes; - - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID"); - } - - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS, &Key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - ACCESS_SCOPE Scope = m_pDevice->GetAccessScope(pParams); - hr = m_pDevice->GetResourceAttributes(Scope, wszObjectID, Key, pAttributes); - CHECK_HR(hr, "Failed to get resource attributes"); - } - - if (SUCCEEDED(hr)) - { - HRESULT hrTemp = S_OK; - - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_ATTRIBUTES, pAttributes); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_ATTRIBUTES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_OPEN - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID: the object identifier of the - * object which contains the specified resource - * - * - WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS: the specified resource - * to open - * - * - WPD_PROPERTY_OBJECT_RESOURCES_ACCESS_MODE: the access mode to which to - * open the specified resource - * - * The driver should: - * - Create a new context for this resource operation. - * - Return an identifier for the context in WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT. - * - Set the optimal transfer size in WPD_PROPERTY_OBJECT_RESOURCES_OPTIMAL_TRANSFER_BUFFER_SIZE - * - */ -HRESULT WpdObjectResources::OnOpenResource( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - PROPERTYKEY Key = WPD_PROPERTY_NULL; - DWORD dwMode = STGM_READ; - CAtlStringW strStrObjectID; - CAtlStringW strResourceContext; - ContextMap* pContextMap = NULL; - - // Get the Object identifier of the object which contains the specified resource - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID, &wszObjectID); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID"); - } - - // Get the resource key - if (SUCCEEDED(hr)) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS, &Key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS"); - } - - // Get the access mode - if (SUCCEEDED(hr)) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_ACCESS_MODE, &dwMode); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_ACCESS_MODE"); - } - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = GetClientContextMap(pParams, &pContextMap); - CHECK_HR(hr, "Failed to get the client context map"); - } - - // Create a new resource operation context, initialize it, and add it to the client context map. - if (SUCCEEDED(hr)) - { - WpdObjectResourceContext* pResourceContext = new WpdObjectResourceContext(); - if (pResourceContext != NULL) - { - ACCESS_SCOPE Scope = m_pDevice->GetAccessScope(pParams); - hr = m_pDevice->OpenResource(Scope, wszObjectID, Key, dwMode, pResourceContext); - CHECK_HR(hr, "Failed to open resource"); - - if (SUCCEEDED(hr)) - { - // Add the resource context to the context map, this calls AddRef() on pResourceContext - hr = pContextMap->Add(pResourceContext, strResourceContext); - CHECK_HR(hr, "Failed to add the resource context"); - } - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate resource context"); - } - SAFE_RELEASE(pResourceContext); - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, strResourceContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Set the optimal buffer size - if (SUCCEEDED(hr)) - { - hr = pResults->SetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_OPTIMAL_TRANSFER_BUFFER_SIZE, FILE_OPTIMAL_READ_BUFFER_SIZE_VALUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_OPTIMAL_TRANSFER_BUFFER_SIZE value"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszObjectID); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_READ - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT: the context the driver returned to - * the client in OnOpenResource. - * - WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ: the number of bytes to - * read from the resource. - * - * The driver should: - * - Read data associated with the resource and return it back to the caller in - * WPD_PROPERTY_OBJECT_RESOURCES_DATA. - * - Report the number of bytes actually read from the resource in - * WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_READ. This number may be smaller - * than WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ when reading the last - * chunk of data from the resource. - */ -HRESULT WpdObjectResources::OnReadResource( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszResourceContext = NULL; - DWORD dwNumBytesToRead = 0; - DWORD dwNumBytesRead = 0; - BYTE* pBuffer = NULL; - WpdObjectResourceContext* pResourceContext = NULL; - - // Get the enumeration context identifier for this enumeration operation. We will - // need this to lookup the specific enumeration context in the client context map. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, &wszResourceContext); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Get the number of bytes to read - if (SUCCEEDED(hr)) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ, &dwNumBytesToRead); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ"); - } - - // Allocate the destination buffer - if (SUCCEEDED(hr)) - { - pBuffer = reinterpret_cast<BYTE *>(CoTaskMemAlloc(dwNumBytesToRead)); - if (pBuffer == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate the destination buffer"); - } - } - - // Get the client context map so we can retrieve the resource context for this resource - // operation using the WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT property value obtained above. - if (SUCCEEDED(hr)) - { - hr = GetClientContext(pParams, wszResourceContext, (IUnknown**)&pResourceContext); - CHECK_HR(hr, "Failed to get the resource context"); - } - - // Read the next chunk of data for this request - if (SUCCEEDED(hr)) - { - hr = m_pDevice->ReadResourceData(pResourceContext, pBuffer, dwNumBytesToRead, &dwNumBytesRead); - CHECK_HR(hr, "Failed to read %d bytes from resource", dwNumBytesToRead); - } - - if (SUCCEEDED(hr)) - { - pResourceContext->m_BytesTransferred += dwNumBytesRead; - hr = pResults->SetBufferValue(WPD_PROPERTY_OBJECT_RESOURCES_DATA, pBuffer, dwNumBytesRead); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_DATA"); - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_READ, dwNumBytesRead); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_READ"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszResourceContext); - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pBuffer); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_CLOSE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT: the context the driver returned to - * the client in OnOpenResource. - * - * The driver should: - * - Destroy any data associated with this context. - */ -HRESULT WpdObjectResources::OnCloseResource( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszResourceContext = NULL; - ContextMap* pContextMap = NULL; - - UNREFERENCED_PARAMETER(pResults); - - // First get ALL parameters for this command. If we cannot get ALL parameters - // then E_INVALIDARG should be returned and no further processing should occur. - - // Get the resource context identifier for this resource operation. We will - // need this to lookup the specific resource context in the client context map. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, &wszResourceContext); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Get the client context map so we can retrieve the resource context for this resource - // operation using the WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT property value obtained above. - if (SUCCEEDED(hr)) - { - hr = GetClientContextMap(pParams, &pContextMap); - CHECK_HR(hr, "Failed to get the client context map"); - } - - // Destroy any data allocated/associated with the resource context and then remove it from the context map. - // We no longer need to keep this context around because the resource operation has been ended. - if (SUCCEEDED(hr)) - { - pContextMap->Remove(wszResourceContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(wszResourceContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/WpdObjectResources.h b/wpd/WpdServiceSampleDriver/WpdObjectResources.h deleted file mode 100644 index 1f8c4a0a..00000000 --- a/wpd/WpdServiceSampleDriver/WpdObjectResources.h +++ /dev/null @@ -1,112 +0,0 @@ -#pragma once - -#define FILE_OPTIMAL_READ_BUFFER_SIZE_VALUE (2 * 1024 * 1024) -#define FILE_OPTIMAL_WRITE_BUFFER_SIZE_VALUE (2 * 1024 * 1024) - -// This class is used to store the context for a specific resource operation. -class WpdObjectResourceContext : public IUnknown -{ -public: - WpdObjectResourceContext() : - m_cRef(1), - m_Resource(WPD_RESOURCE_DEFAULT), - m_BytesTransferred(0), - m_BytesTotal(0), - m_Scope(FULL_DEVICE_ACCESS) - { - - } - - ~WpdObjectResourceContext() - { - - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -private: - DWORD m_cRef; - -// WpdObjectResourceContext specific data -public: - CAtlStringW m_strObjectID; // object identifier of the object whose resource is being transferred - PROPERTYKEY m_Resource; // the specific resource being transferred - ULONGLONG m_BytesTransferred; // number of bytes transferred from the resource to the caller - ULONGLONG m_BytesTotal; // total number of bytes of the resource data - ACCESS_SCOPE m_Scope; // client access scope -}; - -class WpdObjectResources -{ -public: - WpdObjectResources(); - virtual ~WpdObjectResources(); - - HRESULT Initialize(_In_ FakeDevice* pDevice); - - HRESULT DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedResources( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetResourceAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnOpenResource( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnReadResource( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnCloseResource( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - FakeDevice* m_pDevice; -}; diff --git a/wpd/WpdServiceSampleDriver/WpdService.cpp b/wpd/WpdServiceSampleDriver/WpdService.cpp deleted file mode 100644 index 4a255b0b..00000000 --- a/wpd/WpdServiceSampleDriver/WpdService.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include "stdafx.h" - -#include "WpdService.tmh" - -WpdService::WpdService() : m_pContactsService(NULL) -{ -} - -WpdService::~WpdService() -{ - -} - -HRESULT WpdService::Initialize(_In_ FakeDevice* pDevice) -{ - if (pDevice == NULL) - { - return E_POINTER; - } - m_pContactsService = pDevice->GetContactsService(); - m_ServiceMethods.Initialize(m_pContactsService); - m_ServiceCapabilities.Initialize(m_pContactsService); - return S_OK; -} - -HRESULT WpdService::DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszRequestFilename = NULL; - - // Get the request filename to process the service message - hr = pParams->GetStringValue(PRIVATE_SAMPLE_DRIVER_REQUEST_FILENAME, &pszRequestFilename); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to get the required requested filename"); - } - - if (hr == S_OK) - { - hr = CheckRequestFilename(pszRequestFilename); - CHECK_HR(hr, "Unknown request filename %ws received", pszRequestFilename); - } - - if (hr == S_OK) - { - if (Command.fmtid == WPD_CATEGORY_SERVICE_CAPABILITIES) - { - hr = m_ServiceCapabilities.DispatchWpdMessage(Command, pParams, pResults); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_METHODS_START_INVOKE)) - { - hr = m_ServiceMethods.OnStartInvoke(pParams, pResults); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_METHODS_END_INVOKE)) - { - hr = m_ServiceMethods.OnEndInvoke(pParams, pResults); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_METHODS_CANCEL_INVOKE)) - { - hr = m_ServiceMethods.OnCancelInvoke(pParams, pResults); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_COMMON_GET_SERVICE_OBJECT_ID)) - { - hr = OnGetServiceObjectID(pszRequestFilename, pParams, pResults); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "Unknown command %ws.%d received",CComBSTR(Command.fmtid), Command.pid); - } - } - - CoTaskMemFree(pszRequestFilename); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_COMMON_GET_SERVICE_OBJECT_ID - * command. - * - * The parameters sent to us are: - * None - * - * The driver should: - * - Return the objectID associated with the filename. - * - */ -HRESULT WpdService::OnGetServiceObjectID( - _In_ LPCWSTR pszRequestFilename, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if((pParams == NULL) || - (pResults == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // For simplicity, the request filename is the same as the service object ID - hr = pResults->SetStringValue(WPD_PROPERTY_SERVICE_OBJECT_ID, pszRequestFilename); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_COMMON_OBJECT_IDS"); - - return hr; -} - -HRESULT WpdService::CheckRequestFilename( - _In_ LPCWSTR pszRequestFilename) -{ - HRESULT hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); - CAtlStringW strRequestFilename = pszRequestFilename; - - // For simplicity, the request filename happens to be the same as the service object ID - if (strRequestFilename.CompareNoCase(m_pContactsService->GetRequestFilename()) == 0) - { - hr = S_OK; - } - else - { - CHECK_HR(hr, "Unknown request filename %ws received", pszRequestFilename); - } - - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/WpdService.h b/wpd/WpdServiceSampleDriver/WpdService.h deleted file mode 100644 index 0e28eadf..00000000 --- a/wpd/WpdServiceSampleDriver/WpdService.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -class WpdService -{ -public: - WpdService(); - virtual ~WpdService(); - - HRESULT Initialize(_In_ FakeDevice* pDevice); - - HRESULT DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - HRESULT OnGetServiceObjectID( - _In_ LPCWSTR pszRequestFilename, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT CheckRequestFilename( - _In_ LPCWSTR pszRequestFilename); - -private: - WpdServiceMethods m_ServiceMethods; - WpdServiceCapabilities m_ServiceCapabilities; - FakeContactsService* m_pContactsService; -}; - diff --git a/wpd/WpdServiceSampleDriver/WpdServiceCapabilities.cpp b/wpd/WpdServiceSampleDriver/WpdServiceCapabilities.cpp deleted file mode 100644 index 7f67e199..00000000 --- a/wpd/WpdServiceSampleDriver/WpdServiceCapabilities.cpp +++ /dev/null @@ -1,832 +0,0 @@ -#include "stdafx.h" - -#include "WpdServiceCapabilities.tmh" - -WpdServiceCapabilities::WpdServiceCapabilities() : m_pContactsService(NULL) -{ - -} - -WpdServiceCapabilities::~WpdServiceCapabilities() -{ - -} - -HRESULT WpdServiceCapabilities::Initialize(_In_ FakeContactsService* pContactsService) -{ - if (pContactsService == NULL) - { - return E_POINTER; - } - m_pContactsService = pContactsService; - return S_OK; -} - -HRESULT WpdServiceCapabilities::DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - if (Command.fmtid != WPD_CATEGORY_SERVICE_CAPABILITIES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - return hr; - } - - if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_COMMANDS)) - { - hr = OnGetSupportedCommands(pParams, pResults); - CHECK_HR(hr, "Failed to get supported commands"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_CAPABILITIES_GET_COMMAND_OPTIONS)) - { - hr = OnGetCommandOptions(pParams, pResults); - CHECK_HR(hr, "Failed to get command options"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_METHODS)) - { - hr = OnGetSupportedMethods(pParams, pResults); - CHECK_HR(hr, "Failed to get supported methods"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_METHODS_BY_FORMAT)) - { - hr = OnGetSupportedMethodsByFormat(pParams, pResults); - CHECK_HR(hr, "Failed to get supported methods by format"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_CAPABILITIES_GET_METHOD_ATTRIBUTES)) - { - hr = OnGetMethodAttributes(pParams, pResults); - CHECK_HR(hr, "Failed to get method attributes"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_CAPABILITIES_GET_METHOD_PARAMETER_ATTRIBUTES)) - { - hr = OnGetMethodParameterAttributes(pParams, pResults); - CHECK_HR(hr, "Failed to get method parameter attributes"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_FORMATS)) - { - hr = OnGetSupportedFormats(pParams, pResults); - CHECK_HR(hr, "Failed to get supported formats"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_CAPABILITIES_GET_FORMAT_ATTRIBUTES)) - { - hr = OnGetFormatAttributes(pParams, pResults); - CHECK_HR(hr, "Failed to get format attributes"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES)) - { - hr = OnGetSupportedFormatProperties(pParams, pResults); - CHECK_HR(hr, "Failed to get supported format properties"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_CAPABILITIES_GET_FORMAT_PROPERTY_ATTRIBUTES)) - { - hr = OnGetFormatPropertyAttributes(pParams, pResults); - CHECK_HR(hr, "Failed to get format property attributes"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_EVENTS)) - { - hr = OnGetSupportedEvents(pParams, pResults); - CHECK_HR(hr, "Failed to get supported events"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_CAPABILITIES_GET_EVENT_ATTRIBUTES)) - { - hr = OnGetEventAttributes(pParams, pResults); - CHECK_HR(hr, "Failed to get event attributes"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_CAPABILITIES_GET_EVENT_PARAMETER_ATTRIBUTES)) - { - hr = OnGetEventParameterAttributes(pParams, pResults); - CHECK_HR(hr, "Failed to get event parameter attributes"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_SERVICE_CAPABILITIES_GET_INHERITED_SERVICES)) - { - hr = OnGetInheritedServices(pParams, pResults); - CHECK_HR(hr, "Failed to get inherited services"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - - return hr; -} - - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_COMMANDS - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return all commands supported by this service as an - * IPortableDeviceKeyCollection in WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_COMMANDS. - * This includes custom commands, if any. - */ -HRESULT WpdServiceCapabilities::OnGetSupportedCommands( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - UNREFERENCED_PARAMETER(pParams); - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pCommands; - - // CoCreate a collection to store the supported commands. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pCommands); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // Add the supported commands to the collection. - if (hr == S_OK) - { - hr = m_pContactsService->GetSupportedCommands(pCommands); - CHECK_HR(hr, "Failed to get the supported commands"); - } - - // Set the WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_COMMANDS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_COMMANDS, pCommands); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_COMMANDS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_CAPABILITIES_GET_COMMAND_OPTIONS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_SERVICE_CAPABILITIES_COMMAND: a collection of property keys containing a single value, - * which identifies the specific command options are requested to return. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_SERVICE_CAPABILITIES_COMMAND_OPTIONS, containing - * the relevant options. If no options are available for this command, the driver should - * return an IPortableDeviceValues with no elements in it. - */ -HRESULT WpdServiceCapabilities::OnGetCommandOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - PROPERTYKEY Command = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pOptions; - - // Get the command whose options have been requested - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_SERVICE_CAPABILITIES_COMMAND, &Command); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_SERVICE_CAPABILITIES_COMMAND"); - } - - // CoCreate a collection to store the command options. - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pOptions); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Add command options to the collection - if (hr == S_OK) - { - hr = m_pContactsService->GetCommandOptions(Command, pOptions); - CHECK_HR(hr, "Failed to get the command options"); - } - - // Set the WPD_PROPERTY_SERVICE_CAPABILITIES_COMMAND_OPTIONS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_SERVICE_CAPABILITIES_COMMAND_OPTIONS, pOptions); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_CAPABILITIES_COMMAND_OPTIONS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_METHODS command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return all methods supported by this service as an - * IPortableDevicePropVariantCollection in WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_METHODS. - * If no methods are available for this service, the driver should return an IPortableDevicePropVariantCollection - * with no elements in it. - */ -HRESULT WpdServiceCapabilities::OnGetSupportedMethods( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - UNREFERENCED_PARAMETER(pParams); - - CComPtr<IPortableDevicePropVariantCollection> pMethods; - - // CoCreate a collection to store the supported methods. - HRESULT hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pMethods); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - - if (hr == S_OK) - { - hr = m_pContactsService->GetSupportedMethods(pMethods); - CHECK_HR(hr, "Failed to get the supported methods"); - } - - // Set the WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_METHODS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_METHODS, pMethods); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_METHODS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_METHODS_BY_FORMAT command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT: Identifies the format whose methods are being requested - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection in WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_METHODS, - * containing the supported methods that apply to this format. If no methods are available for this format, - * the driver should return an IPortableDevicePropVariantCollection with no elements in it. - */ -HRESULT WpdServiceCapabilities::OnGetSupportedMethodsByFormat( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID Format = GUID_NULL; - - CComPtr<IPortableDevicePropVariantCollection> pMethods; - - // Get the format parameter - hr = pParams->GetGuidValue(WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT, &Format); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT"); - - if (hr == S_OK) - { - // CoCreate a collection to store the supported methods. - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pMethods); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - if (hr == S_OK) - { - hr = m_pContactsService->GetSupportedMethodsByFormat(Format, pMethods); - CHECK_HR(hr, "Failed to get the supported methods by format"); - } - - // Set the WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_METHODS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_METHODS, pMethods); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_METHODS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_CAPABILITIES_GET_METHOD_ATTRIBUTES command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_SERVICE_CAPABILITIES_METHOD: Identifies the method whose attributes are being requested - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_SERVICE_CAPABILITIES_METHOD_ATTRIBUTES, containing - * the method attributes. If no attributes are available for this method, the driver should - * return an IPortableDeviceValues with no elements in it. - */ -HRESULT WpdServiceCapabilities::OnGetMethodAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID Method = GUID_NULL; - - CComPtr<IPortableDeviceValues> pAttributes; - - // Get the method - hr = pParams->GetGuidValue(WPD_PROPERTY_SERVICE_CAPABILITIES_METHOD, &Method); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_CAPABILITIES_METHOD"); - - if (hr == S_OK) - { - // CoCreate a collection to store the method attributes. - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = m_pContactsService->GetMethodAttributes(Method, pAttributes); - CHECK_HR(hr, "Failed to add method attributes"); - } - - // Set the WPD_PROPERTY_SERVICE_CAPABILITIES_METHOD_ATTRIBUTES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_SERVICE_CAPABILITIES_METHOD_ATTRIBUTES, pAttributes); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_METHODS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_CAPABILITIES_GET_METHOD_PARAMETER_ATTRIBUTES command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_SERVICE_CAPABILITIES_PARAMETER: Identifies the parameter whose attributes are being requested - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_SERVICE_CAPABILITIES_METHOD_PARAMETER_ATTRIBUTES, containing - * the parameter attributes. If no attributes are available for this parameter, the driver should - * return an IPortableDeviceValues with no elements in it. - */ -HRESULT WpdServiceCapabilities::OnGetMethodParameterAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - PROPERTYKEY Parameter = WPD_PROPERTY_NULL; - - CComPtr<IPortableDeviceValues> pAttributes; - - // Get the method - hr = pParams->GetKeyValue(WPD_PROPERTY_SERVICE_CAPABILITIES_PARAMETER, &Parameter); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_CAPABILITIES_PARAMETER"); - - if (hr == S_OK) - { - // CoCreate a collection to store the parameter attributes. - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = m_pContactsService->GetMethodParameterAttributes(Parameter, pAttributes); - CHECK_HR(hr, "Failed to get the method parameter attributes"); - } - - // Set the WPD_PROPERTY_SERVICE_CAPABILITIES_PARAMETER_ATTRIBUTES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_SERVICE_CAPABILITIES_PARAMETER_ATTRIBUTES, pAttributes); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_CAPABILITIES_PARAMETER_ATTRIBUTES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_FORMATS command. - * - * The parameters sent to us are: - * - None - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection in WPD_PROPERTY_SERVICE_CAPABILITIES_FORMATS, containing - * the supported formats for the service. If no formats are supported by this service, the driver should - * return an IPortableDevicePropVariantCollection with no elements in it. - */ -HRESULT WpdServiceCapabilities::OnGetSupportedFormats( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - UNREFERENCED_PARAMETER(pParams); - - CComPtr<IPortableDevicePropVariantCollection> pFormats; - - // CoCreate a collection to store the formats. - HRESULT hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFormats); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - - if (hr == S_OK) - { - hr = m_pContactsService->GetSupportedFormats(pFormats); - CHECK_HR(hr, "Failed to get the supported formats"); - } - - // Set the WPD_PROPERTY_SERVICE_CAPABILITIES_FORMATS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_SERVICE_CAPABILITIES_FORMATS, pFormats); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_CAPABILITIES_FORMATS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_CAPABILITIES_GET_FORMAT_ATTRIBUTES command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT: Identifies the format whose attributes are being requested - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT_ATTRIBUTES, containing - * the attributes for the format. If no attributes are supported by the format, the driver should - * return an IPortableDeviceValues with no elements in it. - */ -HRESULT WpdServiceCapabilities::OnGetFormatAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID Format = GUID_NULL; - - CComPtr<IPortableDeviceValues> pAttributes; - - // Get the format - hr = pParams->GetGuidValue(WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT, &Format); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT"); - - if (hr == S_OK) - { - // CoCreate a collection to store the attributes. - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = m_pContactsService->GetFormatAttributes(Format, pAttributes); - CHECK_HR(hr, "Failed to add format attributes"); - } - - // Set the WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT_ATTRIBUTES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT_ATTRIBUTES, pAttributes); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT_ATTRIBUTES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES command. - * This list is the super-set of all properties that will be supported by an object of the given format. - * Individual objects can be queried for their properties using WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED. - * Note that this method is generally much quicker than calling WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED, - * since the driver does not have to perform a dynamic lookup based on a specific object. - * - * The parameters sent to us are: - * - WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT: Identifies the format whose attributes are being requested - * - * The driver should: - * - Return an IPortableDeviceKeyCollection in WPD_PROPERTY_SERVICE_CAPABILITIES_PROPERTY_KEYS, containing - * the supported properties for the format. If no properties are supported by the format, the driver should - * return an IPortableDeviceKeyCollection with no elements in it. - */ -HRESULT WpdServiceCapabilities::OnGetSupportedFormatProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID Format = GUID_NULL; - - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // Get the format - hr = pParams->GetGuidValue(WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT, &Format); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT"); - - if (hr == S_OK) - { - // CoCreate a collection to store the attributes. - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - if (hr == S_OK) - { - hr = m_pContactsService->GetSupportedFormatProperties(Format, pKeys); - CHECK_HR(hr, "Failed to add the supported format properties"); - } - - // Set the WPD_PROPERTY_SERVICE_CAPABILITIES_PROPERTY_KEYS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_SERVICE_CAPABILITIES_PROPERTY_KEYS, pKeys); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_CAPABILITIES_PROPERTY_KEYS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_CAPABILITIES_GET_FORMAT_PROPERTY_ATTRIBUTES command. - * Often, a driver treats objects of a given format the same. Many properties therefore will have attributes - * that are identical across all objects of that format. These can be returned here. There are some attributes - * which may be differ per object instance, which are not returned here. See WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES. - * - * The parameters sent to us are: - * - WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT: Identifies the format whose property attributes are being requested - * - WPD_PROPERTY_SERVICE_CAPABILITIES_PROPERTY_KEYS: An IPortableDeviceKeyCollection containing a single value, - * which is the key identifying the specific property attributes the driver is requested to return. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_SERVICE_CAPABILITIES_PROPERTY_ATTRIBUTES, containing - * the attributes for the property. If no attributes are supported by the property, the driver should - * return an IPortableDeviceValues with no elements in it. - */ -HRESULT WpdServiceCapabilities::OnGetFormatPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID Format = GUID_NULL; - PROPERTYKEY Property = WPD_PROPERTY_NULL; - - CComPtr<IPortableDeviceValues> pAttributes; - - // Get the format - hr = pParams->GetGuidValue(WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT, &Format); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT"); - - if (hr == S_OK) - { - // Get the property - hr = pParams->GetKeyValue(WPD_PROPERTY_SERVICE_CAPABILITIES_PROPERTY_KEYS, &Property); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_CAPABILITIES_FORMAT"); - } - - if (hr == S_OK) - { - // CoCreate a collection to store the attributes. - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = m_pContactsService->GetPropertyAttributes(Format, Property, pAttributes); - CHECK_HR(hr, "Failed to get the supported property attributes"); - } - - // Set the WPD_PROPERTY_SERVICE_CAPABILITIES_PROPERTY_ATTRIBUTES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_SERVICE_CAPABILITIES_PROPERTY_ATTRIBUTES, pAttributes); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_CAPABILITIES_PROPERTY_ATTRIBUTES"); - } - - return hr; - -} - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_EVENTS command. - * - * The parameters sent to us are: - * - None - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection in WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_EVENTS, containing - * the events for the service. If no events are supported by the service, the driver should - * return an IPortableDevicePropVariantCollection with no elements in it. - */ -HRESULT WpdServiceCapabilities::OnGetSupportedEvents( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - UNREFERENCED_PARAMETER(pParams); - - CComPtr<IPortableDevicePropVariantCollection> pEvents; - - // CoCreate a collection to store the supported events. - HRESULT hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pEvents); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - - // Add the supported events to the collection. - if (hr == S_OK) - { - hr = m_pContactsService->GetSupportedEvents(pEvents); - CHECK_HR(hr, "Failed to get the supported events"); - } - - // Set the WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_EVENTS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_EVENTS, pEvents); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_EVENTS"); - } - - return hr; - -} - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_CAPABILITIES_GET_EVENT_ATTRIBUTES command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_SERVICE_CAPABILITIES_EVENT: Indicates the event the caller is interested in - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_SERVICE_CAPABILITIES_EVENT_ATTRIBUTES, containing - * the event attributes. If there are no attributes for that event, the driver should - * return an IPortableDeviceValues with no elements in it. - */ -HRESULT WpdServiceCapabilities::OnGetEventAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID Event = GUID_NULL; - - CComPtr<IPortableDeviceValues> pAttributes; - - // Get the format - hr = pParams->GetGuidValue(WPD_PROPERTY_SERVICE_CAPABILITIES_EVENT, &Event); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_CAPABILITIES_EVENT"); - - if (hr == S_OK) - { - // CoCreate a collection to store the attributes. - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = m_pContactsService->GetEventAttributes(Event, pAttributes); - CHECK_HR(hr, "Failed to add event attributes"); - } - - // Set the WPD_PROPERTY_SERVICE_CAPABILITIES_SUPPORTED_EVENTS value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_SERVICE_CAPABILITIES_EVENT_ATTRIBUTES, pAttributes); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_CAPABILITIES_EVENT_ATTRIBUTES"); - } - - return hr; -} - - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_CAPABILITIES_GET_EVENT_PARAMETER_ATTRIBUTES command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_SERVICE_CAPABILITIES_PARAMETER: Identifies the parameter whose attributes are being requested - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_SERVICE_CAPABILITIES_EVENT_PARAMETER_ATTRIBUTES, containing - * the parameter attributes. If no attributes are available for this parameter, the driver should - * return an IPortableDeviceValues with no elements in it. - */ -HRESULT WpdServiceCapabilities::OnGetEventParameterAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - PROPERTYKEY Parameter = WPD_PROPERTY_NULL; - - CComPtr<IPortableDeviceValues> pAttributes; - - // Get the method - hr = pParams->GetKeyValue(WPD_PROPERTY_SERVICE_CAPABILITIES_PARAMETER, &Parameter); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_CAPABILITIES_PARAMETER"); - - if (hr == S_OK) - { - // CoCreate a collection to store the parameter attributes. - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = m_pContactsService->GetEventParameterAttributes(Parameter, pAttributes); - CHECK_HR(hr, "Failed to get the event parameter attributes"); - } - - // Set the WPD_PROPERTY_SERVICE_CAPABILITIES_PARAMETER_ATTRIBUTES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_SERVICE_CAPABILITIES_PARAMETER_ATTRIBUTES, pAttributes); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_CAPABILITIES_PARAMETER_ATTRIBUTES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_CAPABILITIES_GET_INHERITED_SERVICES command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_SERVICE_CAPABILITIES_INHERITANCE_TYPE: Indicates the inheritance type the caller is interested in - * Possible values are from the WPD_SERVICE_INHERITANCE_TYPES enumeration - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection in WPD_PROPERTY_SERVICE_CAPABILITIES_INHERITED_SERVICES, containing - * the inherited services. For WPD_SERVICE_INHERITANCE_IMPLEMENTATION, this will be an - * IPortableDevicePropVariantCollection (of type VT_CLSID) containing the inherited service type GUIDs. - * If there are no inherited services, the driver should return an IPortableDevicePropVariantCollection with no elements in it. - */ -HRESULT WpdServiceCapabilities::OnGetInheritedServices( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - DWORD dwInheritanceType = 0; - - CComPtr<IPortableDevicePropVariantCollection> pServices; - - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_SERVICE_CAPABILITIES_INHERITANCE_TYPE, &dwInheritanceType); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_CAPABILITIES_INHERITANCE_TYPE"); - - if (hr == S_OK) - { - // CoCreate a collection to store the attributes. - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pServices); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - if (hr == S_OK) - { - hr = m_pContactsService->GetInheritedServices(dwInheritanceType, pServices); - CHECK_HR(hr, "Failed to add inherited services"); - } - - // Set the WPD_PROPERTY_SERVICE_CAPABILITIES_INHERITED_SERVICES value in the results. - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_SERVICE_CAPABILITIES_INHERITED_SERVICES, pServices); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_CAPABILITIES_EVENT_ATTRIBUTES"); - } - - return hr; -} - diff --git a/wpd/WpdServiceSampleDriver/WpdServiceCapabilities.h b/wpd/WpdServiceSampleDriver/WpdServiceCapabilities.h deleted file mode 100644 index cffa2361..00000000 --- a/wpd/WpdServiceSampleDriver/WpdServiceCapabilities.h +++ /dev/null @@ -1,76 +0,0 @@ -#pragma once - -class WpdServiceCapabilities -{ -public: - WpdServiceCapabilities(); - virtual ~WpdServiceCapabilities(); - - HRESULT Initialize(_In_ FakeContactsService* pContactsService); - - HRESULT DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - HRESULT OnGetSupportedCommands( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetCommandOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedMethods( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedMethodsByFormat( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetMethodAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetMethodParameterAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedFormats( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFormatAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedFormatProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFormatPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedEvents( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetEventAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetEventParameterAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetInheritedServices( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - FakeContactsService* m_pContactsService; -}; - diff --git a/wpd/WpdServiceSampleDriver/WpdServiceMethods.cpp b/wpd/WpdServiceSampleDriver/WpdServiceMethods.cpp deleted file mode 100644 index 42b362f2..00000000 --- a/wpd/WpdServiceSampleDriver/WpdServiceMethods.cpp +++ /dev/null @@ -1,526 +0,0 @@ -#include "stdafx.h" - -#include "WpdServiceMethods.tmh" - -CMethodTask::CMethodTask(_In_ ServiceMethodContext* pContext) : - m_hThread(NULL), - m_pContext(pContext) -{ - m_pContext->AddRef(); -} - -CMethodTask::~CMethodTask() -{ - if (m_hThread != NULL) - { - CloseHandle(m_hThread); - m_hThread = NULL; - } - SAFE_RELEASE(m_pContext); -} - -HRESULT CMethodTask::Run() -{ - HRESULT hr = S_OK; - - // Create the thread - m_hThread = CreateThread(NULL, 0, ThreadProc, m_pContext, 0, NULL); - if (m_hThread == NULL) - { - DWORD dwError = GetLastError(); - hr = HRESULT_FROM_WIN32(dwError); - } - - return hr; -} - -ServiceMethodContext::ServiceMethodContext() : - m_cRef(1), - m_pServiceMethods(NULL) -{ - m_pTask = NULL; -} - -ServiceMethodContext::~ServiceMethodContext() -{ - if (m_pTask) - { - delete m_pTask; - m_pTask = NULL; - } -} - -HRESULT ServiceMethodContext::Initialize( - _In_ WpdServiceMethods* pServiceMethods, - _In_ IPortableDeviceValues* pStartParams, - _In_ LPCWSTR pwszContext) -{ - HRESULT hr = S_OK; - - m_pTask = new CMethodTask(this); - if (m_pTask != NULL) - { - m_pServiceMethods = pServiceMethods; - m_pStartParameters = pStartParams; - m_strContext = pwszContext; - - hr = m_pTask->Run(); - CHECK_HR(hr, "Failed to run method task"); - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate method task"); - } - return hr; -} - -VOID ServiceMethodContext::InvokeMethod() -{ - if (m_pServiceMethods != NULL && - m_pStartParameters != NULL && - m_strContext.GetLength() > 0) - { - m_hrStatus = m_pServiceMethods->DispatchMethod(m_strContext, m_pStartParameters, &m_pResults); - } - CHECK_HR(m_hrStatus, "Failed to Dispatch method"); -} - - -WpdServiceMethods::WpdServiceMethods() - : m_pContactsService(NULL) -{ - -} - -WpdServiceMethods::~WpdServiceMethods() -{ - -} - -HRESULT WpdServiceMethods::Initialize( - _In_ FakeContactsService* pContactsService) -{ - if (pContactsService == NULL) - { - return E_POINTER; - } - m_pContactsService = pContactsService; - return S_OK; -} - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_METHODS_START_INVOKE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_SERVICE_METHOD: Indicates the method to invoke. - * This must be from the list returned by WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_METHODS - * or WPD_COMMAND_SERVICE_CAPABILITIES_GET_SUPPORTED_ METHODS_BY_FORMAT. - * - * - WPD_PROPERTY_SERVICE_METHOD_PARAMETER_VALUES: IPortableDeviceValues containing the method parameters. - * Each parameter must be set in the ordering specified by WPD_PARAMETER_ATTRIBUTE_ORDER, with all parameters present. - * This must be an empty set if the method does not have any parameters. - * - * The driver should: - * - Return immediately with the method invocation context in WPD_PROPERTY_SERVICE_METHOD_CONTEXT. - * - When this method invocation completes, the driver must send a WPD_EVENT_SERVICE_METHOD_COMPLETE event - * with the WPD_EVENT_PARAMETER_SERVICE_METHOD_CONTEXT parameter set as this method context. - * - Lastly, the driver should wait for the WPD_COMMAND_SERVICE_METHODS_END_INVOKE command - * before cleaning up associated resources with this context - */ -HRESULT WpdServiceMethods::OnStartInvoke( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pwszContext = NULL; - - // Create a new method context - hr = StartMethod(pParams, &pwszContext); - CHECK_HR(hr, "Failed to create a new method context"); - - // Return the method context in the results - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_SERVICE_METHOD_CONTEXT, pwszContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_METHOD_CONTEXT"); - } - - CoTaskMemFree(pwszContext); - return hr; -} - - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_METHODS_END_INVOKE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_SERVICE_METHOD_CONTEXT: Context of the method invocation being ended. - * This must be returned from WPD_COMMAND_SERVICE_METHODS_START_INVOKE - * - * The driver should: - * - Return the method results in WPD_PROPERTY_SERVICE_METHOD_RESULT_VALUES - * - Return the overall method status code in WPD_PROPERTY_SERVICE_METHOD_HRESULT - * - Destroy any resources associated with this context. - */ -HRESULT WpdServiceMethods::OnEndInvoke( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - HRESULT hrStatus = S_OK; - LPWSTR pwszContext = NULL; - ContextMap* pContextMap = NULL; - - CComPtr<IPortableDeviceValues> pMethodResults; - - hr = pParams->GetStringValue(WPD_PROPERTY_SERVICE_METHOD_CONTEXT, &pwszContext); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_METHOD_CONTEXT from IPortableDeviceValues"); - - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - hr = EndMethod(pContextMap, pwszContext, &pMethodResults, &hrStatus); - CHECK_HR(hr, "Failed to destroy method context %ws", pwszContext); - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetErrorValue(WPD_PROPERTY_SERVICE_METHOD_HRESULT, hrStatus); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_METHOD_HRESULT for method context %ws", pwszContext); - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_SERVICE_METHOD_RESULT_VALUES, pMethodResults); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_SERVICE_METHOD_RESULT_VALUES for method context %ws", pwszContext); - } - - CoTaskMemFree(pwszContext); - SAFE_RELEASE(pContextMap); - return hr; -} - - -/** - * This method is called when we receive a WPD_COMMAND_SERVICE_METHODS_CANCEL_INVOKE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_SERVICE_METHOD_CONTEXT: Context of the method invocation being cancelled. - * This must be returned from WPD_COMMAND_SERVICE_METHODS_START_INVOKE - * - * The driver should: - * - Destroy any resources associated with this context. - * - */ -HRESULT WpdServiceMethods::OnCancelInvoke( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pwszContext = NULL; - ContextMap* pContextMap = NULL; - UNREFERENCED_PARAMETER(pResults); - - hr = pParams->GetStringValue(WPD_PROPERTY_SERVICE_METHOD_CONTEXT, &pwszContext); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_METHOD_CONTEXT from IPortableDeviceValues"); - - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - hr = CancelMethod(pContextMap, pwszContext); - CHECK_HR(hr, "Failed to cancel the method"); - } - - CoTaskMemFree(pwszContext); - SAFE_RELEASE(pContextMap); - return hr; -} - -HRESULT WpdServiceMethods::StartMethod( - _In_ IPortableDeviceValues* pParams, - _Outptr_result_nullonfailure_ LPWSTR* ppwszMethodContext) -{ - HRESULT hr = S_OK; - ContextMap* pContextMap = NULL; - ServiceMethodContext* pContext = NULL; - GUID Method = GUID_NULL; - - CAtlStringW strKey; - CComPtr<IPortableDeviceValues> pMethodParams; - - if((pParams == NULL) || - (ppwszMethodContext == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *ppwszMethodContext = NULL; - - // Check if the method is supported - hr = pParams->GetGuidValue(WPD_PROPERTY_SERVICE_METHOD, &Method); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_METHOD"); - - if (SUCCEEDED(hr) && !m_pContactsService->IsMethodSupported(Method)) - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - CHECK_HR(hr, "Unknown method %ws received",CComBSTR(Method)); - } - - if (SUCCEEDED(hr)) - { - // Get the context map which the driver stored in pParams for convenience - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - pContext = new ServiceMethodContext(); - if(pContext == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new method context"); - } - } - - if (SUCCEEDED(hr)) - { - hr = pContextMap->Add(pContext, strKey); - CHECK_HR(hr, "Failed to insert method context into our context Map"); - } - - if (SUCCEEDED(hr)) - { - hr = pContext->Initialize(this, pParams, strKey); - CHECK_HR(hr, "Failed to initialize the method context"); - } - - if (SUCCEEDED(hr)) - { - *ppwszMethodContext = AtlAllocTaskWideString(strKey); - if (*ppwszMethodContext == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate method context string"); - } - } - - SAFE_RELEASE(pContextMap); - SAFE_RELEASE(pContext); - - return hr; -} - -HRESULT WpdServiceMethods::EndMethod( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pwszMethodContext, - _COM_Outptr_result_maybenull_ IPortableDeviceValues** ppResults, - _Out_ HRESULT* phrStatus) -{ - HRESULT hr = S_OK; - ServiceMethodContext* pContext = NULL; - CAtlStringW strKey = pwszMethodContext; - - *ppResults = NULL; - *phrStatus = S_OK; - pContext = (ServiceMethodContext*) pContextMap->GetContext(strKey); - - if (pContext != NULL) - { - if (pContext->m_pResults) - { - hr = pContext->m_pResults->QueryInterface(IID_IPortableDeviceValues, (void**)ppResults); - CHECK_HR(hr, "Failed to QueryInterface IPortableDeviceValues for results"); - } - - if (SUCCEEDED(hr)) - { - *phrStatus = pContext->m_hrStatus; - } - pContextMap->Remove(strKey); - } - else - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); - CHECK_HR(hr, "Failed to get the context for %ws", pwszMethodContext); - } - - if (FAILED(hr)) - { - *phrStatus = hr; - } - - SAFE_RELEASE(pContext); - return hr; -} - -HRESULT WpdServiceMethods::CancelMethod( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pwszMethodContext) -{ - HRESULT hr = S_OK; - ServiceMethodContext* pContext = NULL; - CAtlStringW strKey = pwszMethodContext; - - pContext = (ServiceMethodContext*) pContextMap->GetContext(strKey); - - if (pContext != NULL) - { - // - // This is where we will cancel the method invocation associated - // with this context - // - - // .... - - // When done ... clean up associated resources - pContextMap->Remove(strKey); - } - else - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); - CHECK_HR(hr, "Failed to get the context for %ws", pwszMethodContext); - } - - SAFE_RELEASE(pContext); - return hr; -} - -HRESULT WpdServiceMethods::DispatchMethod( - _In_ LPCWSTR pwszContext, - _In_ IPortableDeviceValues* pStartParams, - _COM_Outptr_ IPortableDeviceValues** ppResults) -{ - HRESULT hr = S_OK; - HRESULT hrStatus = S_OK; - GUID Method = GUID_NULL; - CComPtr<IPortableDeviceValues> pMethodParams; - CComPtr<IPortableDeviceValues> pMethodResults; - - *ppResults = NULL; - - // Get the method GUID - hr = pStartParams->GetGuidValue(WPD_PROPERTY_SERVICE_METHOD, &Method); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_SERVICE_METHOD"); - - // Get the method parameters. These can be optional if the methods don't require parameters - if (SUCCEEDED(hr)) - { - HRESULT hrTemp = pStartParams->GetIPortableDeviceValuesValue(WPD_PROPERTY_SERVICE_METHOD_PARAMETER_VALUES, &pMethodParams); - CHECK_HR(hrTemp, "Failed to get WPD_PROPERTY_SERVICE_METHOD_PARAMETER_VALUES (ok if method does not require parameters)"); - } - - // Prepare the results collection - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pMethodResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (SUCCEEDED(hr)) - { - // Invoke the method - if (IsEqualGUID(METHOD_FullEnumSyncSvc_BeginSync, Method)) - { - hrStatus = m_pContactsService->OnBeginSync(pMethodParams, *ppResults); - CHECK_HR(hrStatus, "BeginSync method failed"); - } - else if (IsEqualGUID(METHOD_FullEnumSyncSvc_EndSync, Method)) - { - hrStatus = m_pContactsService->OnEndSync(pMethodParams, *ppResults); - CHECK_HR(hrStatus, "EndSync method failed"); - } - else if (IsEqualGUID(MyCustomMethod, Method)) - { - CComPtr<IPortableDeviceValues> pCustomEventParams; - - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pCustomEventParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - - if (SUCCEEDED(hr)) - { - hrStatus = m_pContactsService->OnMyCustomMethod(pMethodParams, pMethodResults, pCustomEventParams); - CHECK_HR(hrStatus, "MyCustomMethod method failed"); - } - - if (SUCCEEDED(hr)) - { - // In addition to a method complete event, we can also send a custom event, - // for example, to indicate progress of the method - hr = PostWpdEvent(pStartParams, pCustomEventParams); - CHECK_HR(hr, "Failed to post custom event"); - } - } - else - { - hrStatus = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - CHECK_HR(hr, "Unknown method %ws received",CComBSTR(Method)); - } - } - - // We always want to post a method completion event - // Even if the method has failed - { - CComPtr<IPortableDeviceValues> pEventParams; - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pEventParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - - if (SUCCEEDED(hr)) - { - hr = pEventParams->SetGuidValue(WPD_EVENT_PARAMETER_EVENT_ID, WPD_EVENT_SERVICE_METHOD_COMPLETE); - CHECK_HR(hr, "Failed to set the event id to WPD_EVENT_SERVICE_METHOD_COMPLETE"); - } - - if (SUCCEEDED(hr)) - { - hr = pEventParams->SetStringValue(WPD_EVENT_PARAMETER_SERVICE_METHOD_CONTEXT, pwszContext); - CHECK_HR(hr, "Failed to set the method context for WPD_EVENT_SERVICE_METHOD_COMPLETE"); - } - - if (SUCCEEDED(hr)) - { - hr = PostWpdEvent(pStartParams, pEventParams); - CHECK_HR(hr, "Failed to post WPD_EVENT_SERVICE_METHOD_COMPLETE"); - } - } - - if (SUCCEEDED(hr)) - { - hr = hrStatus; - } - - if (SUCCEEDED(hr)) - { - *ppResults = pMethodResults.Detach(); - } - - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/WpdServiceMethods.h b/wpd/WpdServiceSampleDriver/WpdServiceMethods.h deleted file mode 100644 index 0e607331..00000000 --- a/wpd/WpdServiceSampleDriver/WpdServiceMethods.h +++ /dev/null @@ -1,151 +0,0 @@ -#pragma once - -class CMethodTask; - -// This class is used to store the context for a specific method invocation -class ServiceMethodContext : public IUnknown -{ -public: - ServiceMethodContext(); - ~ServiceMethodContext(); - - HRESULT Initialize( - _In_ WpdServiceMethods* pServiceMethods, - _In_ IPortableDeviceValues* pStartParams, - _In_ LPCWSTR pwszContext); - - VOID InvokeMethod(); - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -public: - HRESULT m_hrStatus; - CComPtr<IPortableDeviceValues> m_pResults; - -private: - DWORD m_cRef; - CAtlStringW m_strContext; - CMethodTask* m_pTask; - CComPtr<IPortableDeviceValues> m_pStartParameters; - WpdServiceMethods* m_pServiceMethods; -}; - - -class CMethodTask -{ -public: - CMethodTask(_In_ ServiceMethodContext* pContext); - - ~CMethodTask(); - - HRESULT Run(); - - static DWORD ThreadProc(LPVOID pData) - { - // Initialize COM - if (SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) - { - ServiceMethodContext* pContext = (ServiceMethodContext*) pData; - if (pContext != NULL) - { - pContext->AddRef(); - pContext->InvokeMethod(); - pContext->Release(); - } - - // Uninitialize COM - CoUninitialize(); - } - return 0; - } -private: - HANDLE m_hThread; - ServiceMethodContext* m_pContext; -}; - -class WpdServiceMethods -{ -public: - WpdServiceMethods(); - virtual ~WpdServiceMethods(); - - HRESULT Initialize( - _In_ FakeContactsService* pContactsService); - - // Handler for WPD_COMMAND_SERVICE_METHODS_START_INVOKE - HRESULT OnStartInvoke( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - // Handler for WPD_COMMAND_SERVICE_METHODS_END_INVOKE - HRESULT OnEndInvoke( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - // Handler for WPD_COMMAND_SERVICE_METHODS_CANCEL_INVOKE - HRESULT OnCancelInvoke( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT DispatchMethod( - _In_ LPCWSTR pwszContext, - _In_ IPortableDeviceValues* pStartParams, - _COM_Outptr_ IPortableDeviceValues** ppResults); - -private: - HRESULT StartMethod( - _In_ IPortableDeviceValues* pCommandParams, - _Outptr_result_nullonfailure_ LPWSTR* ppwszMethodContext); - - HRESULT EndMethod( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pwszMethodContext, - _COM_Outptr_result_maybenull_ IPortableDeviceValues** ppResults, - _Out_ HRESULT* phrStatus); - - HRESULT CancelMethod( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pwszMethodContext); - -private: - FakeContactsService* m_pContactsService; -}; - diff --git a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.cpp b/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.cpp deleted file mode 100644 index d2bf9d73..00000000 --- a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "stdafx.h" -#include "resource.h" -#include "WpdServiceSampleDriver.h" - -#include "WpdServiceSampleDriver.tmh" - -HINSTANCE g_hInstance = NULL; - -class CWpdServiceSampleDriverModule : public CAtlDllModuleT< CWpdServiceSampleDriverModule > -{ -public : - DECLARE_REGISTRY_APPID_RESOURCEID(IDR_WpdServiceSampleDriver, "{95B558CB-F6B1-4B37-A105-3B7B6A196FB5}") - DECLARE_LIBID(LIBID_WpdServiceSampleDriverLib) -}; - -CWpdServiceSampleDriverModule _AtlModule; - -// DLL Entry Point -extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) -{ - if(dwReason == DLL_PROCESS_ATTACH) - { - g_hInstance = hInstance; - - // Initialize tracing. - WPP_INIT_TRACING(MYDRIVER_TRACING_ID); - } - else if (dwReason == DLL_PROCESS_DETACH) - { - // Cleanup tracing. - WPP_CLEANUP(); - } - - return _AtlModule.DllMain(dwReason, lpReserved); -} - -// Used to determine whether the DLL can be unloaded by OLE -STDAPI DllCanUnloadNow(void) -{ - return _AtlModule.DllCanUnloadNow(); -} - -// Returns a class factory to create an object of the requested type -STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID* ppv) -{ - return _AtlModule.DllGetClassObject(rclsid, riid, ppv); -} - -// DllRegisterServer - Adds entries to the system registry -STDAPI DllRegisterServer(void) -{ - // registers object, typelib and all interfaces in typelib - HRESULT hr = _AtlModule.DllRegisterServer(); - return hr; -} - -// DllUnregisterServer - Removes entries from the system registry -STDAPI DllUnregisterServer(void) -{ - HRESULT hr = _AtlModule.DllUnregisterServer(); - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.def b/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.def deleted file mode 100644 index 47cf750d..00000000 --- a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.def +++ /dev/null @@ -1,9 +0,0 @@ -; WpdServiceSampleDriver.def : Declares the module parameters. - -LIBRARY "WpdServiceSampleDriver.DLL" - -EXPORTS - DllCanUnloadNow PRIVATE - DllGetClassObject PRIVATE - DllRegisterServer PRIVATE - DllUnregisterServer PRIVATE diff --git a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.idl b/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.idl deleted file mode 100644 index 75102566..00000000 --- a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.idl +++ /dev/null @@ -1,24 +0,0 @@ - -import "oaidl.idl"; -import "ocidl.idl"; - -import "wudfddi.idl"; - -[ - uuid(74FF6859-73D1-488C-B2EA-88BD6DA31A17), - version(1.0), - helpstring("Windows Portable Device Services Sample Driver Type Library") -] -library WpdServiceSampleDriverLib -{ - importlib("stdole2.tlb"); - [ - uuid(CFC0AF02-CE72-4717-83E7-D51BCFCBE87B), - helpstring("WpdServiceSampleDriver Class") - ] - coclass WpdServiceSampleDriver - { - [default] interface IDriverEntry; - }; -}; - diff --git a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.inx b/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.inx deleted file mode 100644 index 0f4365cc..00000000 --- a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.inx +++ /dev/null @@ -1,80 +0,0 @@ -; -; WpdServiceSampleDriver.inf -; - -[Version] -Signature="$Windows NT$" -Class=WPD -ClassGuid={EEC5AD98-8080-425f-922A-DABF3DE3F69A} -Provider=%Provider% -CatalogFile=WpdServiceSampleDriver.cat -DriverVer=01/24/2007,1.1.1.1 - -[Manufacturer] -%Mfg%=Standard,NT$ARCH$ - -[Standard.NT$ARCH$] -%BasicDeviceName%=Basic_Install,WUDF\WpdService - -[SourceDisksFiles] -WudfUpdate_$UMDFCOINSTALLERVERSION$.dll=1 -WpdServiceSampleDriver.dll=1 - -[SourceDisksNames] -1 = %MediaDescription% - -; =================== WPD Sample Device ================================== - -[Basic_Install] -CopyFiles=System32Copy - -[Basic_Install.hw] -AddReg=Device_AddReg - -[Basic_Install.Services] -AddService=WUDFRd,0x000001fa,WUDFRD_ServiceInstall - -[Basic_Install.CoInstallers] -AddReg=Basic_Install.CoInstallers_AddReg -CopyFiles = CoInstallers_CopyFiles - -[Basic_Install.CoInstallers_AddReg] -HKR,,CoInstallers32,0x00010000,"WudfUpdate_$UMDFCOINSTALLERVERSION$.dll" - -[Basic_Install.Wdf] -UmdfService=WpdServiceSampleDriver, WpdServiceSampleDriver_Install -UmdfServiceOrder=WpdServiceSampleDriver - -[CoInstallers_CopyFiles] -WudfUpdate_$UMDFCOINSTALLERVERSION$.dll - -[WpdServiceSampleDriver_Install] -UmdfLibraryVersion=$UMDFVERSION$ -DriverCLSID="{CFC0AF02-CE72-4717-83E7-D51BCFCBE87B}" -ServiceBinary=%12%\UMDF\WpdServiceSampleDriver.dll - -[Device_AddReg] -; Enable default AutoPlay support -HKR,,"EnableDefaultAutoPlaySupport",0x10001,1 - -[WUDFRD_ServiceInstall] -ServiceType=1 -StartType=3 -ErrorControl=1 -ServiceBinary=%12%\WUDFRd.sys - -[DestinationDirs] -System32Copy=12,UMDF ; copy to system32\drivers\umdf -CoInstallers_CopyFiles= 11 - -[System32Copy] -WpdServiceSampleDriver.dll - - -; =================== Generic ================================== - -[Strings] -Provider="TODO-Set-Provider" -Mfg="Windows Portable Devices" -MediaDescription="Windows Portable Device Services Sample Driver Installation Media" -BasicDeviceName="Windows Portable Device Services Sample Driver" diff --git a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.rc b/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.rc deleted file mode 100644 index 02cbfa08..00000000 --- a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.rc +++ /dev/null @@ -1,18 +0,0 @@ -#include "resource.h" -#include <windows.h> -#include <ntverp.h> - -#define VER_FILETYPE VFT_DLL -#define VER_FILESUBTYPE VFT2_UNKNOWN -#define VER_FILEDESCRIPTION_STR "Windows Portable Device Services Sample Driver" -#define VER_INTERNALNAME_STR "WpdServiceSampleDriver.dll" - -#include <common.ver> - -IDR_WPD_SAMPLEDRIVER_DEVICE_ICON DATA_FILE "SampleDeviceIcon.ico" -IDR_WPD_SAMPLEDRIVER_SERVICE_ICON DATA_FILE "SampleContactsServiceIcon.ico" - -1 TYPELIB "WpdServiceSampleDriver.tlb" - -IDR_WpdServiceSampleDriver REGISTRY "WpdServiceSampleDriver.rgs" - diff --git a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.rgs b/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.rgs deleted file mode 100644 index d0de4d3b..00000000 --- a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.rgs +++ /dev/null @@ -1,26 +0,0 @@ -HKCR -{ - WpdServiceSampleDriver.WpdServiceSampleDriver.1 = s 'WpdServiceSampleDriver Class' - { - CLSID = s '{CFC0AF02-CE72-4717-83E7-D51BCFCBE87B}' - } - WpdServiceSampleDriver.WpdServiceSampleDriver = s 'WpdServiceSampleDriver Class' - { - CLSID = s '{CFC0AF02-CE72-4717-83E7-D51BCFCBE87B}' - CurVer = s 'WpdServiceSampleDriver.WpdServiceSampleDriver.1' - } - NoRemove CLSID - { - ForceRemove {CFC0AF02-CE72-4717-83E7-D51BCFCBE87B} = s 'WpdServiceSampleDriver Class' - { - ProgID = s 'WpdServiceSampleDriver.WpdServiceSampleDriver.1' - VersionIndependentProgID = s 'WpdServiceSampleDriver.WpdServiceSampleDriver.1' - InprocServer32 = s '%MODULE%' - { - val ThreadingModel = s 'Free' - } - 'TypeLib' = s '{74FF6859-73D1-488C-B2EA-88BD6DA31A17}' - } - } -} - diff --git a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.sln b/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.sln deleted file mode 100644 index 2c7e40e5..00000000 --- a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.sln +++ /dev/null @@ -1,28 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0 -MinimumVisualStudioVersion = 12.0 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WpdServiceSampleDriver", "WpdServiceSampleDriver.vcxproj", "{427BB6BF-A2BA-4CC6-AE53-648B107C0E5F}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - Debug|x64 = Debug|x64 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {427BB6BF-A2BA-4CC6-AE53-648B107C0E5F}.Debug|Win32.ActiveCfg = Debug|Win32 - {427BB6BF-A2BA-4CC6-AE53-648B107C0E5F}.Debug|Win32.Build.0 = Debug|Win32 - {427BB6BF-A2BA-4CC6-AE53-648B107C0E5F}.Release|Win32.ActiveCfg = Release|Win32 - {427BB6BF-A2BA-4CC6-AE53-648B107C0E5F}.Release|Win32.Build.0 = Release|Win32 - {427BB6BF-A2BA-4CC6-AE53-648B107C0E5F}.Debug|x64.ActiveCfg = Debug|x64 - {427BB6BF-A2BA-4CC6-AE53-648B107C0E5F}.Debug|x64.Build.0 = Debug|x64 - {427BB6BF-A2BA-4CC6-AE53-648B107C0E5F}.Release|x64.ActiveCfg = Release|x64 - {427BB6BF-A2BA-4CC6-AE53-648B107C0E5F}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.vcxproj b/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.vcxproj deleted file mode 100644 index 6b16f927..00000000 --- a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.vcxproj +++ /dev/null @@ -1,460 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup Label="ProjectConfigurations"> - <ProjectConfiguration Include="Debug|Win32"> - <Configuration>Debug</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|Win32"> - <Configuration>Release</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Debug|x64"> - <Configuration>Debug</Configuration> - <Platform>x64</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|x64"> - <Configuration>Release</Configuration> - <Platform>x64</Platform> - </ProjectConfiguration> - </ItemGroup> - <PropertyGroup Label="Globals"> - <ProjectGuid>{427BB6BF-A2BA-4CC6-AE53-648B107C0E5F}</ProjectGuid> - <RootNamespace>$(MSBuildProjectName)</RootNamespace> - <UMDF_VERSION_MAJOR>1</UMDF_VERSION_MAJOR> - <KMDF_VERSION_MAJOR>1</KMDF_VERSION_MAJOR> - <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration> - <Platform Condition="'$(Platform)' == ''">Win32</Platform> - <SampleGuid>{23866B2C-44B5-4963-821D-729F96EA5AD9}</SampleGuid> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>False</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>True</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>False</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>True</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> - <PropertyGroup> - <OutDir>$(IntDir)</OutDir> - </PropertyGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ItemGroup Label="WrappedTaskItems"> - <ClCompile Include="WpdServiceSampleDriver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Driver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Device.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Queue.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdBaseDriver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectEnum.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectManagement.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectProperties.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectPropertiesBulk.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectResources.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdCapabilities.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdService.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdServiceMethods.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdServiceCapabilities.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="helpers.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="FakeContent.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="FakeContactsService.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="FakeContactsServiceContent.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="FakeStorage.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="FakeContactContent.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="FakeDeviceContent.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="FakeDevice.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <Inf Include="WpdServiceSampleDriver.inx"> - <Architecture>$(InfArch)</Architecture> - <SpecifyArchitecture>true</SpecifyArchitecture> - <CopyOutput>.\$(IntDir)\WpdServiceSampleDriver.inf</CopyOutput> - </Inf> - <OtherWpp Include="WpdServiceSampleDriver.rc; WpdServiceSampleDriver.idl"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - </OtherWpp> - </ItemGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <TargetName>WpdServiceSampleDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <TargetName>WpdServiceSampleDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <TargetName>WpdServiceSampleDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <TargetName>WpdServiceSampleDriver</TargetName> - </PropertyGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <ExceptionHandling>Sync</ExceptionHandling> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <ExceptionHandling>Sync</ExceptionHandling> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <ExceptionHandling>Sync</ExceptionHandling> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <ExceptionHandling>Sync</ExceptionHandling> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(SDK_INC_PATH);$(DDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Link> - <ModuleDefinitionFile>WpdServiceSampleDriver.def</ModuleDefinitionFile> - </Link> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Link> - <ModuleDefinitionFile>WpdServiceSampleDriver.def</ModuleDefinitionFile> - </Link> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Link> - <ModuleDefinitionFile>WpdServiceSampleDriver.def</ModuleDefinitionFile> - </Link> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Link> - <ModuleDefinitionFile>WpdServiceSampleDriver.def</ModuleDefinitionFile> - </Link> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemGroup> - <ClCompile Include="Stdafxsrc.cpp"> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Create</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <Midl Include="WpdServiceSampleDriver.idl" /> - <ResourceCompile Include="WpdServiceSampleDriver.rc" /> - </ItemGroup> - <ItemGroup> - <Inf Exclude="@(Inf)" Include="*.inf" /> - <FilesToPackage Include="$(TargetPath)" Condition="'$(ConfigurationType)'=='Driver' or '$(ConfigurationType)'=='DynamicLibrary'" /> - </ItemGroup> - <ItemGroup> - <None Exclude="@(None)" Include="*.txt;*.htm;*.html" /> - <None Exclude="@(None)" Include="*.ico;*.cur;*.bmp;*.dlg;*.rct;*.gif;*.jpg;*.jpeg;*.wav;*.jpe;*.tiff;*.tif;*.png;*.rc2" /> - <None Exclude="@(None)" Include="*.def;*.bat;*.hpj;*.asmx" /> - </ItemGroup> - <ItemGroup> - <ClInclude Exclude="@(ClInclude)" Include="*.h;*.hpp;*.hxx;*.hm;*.inl;*.xsd" /> - </ItemGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> -</Project>
\ No newline at end of file diff --git a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.vcxproj.Filters b/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.vcxproj.Filters deleted file mode 100644 index a3cf3c7c..00000000 --- a/wpd/WpdServiceSampleDriver/WpdServiceSampleDriver.vcxproj.Filters +++ /dev/null @@ -1,113 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup> - <Filter Include="Source Files"> - <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;*</Extensions> - <UniqueIdentifier>{59DE54EC-F93C-4B41-9870-C769D596B90B}</UniqueIdentifier> - </Filter> - <Filter Include="Header Files"> - <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> - <UniqueIdentifier>{CE787A41-44CA-4CF5-83F3-A902A8CEC775}</UniqueIdentifier> - </Filter> - <Filter Include="Resource Files"> - <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml</Extensions> - <UniqueIdentifier>{7BDBC101-4E7B-45A0-A875-8975F943CBCE}</UniqueIdentifier> - </Filter> - <Filter Include="Driver Files"> - <Extensions>inf;inv;inx;mof;mc;</Extensions> - <UniqueIdentifier>{AE71DC3E-F17F-4900-A386-6E0295E28E9D}</UniqueIdentifier> - </Filter> - </ItemGroup> - <ItemGroup> - <ClCompile Include="Device.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Driver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="FakeContactContent.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="FakeContactsService.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="FakeContactsServiceContent.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="FakeContent.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="FakeDevice.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="FakeDeviceContent.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="FakeStorage.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="helpers.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Queue.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Stdafxsrc.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdBaseDriver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdCapabilities.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectEnum.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectManagement.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectProperties.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectPropertiesBulk.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectResources.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdService.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdServiceCapabilities.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdServiceMethods.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdServiceSampleDriver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <Midl Include="WpdServiceSampleDriver.idl"> - <Filter>Source Files</Filter> - </Midl> - <None Include="WpdServiceSampleDriver.def"> - <Filter>Source Files</Filter> - </None> - </ItemGroup> - <ItemGroup> - <Inf Include="WpdServiceSampleDriver.inx"> - <Filter>Driver Files</Filter> - </Inf> - </ItemGroup> - <ItemGroup> - <ResourceCompile Include="WpdServiceSampleDriver.rc"> - <Filter>Resource Files</Filter> - </ResourceCompile> - </ItemGroup> - <ItemGroup> - <ClInclude Include="WpdObjectResources.h"> - <Filter>Header Files</Filter> - </ClInclude> - </ItemGroup> -</Project>
\ No newline at end of file diff --git a/wpd/WpdServiceSampleDriver/helpers.cpp b/wpd/WpdServiceSampleDriver/helpers.cpp deleted file mode 100644 index 49ed66fc..00000000 --- a/wpd/WpdServiceSampleDriver/helpers.cpp +++ /dev/null @@ -1,700 +0,0 @@ -#include "stdafx.h" - -#include "helpers.tmh" - -HRESULT UpdateDeviceFriendlyName( - _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension, - _In_ LPCWSTR wszDeviceFriendlyName) -{ - HRESULT hr = S_OK; - - // If we were passed NULL parameters we have nothing to do, return S_OK. - if ((pPortableDeviceClassExtension == NULL) || - (wszDeviceFriendlyName == NULL)) - { - return S_OK; - } - - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<IPortableDeviceValues> pValues; - - // Prepare to make a call to set the device information - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues for results"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues for results"); - } - - // Get the information values to update and set them in WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES - if (hr == S_OK) - { - hr = pValues->SetStringValue(WPD_DEVICE_FRIENDLY_NAME, wszDeviceFriendlyName); - CHECK_HR(hr, ("Failed to set WPD_DEVICE_FRIENDLY_NAME")); - } - - // Set the params - if (hr == S_OK) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_CLASS_EXTENSION_WRITE_DEVICE_INFORMATION.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - if (hr == S_OK) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_CLASS_EXTENSION_WRITE_DEVICE_INFORMATION.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - if (hr == S_OK) - { - hr = pParams->SetIPortableDeviceValuesValue(WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES, pValues); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES")); - } - - // Make the call - if (hr == S_OK) - { - hr = pPortableDeviceClassExtension->ProcessLibraryMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to process update device information message")); - } - - // A Failed ProcessLibraryMessage operation for updating this value is not considered - // fatal and should return S_OK. - - return S_OK; -} - -HRESULT RegisterServices( - _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension, - const bool bUnregister) -{ - // If we were passed NULL parameters we have nothing to do, return S_OK. - if (pPortableDeviceClassExtension == NULL) - { - return S_OK; - } - - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<IPortableDevicePropVariantCollection> pInterfaces; - - PROPERTYKEY commandToUse = bUnregister? - WPD_COMMAND_CLASS_EXTENSION_UNREGISTER_SERVICE_INTERFACES: - WPD_COMMAND_CLASS_EXTENSION_REGISTER_SERVICE_INTERFACES; - - // Prepare to make a call to register the services - HRESULT hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues for results"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**)&pInterfaces); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection for interfaces"); - } - - // Get the interfaces values to register and set them in WPD_PROPERTY_CLASS_EXTENSION_SERVICE_INTERFACES - if (hr == S_OK) - { - PROPVARIANT pv; - PropVariantInit(&pv); - pv.vt = VT_CLSID; - - pv.puuid = (CLSID*)&SERVICE_FullEnumSync; - hr = pInterfaces->Add(&pv); - CHECK_HR(hr, "Failed to add EnumerationSyncService to the list of requested interfaces"); - - pv.puuid = (CLSID*)&SERVICE_Contacts; - hr = pInterfaces->Add(&pv); - CHECK_HR(hr, "Failed to add ContactsSyncService to the list of requested interfaces"); - - // Don't call PropVariantClear, since we did not allocate the memory for these GUIDs - } - - // Set the params - if (hr == S_OK) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, commandToUse.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - if (hr == S_OK) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, commandToUse.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - - if (hr == S_OK) - { - hr = pParams->SetStringValue(WPD_PROPERTY_CLASS_EXTENSION_SERVICE_OBJECT_ID, CONTACTS_SERVICE_OBJECT_ID); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_CLASS_EXTENSION_SERVICE_OBJECT_ID")); - } - - if (hr == S_OK) - { - hr = pParams->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_CLASS_EXTENSION_SERVICE_INTERFACES, pInterfaces); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_CLASS_EXTENSION_SERVICE_INTERFACES")); - } - - // Make the call - if (hr == S_OK) - { - hr = pPortableDeviceClassExtension->ProcessLibraryMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to process update device information message")); - } - - return hr; -} - -DWORD GetResourceSize( - const UINT uiResource) -{ - HRESULT hr = S_OK; - LONG lError = ERROR_SUCCESS; - DWORD dwResourceSize = 0; - - HRSRC hResource = FindResource(g_hInstance, MAKEINTRESOURCE(uiResource), TEXT("DATA_FILE")); - if (hResource) - { - HGLOBAL hGlobal = LoadResource(g_hInstance, hResource); - if (hGlobal) - { - dwResourceSize = SizeofResource(g_hInstance, hResource); - } - else - { - lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - } - else - { - lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get resource size for '%d'", uiResource); - } - - return dwResourceSize; -} - -PBYTE GetResourceData( - const UINT uiResource) -{ - HRESULT hr = S_OK; - LONG lError = ERROR_SUCCESS; - PBYTE pData = NULL; - - HRSRC hResource = FindResource(g_hInstance, MAKEINTRESOURCE(uiResource), TEXT("DATA_FILE")); - if (hResource) - { - HGLOBAL hGlobal = LoadResource(g_hInstance, hResource); - if (hGlobal) - { - pData = static_cast<BYTE*>(LockResource(hGlobal)); - } - else - { - lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - } - else - { - lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get resource data pointer for '%d'", uiResource); - } - - return pData; -} - - -HRESULT AddStringValueToPropVariantCollection( - _In_ IPortableDevicePropVariantCollection* pCollection, - _In_ LPCWSTR wszValue) -{ - HRESULT hr = S_OK; - - if ((pCollection == NULL) || - (wszValue == NULL)) - { - hr = E_INVALIDARG; - return hr; - } - - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - - pv.vt = VT_LPWSTR; - pv.pwszVal = (LPWSTR)wszValue; - - // The wszValue will be copied into the collection, keeping the ownership - // of the string belonging to the caller. - // Don't call PropVariantClear, since we did not allocate the memory for these string values - - hr = pCollection->Add(&pv); - - return hr; -} - -HRESULT GetClientContextMap( - _In_ IPortableDeviceValues* pParams, - _Outptr_ ContextMap** ppContextMap) -{ - HRESULT hr = S_OK; - - if(ppContextMap == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**) ppContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - - return hr; -} - -HRESULT GetClientContext( - _In_ IPortableDeviceValues* pParams, - _In_ LPCWSTR pszContextKey, - _COM_Outptr_ IUnknown** ppContext) -{ - HRESULT hr = S_OK; - ContextMap* pContextMap = NULL; - - if(ppContext == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - *ppContext = NULL; - - hr = GetClientContextMap(pParams, &pContextMap); - CHECK_HR(hr, ("Failed to get the client context map")); - - if (SUCCEEDED(hr) && pContextMap == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Client context map is NULL")); - } - - if (SUCCEEDED(hr)) - { - *ppContext = pContextMap->GetContext(pszContextKey); - if(*ppContext == NULL) - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); - CHECK_HR(hr, "Failed to find context %ws for this client", pszContextKey); - } - } - - SAFE_RELEASE(pContextMap); - - return hr; -} - -HRESULT GetClientEventCookie( - _In_ IPortableDeviceValues* pParams, - _Outptr_result_maybenull_ LPWSTR* ppszEventCookie) -{ - HRESULT hr = S_OK; - LPWSTR pszClientContext = NULL; - ClientContext* pClientContext = NULL; - - if ((pParams == NULL) || - (ppszEventCookie == NULL)) - { - return E_POINTER; - } - - *ppszEventCookie = NULL; - - hr = pParams->GetStringValue(WPD_PROPERTY_COMMON_CLIENT_INFORMATION_CONTEXT, &pszClientContext); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_COMMON_CLIENT_INFORMATION_CONTEXT"); - - if (SUCCEEDED(hr)) - { - // Get the client context for this request. - hr = GetClientContext(pParams, pszClientContext, (IUnknown**)&pClientContext); - CHECK_HR(hr, "Failed to get the client context"); - } - - if (SUCCEEDED(hr) && (pClientContext->EventCookie.GetLength() > 0)) - { - // Get the event cookie only if it has been set - *ppszEventCookie = AtlAllocTaskWideString(pClientContext->EventCookie); - if (*ppszEventCookie == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate the client event cookie"); - } - } - - // We're done with the context - SAFE_RELEASE(pClientContext); - - CoTaskMemFree(pszClientContext); - pszClientContext = NULL; - - return hr; -} - - -HRESULT PostWpdEvent( - _In_ IPortableDeviceValues* pCommandParams, - _In_ IPortableDeviceValues* pEventParams) -{ - HRESULT hr = S_OK; - BYTE* pBuffer = NULL; - DWORD cbBuffer = 0; - LPWSTR pszEventCookie = NULL; - - CComPtr<IWDFDevice> pDevice; - CComPtr<IWpdSerializer> pSerializer; - - // Get the WUDF Device Object - hr = pCommandParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT, (IUnknown**) &pDevice); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT"); - - // Get the WpdSerializer Object - if (hr == S_OK) - { - hr = pCommandParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT, (IUnknown**) &pSerializer); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT"); - } - - if (hr == S_OK) - { - // Set the client event cookie if available. This is benign, as some clients may not provide a cookie. - HRESULT hrEventCookie = GetClientEventCookie(pCommandParams, &pszEventCookie); - if ((hrEventCookie == S_OK) && (pszEventCookie != NULL)) - { - hrEventCookie = pEventParams->SetStringValue(WPD_CLIENT_EVENT_COOKIE, pszEventCookie); - CHECK_HR(hrEventCookie, "Failed to set WPD_CLIENT_EVENT_COOKIE (error ignored)"); - } - } - - if (hr == S_OK) - { - // Create a buffer with the serialized parameters - hr = pSerializer->GetBufferFromIPortableDeviceValues(pEventParams, &pBuffer, &cbBuffer); - CHECK_HR(hr, "Failed to get buffer from IPortableDeviceValues"); - } - - // Send the event - if (hr == S_OK && pBuffer != NULL) - { - hr = pDevice->PostEvent(WPD_EVENT_NOTIFICATION, WdfEventBroadcast, pBuffer, cbBuffer); - CHECK_HR(hr, "Failed to post WPD (broadcast) event"); - } - - // Free the memory - CoTaskMemFree(pBuffer); - pBuffer = NULL; - - CoTaskMemFree(pszEventCookie); - pszEventCookie = NULL; - - return hr; -} - -HRESULT AddPropertyAttributesByType( - const FakeDevicePropertyAttributesType type, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - if (pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - if (type == UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_WRITE, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_WRITE"); - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_DELETE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_READ"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_FORM, WPD_PROPERTY_ATTRIBUTE_FORM_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FORM"); - } - else - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_WRITE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_WRITE"); - } - } - else - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_WRITE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_WRITE"); - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_DELETE"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_READ"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY, TRUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY"); - } - - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_FORM, WPD_PROPERTY_ATTRIBUTE_FORM_UNSPECIFIED); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FORM"); - } - - } - - return hr; -} - -#define WPD_PROPERTY_ATTRIBUTE_MAX_SIZE_VALUE 1024 -HRESULT SetPropertyAttributes( - _In_ REFPROPERTYKEY Key, - _In_reads_(cAttributeInfo) const PropertyAttributeInfo* AttributeInfo, - _In_ DWORD cAttributeInfo, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - - if (pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - for (DWORD dwIndex=0; dwIndex<cAttributeInfo; dwIndex++) - { - if (IsEqualPropertyKey(Key, *(AttributeInfo[dwIndex].pKey))) - { - // Set vartype - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_VARTYPE, AttributeInfo[dwIndex].Vartype); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_VARTYPE"); - - // Set name - if (hr == S_OK && AttributeInfo[dwIndex].wszName != NULL) - { - hr = pAttributes->SetStringValue(WPD_PROPERTY_ATTRIBUTE_NAME, AttributeInfo[dwIndex].wszName); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_NAME"); - } - - // Set max size for string properties - if (hr == S_OK && AttributeInfo[dwIndex].Vartype == VT_LPWSTR) - { - hr = pAttributes->SetUnsignedLargeIntegerValue(WPD_PROPERTY_ATTRIBUTE_MAX_SIZE, WPD_PROPERTY_ATTRIBUTE_MAX_SIZE_VALUE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_MAX_SIZE"); - } - - // Set access attributes - if (hr == S_OK) - { - hr = AddPropertyAttributesByType(AttributeInfo[dwIndex].AttributesType, pAttributes); - CHECK_HR(hr, "Failed to set common property attributes"); - } - - break; - } - } - - return hr; -} - -HRESULT SetMethodParameterAttributes( - _In_ REFPROPERTYKEY Parameter, - _In_reads_(cAttributeInfo) const MethodParameterAttributeInfo* AttributeInfo, - _In_ DWORD cAttributeInfo, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - - if (pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - for (DWORD dwIndex=0; dwIndex<cAttributeInfo; dwIndex++) - { - if (IsEqualPropertyKey(Parameter, *AttributeInfo[dwIndex].pKey)) - { - // Set vartype - hr = pAttributes->SetUnsignedIntegerValue(WPD_PARAMETER_ATTRIBUTE_VARTYPE, AttributeInfo[dwIndex].Vartype); - CHECK_HR(hr, "Failed to set WPD_PARAMETER_ATTRIBUTE_VARTYPE"); - - // Set form - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_PARAMETER_ATTRIBUTE_FORM, (DWORD)AttributeInfo[dwIndex].Form); - CHECK_HR(hr, "Failed to set WPD_PARAMETER_ATTRIBUTE_FORM"); - } - - // Set order - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_PARAMETER_ATTRIBUTE_ORDER, AttributeInfo[dwIndex].Order); - CHECK_HR(hr, "Failed to set WPD_PARAMETER_ATTRIBUTE_ORDER"); - } - - // Set usage - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_PARAMETER_ATTRIBUTE_USAGE, AttributeInfo[dwIndex].UsageType); - CHECK_HR(hr, "Failed to set WPD_PARAMETER_ATTRIBUTE_USAGE"); - } - - // Set name - if (hr == S_OK) - { - hr = pAttributes->SetStringValue(WPD_PARAMETER_ATTRIBUTE_NAME, AttributeInfo[dwIndex].wszName); - CHECK_HR(hr, "Failed to set WPD_PARAMETER_ATTRIBUTE_NAME"); - } - - break; - } - } - - return hr; -} - -HRESULT SetEventParameterAttributes( - _In_ REFPROPERTYKEY Parameter, - _In_reads_(cAttributeInfo) const EventParameterAttributeInfo* AttributeInfo, - _In_ DWORD cAttributeInfo, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - - if (pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - for (DWORD dwIndex=0; dwIndex<cAttributeInfo; dwIndex++) - { - if (IsEqualPropertyKey(Parameter, *AttributeInfo[dwIndex].pParameter)) - { - // Set vartype - hr = pAttributes->SetUnsignedIntegerValue(WPD_PARAMETER_ATTRIBUTE_VARTYPE, AttributeInfo[dwIndex].Vartype); - CHECK_HR(hr, "Failed to set WPD_PARAMETER_ATTRIBUTE_VARTYPE"); - break; - } - } - - return hr; - -} - -HRESULT SetEventParameters( - _In_ REFGUID Event, - _In_reads_(cAttributeInfo) const EventParameterAttributeInfo* AttributeInfo, - _In_ DWORD cAttributeInfo, - _In_ IPortableDeviceKeyCollection* pParameters) -{ - HRESULT hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED); - - if (pParameters == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - for (DWORD dwIndex=0; dwIndex<cAttributeInfo; dwIndex++) - { - GUID guidEvent = *AttributeInfo[dwIndex].pEventGuid; - PROPERTYKEY param = *AttributeInfo[dwIndex].pParameter; - - if (guidEvent == Event) - { - hr = pParameters->Add(param); - CHECK_HR(hr, "Failed to add event parameter to collection"); - } - } - - return hr; -} diff --git a/wpd/WpdServiceSampleDriver/helpers.h b/wpd/WpdServiceSampleDriver/helpers.h deleted file mode 100644 index 5ea3967b..00000000 --- a/wpd/WpdServiceSampleDriver/helpers.h +++ /dev/null @@ -1,459 +0,0 @@ -#pragma once - -#ifndef SAFE_RELEASE - #define SAFE_RELEASE(p) if( NULL != p ) { ( p )->Release(); p = NULL; } -#endif - -// {CDD18979-A7B0-4D5E-9EB2-0A826805CBBD} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT, 0xCDD18979, 0xA7B0, 0x4D5E, 0x9E, 0xB2, 0x0A, 0x82, 0x68, 0x05, 0xCB, 0xBD, 2); -// {9BD949E5-59CF-41AE-90A9-BE1D044F578F} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT, 0x9BD949E5, 0x59CF, 0x41AE, 0x90, 0xA9, 0xBE, 0x1D, 0x04, 0x4F, 0x57, 0x8F, 2); -// {4DF6C8C7-2CE5-457C-9F53-EFCECAA95C04} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, 0x4DF6C8C7, 0x2CE5, 0x457C, 0x9F, 0x53, 0xEF, 0xCE, 0xCA, 0xA9, 0x5C, 0x04, 2); -// {67BA8D9E-1DC4-431C-B89C-9D03F7D8C223} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_REQUEST_FILENAME, 0x67BA8D9E, 0x1DC4, 0x431C, 0xB8, 0x9C, 0x9D, 0x03, 0xF7, 0xD8, 0xC2, 0x23, 2); - -// Service event and parameters -// {D93102D5-8FED-4A39-AF84-228FE15888D0} -DEFINE_GUID(MyCustomEvent, 0xD93102D5, 0x8FED, 0x4A39, 0xAF, 0x84, 0x22, 0x8F, 0xE1, 0x58, 0x88, 0xD0); -// {D93102D5-8FED-4A39-AF84-228FE15888D0}.2 -DEFINE_PROPERTYKEY(MyCustomEventParam0, 0xD93102D5, 0x8FED, 0x4A39, 0xAF, 0x84, 0x22, 0x8F, 0xE1, 0x58, 0x88, 0xD0, 2); -// {D93102D5-8FED-4A39-AF84-228FE15888D0}.3 -DEFINE_PROPERTYKEY(MyCustomEventParam1, 0xD93102D5, 0x8FED, 0x4A39, 0xAF, 0x84, 0x22, 0x8F, 0xE1, 0x58, 0x88, 0xD0, 3); - -// Service method and parameters -// {ECFC865F-7B43-4D76-9C6B-D67309A3F6F7} -DEFINE_GUID(MyCustomMethod, 0xECFC865F, 0x7B43, 0x4D76, 0x9C, 0x6B, 0xD6, 0x73, 0x09, 0xA3, 0xF6, 0xF7); -// {ECFC865F-7B43-4D76-9C6B-D67309A3F6F7}.2 -DEFINE_PROPERTYKEY(MyCustomMethodResult, 0xECFC865F, 0x7B43, 0x4D76, 0x9C, 0x6B, 0xD6, 0x73, 0x09, 0xA3, 0xF6, 0xF7, 2); -// {ECFC865F-7B43-4D76-9C6B-D67309A3F6F7}.3 -DEFINE_PROPERTYKEY(MyCustomMethodParam, 0xECFC865F, 0x7B43, 0x4D76, 0x9C, 0x6B, 0xD6, 0x73, 0x09, 0xA3, 0xF6, 0xF7, 3); -// {ECFC865F-7B43-4D76-9C6B-D67309A3F6F7}.4 -DEFINE_PROPERTYKEY(MyCustomMethodParamInOut, 0xECFC865F, 0x7B43, 0x4D76, 0x9C, 0x6B, 0xD6, 0x73, 0x09, 0xA3, 0xF6, 0xF7, 4); - -// Contact versioning property -// {2B0D5AA4-7EB3-4674-BD36-23FE4C39A2C2}.2 -DEFINE_PROPERTYKEY(MyContactVersionIdentifier, 0x2B0D5AA4, 0x7EB3, 0x4674, 0xBD, 0x36, 0x23, 0xFE, 0x4C, 0x39, 0xA2, 0xC2, 2); - -// Full Enumeration Sync Replica ID -// {81176f1e-2c42-4b4e-8f79-bc1a7f3da046} -DEFINE_GUID(MyFullEnumSyncReplicaId, 0x81176f1e, 0x2c42, 0x4b4e, 0x8f, 0x79, 0xbc, 0x1a, 0x7f, 0x3d, 0xa0, 0x46); - -// Access Scope is a bit mask, where each bit enables access to a particular scope -// for example, contacts service is bit 1. -// The next scope, if any, will be in bit 2 -// Full device access is a combination of all, requires all bits to be set -typedef enum tagACCESS_SCOPE -{ - CONTACTS_SERVICE_ACCESS = 1, - FULL_DEVICE_ACCESS = 0xFFFFFFFF -}ACCESS_SCOPE; - -typedef enum tagFakeDevicePropertyAttributesType -{ - UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast, - UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, -} FakeDevicePropertyAttributesType; - -typedef struct tagPropertyAttributeInfo -{ - const PROPERTYKEY* pKey; - VARTYPE Vartype; - FakeDevicePropertyAttributesType AttributesType; - PCWSTR wszName; -} PropertyAttributeInfo; - -typedef struct tagMethodParameterAttributeInfo -{ - const PROPERTYKEY* pKey; - VARTYPE Vartype; - WPD_PARAMETER_USAGE_TYPES UsageType; - WpdParameterAttributeForm Form; - DWORD Order; - PCWSTR wszName; -} MethodParameterAttributeInfo; - -typedef struct tagEventParameterAttributeInfo -{ - const GUID* pEventGuid; - const PROPERTYKEY* pParameter; - VARTYPE Vartype; -} EventParameterAttributeInfo; - -typedef struct tagFormatAttributeInfo -{ - const GUID* pFormatGuid; - PCWSTR wszName; -} FormatAttributeInfo; - - -class ContextMap : public IUnknown -{ -public: - ContextMap() : - m_cRef(1) - { - - } - - ~ContextMap() - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - - IUnknown* pUnk = NULL; - POSITION elementPosition = NULL; - - elementPosition = m_Map.GetStartPosition(); - while(elementPosition != NULL) - { - pUnk = m_Map.GetNextValue(elementPosition); - if(pUnk != NULL) - { - pUnk->Release(); - } - } - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - return hr; - } - - -public: // Context accessor methods - - // If successful, this method AddRef's the context and returns - // a context key - HRESULT Add( - _In_ IUnknown* pContext, - _Out_ CAtlStringW& key) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - HRESULT hr = S_OK; - GUID guidContext = GUID_NULL; - CComBSTR bstrContext; - key = L""; - - // Create a unique context key - hr = CoCreateGuid(&guidContext); - if (hr == S_OK) - { - bstrContext = guidContext; - if(bstrContext.Length() > 0) - { - key = bstrContext; - } - else - { - hr = E_OUTOFMEMORY; - } - } - - if (hr == S_OK) - { - // Insert this into the map - POSITION elementPosition = m_Map.SetAt(key, pContext); - if(elementPosition != NULL) - { - // AddRef since we are holding onto it - pContext->AddRef(); - } - else - { - hr = E_OUTOFMEMORY; - } - } - return hr; - } - - void Remove( - const CAtlStringW& key) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - // Get the element - IUnknown* pContext = NULL; - - if (m_Map.Lookup(key, pContext) == true) - { - // Remove the entry for it - m_Map.RemoveKey(key); - - // Release it - pContext->Release(); - } - } - - // Returns the context pointer. If not found, return value is NULL. - // If non-NULL, caller is responsible for Releasing when it is done, - // since this method will AddRef the context. - IUnknown* GetContext( - const CAtlStringW& key) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - // Get the element - IUnknown* pContext = NULL; - - if (m_Map.Lookup(key, pContext) == true) - { - // AddRef - pContext->AddRef(); - } - return pContext; - } - -private: - CComAutoCriticalSection m_CriticalSection; - CAtlMap<CAtlStringW, IUnknown*> m_Map; - DWORD m_cRef; -}; - - -// This class is used to store the connected client information. -class ClientContext : public IUnknown -{ -public: - ClientContext() : - MajorVersion(0), - MinorVersion(0), - Revision(0), - m_cRef(1) - { - } - - ~ClientContext() - { - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -private: - DWORD m_cRef; - -public: - CAtlStringW ClientName; - CAtlStringW EventCookie; - DWORD MajorVersion; - DWORD MinorVersion; - DWORD Revision; -}; - - -class PropVariantWrapper : public tagPROPVARIANT -{ -public: - PropVariantWrapper() - { - PropVariantInit(this); - } - - PropVariantWrapper(LPCWSTR pszSrc) - { - PropVariantInit(this); - - *this = pszSrc; - } - - virtual ~PropVariantWrapper() - { - Clear(); - } - - void Clear() - { - PropVariantClear(this); - } - - PropVariantWrapper& operator= (const ULONG ulValue) - { - Clear(); - vt = VT_UI4; - ulVal = ulValue; - - return *this; - } - - PropVariantWrapper& operator= (_In_ LPCWSTR pszSrc) - { - Clear(); - - pwszVal = AtlAllocTaskWideString(pszSrc); - if(pwszVal != NULL) - { - vt = VT_LPWSTR; - } - return *this; - } - - PropVariantWrapper& operator= (_In_ IUnknown* punkSrc) - { - Clear(); - - // Need to AddRef as PropVariantClear will Release - if (punkSrc != NULL) - { - vt = VT_UNKNOWN; - punkVal = punkSrc; - punkVal->AddRef(); - } - return *this; - } - - void SetErrorValue(const HRESULT hr) - { - Clear(); - vt = VT_ERROR; - scode = hr; - } - - void SetBoolValue(const bool bValue) - { - Clear(); - vt = VT_BOOL; - if(bValue) - { - boolVal = VARIANT_TRUE; - } - else - { - boolVal = VARIANT_FALSE; - } - } -}; - -HRESULT UpdateDeviceFriendlyName( - _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension, - _In_ LPCWSTR wszDeviceFriendlyName); - -HRESULT RegisterServices( - _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension, - const bool bUnregister); - -HRESULT CheckRequestFilename( - _In_ LPCWSTR pszRequestFilename); - -DWORD GetResourceSize( - const UINT uiResource); - -PBYTE GetResourceData( - const UINT uiResource); - -HRESULT AddStringValueToPropVariantCollection( - _In_ IPortableDevicePropVariantCollection* pCollection, - _In_ LPCWSTR wszValue); - -HRESULT PostWpdEvent( - _In_ IPortableDeviceValues* pCommandParams, - _In_ IPortableDeviceValues* pEventParams); - -HRESULT GetClientContextMap( - _In_ IPortableDeviceValues* pParams, - _Outptr_ ContextMap** ppContextMap); - -HRESULT GetClientContext( - _In_ IPortableDeviceValues* pParams, - _In_ LPCWSTR pszContextKey, - _COM_Outptr_ IUnknown** ppContext); - -HRESULT GetClientEventCookie( - _In_ IPortableDeviceValues* pParams, - _Outptr_result_maybenull_ LPWSTR* ppszEventCookie); - -HRESULT AddPropertyAttributesByType( - const FakeDevicePropertyAttributesType type, - _In_ IPortableDeviceValues* pAttributes); - -HRESULT SetPropertyAttributes( - _In_ REFPROPERTYKEY Key, - _In_reads_(cAttributeInfo) const PropertyAttributeInfo* AttributeInfo, - _In_ DWORD cAttributeInfo, - _In_ IPortableDeviceValues* pAttributes); - -HRESULT SetMethodParameterAttributes( - _In_ REFPROPERTYKEY Parameter, - _In_reads_(cAttributeInfo) const MethodParameterAttributeInfo* AttributeInfo, - _In_ DWORD cAttributeInfo, - _In_ IPortableDeviceValues* pAttributes); - -HRESULT SetEventParameterAttributes( - _In_ REFPROPERTYKEY Parameter, - _In_reads_(cAttributeInfo) const EventParameterAttributeInfo* AttributeInfo, - _In_ DWORD cAttributeInfo, - _In_ IPortableDeviceValues* pAttributes); - -HRESULT SetEventParameters( - _In_ REFGUID Event, - _In_reads_(cAttributeInfo) const EventParameterAttributeInfo* AttributeInfo, - _In_ DWORD cAttributeInfo, - _In_ IPortableDeviceKeyCollection* pParameters); diff --git a/wpd/WpdServiceSampleDriver/resource.h b/wpd/WpdServiceSampleDriver/resource.h deleted file mode 100644 index 00789508..00000000 --- a/wpd/WpdServiceSampleDriver/resource.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once -#define IDR_WpdServiceSampleDriver 101 - -#define IDR_WPD_SAMPLEDRIVER_SERVICE_ICON 3000 -#define IDR_WPD_SAMPLEDRIVER_DEVICE_ICON 3001 diff --git a/wpd/WpdServiceSampleDriver/stdafx.h b/wpd/WpdServiceSampleDriver/stdafx.h deleted file mode 100644 index 359c8990..00000000 --- a/wpd/WpdServiceSampleDriver/stdafx.h +++ /dev/null @@ -1,123 +0,0 @@ -#pragma once - -#include "resource.h" -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#define STRSAFE_NO_DEPRECATE - -#include <stdio.h> -#include <tchar.h> - -#include <atlbase.h> -#include <atlcom.h> -#include <atlcoll.h> -#include <atlstr.h> - -// This driver is entirely user-mode -_Analysis_mode_(_Analysis_code_type_user_code_); - -// Driver specific tracing #defines -// -// TODO: Change these values to be appropriate for your driver. -// -#define MYDRIVER_TRACING_ID L"Microsoft\\WPD\\ServiceSampleDriver" - -// -// TODO: Choose a different trace control GUID -// -#define WPP_CONTROL_GUIDS \ - WPP_DEFINE_CONTROL_GUID(ServiceSampleDriverCtlGuid,(f0cc34b3,a482,4dc0,b978,b5cf42aec4fd), \ - WPP_DEFINE_BIT(TRACE_FLAG_ALL) \ - WPP_DEFINE_BIT(TRACE_FLAG_DEVICE) \ - WPP_DEFINE_BIT(TRACE_FLAG_DRIVER) \ - WPP_DEFINE_BIT(TRACE_FLAG_QUEUE) \ - ) - -#define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) \ - WPP_LEVEL_LOGGER(flags) - -#define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) \ - (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= lvl) - -// -// This comment block is scanned by the trace preprocessor to define our -// TraceEvents function. -// -// begin_wpp config -// FUNC Trace{FLAG=TRACE_FLAG_ALL}(LEVEL, MSG, ...); -// FUNC TraceEvents(LEVEL, FLAGS, MSG, ...); -// end_wpp - -// -// This comment block is scanned by the trace preprocessor to define our -// CHECK_HR function. -// -// -// begin_wpp config -// USEPREFIX (CHECK_HR,"%!STDPREFIX!"); -// FUNC CHECK_HR{FLAG=TRACE_FLAG_ALL}(hrCheck, MSG, ...); -// USESUFFIX (CHECK_HR, " hr= %!HRESULT!", hrCheck); -// end_wpp - -// -// PRE macro: The name of the macro includes the condition arguments FLAGS and EXP -// define in FUNC above -// -#define WPP_FLAG_hrCheck_PRE(FLAGS, hrCheck) {if(hrCheck != S_OK) { - -// -// POST macro -// The name of the macro includes the condition arguments FLAGS and EXP -// define in FUNC above -#define WPP_FLAG_hrCheck_POST(FLAGS, hrCheck) ; } } - -// -// The two macros below are for checking if the event should be logged and for -// choosing the logger handle to use when calling the ETW trace API -// -#define WPP_FLAG_hrCheck_ENABLED(FLAGS, hrCheck) WPP_FLAG_ENABLED(FLAGS) -#define WPP_FLAG_hrCheck_LOGGER(FLAGS, hrCheck) WPP_FLAG_LOGGER(FLAGS) - -#include <PortableDeviceTypes.h> -#include <PortableDeviceClassExtension.h> -#include <PortableDevice.h> - -// Service GUID definitions -#include <initguid.h> -#include <propkeydef.h> -#define DEFINE_DEVSVCGUID DEFINE_GUID -#define DEFINE_DEVSVCPROPKEY DEFINE_PROPERTYKEY -#include <DeviceServices.h> -#include <FullEnumSyncDeviceService.h> -#include <ContactDeviceService.h> - -// Forward class declarations -class WpdObjectResourceContext; -class WpdObjectEnumeratorContext; -class WpdServiceMethods; - -#include "helpers.h" -#include "FakeContent.h" -#include "FakeContactContent.h" -#include "FakeContactsServiceContent.h" -#include "FakeContactsService.h" -#include "FakeStorage.h" -#include "FakeDeviceContent.h" -#include "FakeDevice.h" - -#include "WpdServiceSampleDriver.h" -#include "WpdObjectEnum.h" -#include "WpdObjectManagement.h" -#include "WpdObjectProperties.h" -#include "WpdObjectPropertiesBulk.h" -#include "WpdObjectResources.h" -#include "WpdCapabilities.h" -#include "WpdServiceCapabilities.h" -#include "WpdServiceMethods.h" -#include "WpdService.h" -#include "WpdBaseDriver.h" - -extern HINSTANCE g_hInstance; - diff --git a/wpd/WpdWudfSampleDriver/ContextMap.h b/wpd/WpdWudfSampleDriver/ContextMap.h deleted file mode 100644 index 63127d4d..00000000 --- a/wpd/WpdWudfSampleDriver/ContextMap.h +++ /dev/null @@ -1,135 +0,0 @@ -#pragma once - -class ContextMap : public IUnknown -{ -public: - ContextMap() : - m_cRef(1) - { - - } - - ~ContextMap() - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - - IUnknown* pUnk = NULL; - POSITION elementPosition = NULL; - elementPosition = m_Map.GetStartPosition(); - while(elementPosition != NULL) - { - pUnk = m_Map.GetNextValue(elementPosition); - - if(pUnk != NULL) - { - pUnk->Release(); - } - } - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - - -public: // Context accessor methods - - // If successfull, this method AddRef's the context - HRESULT Add( - _In_ const CAtlStringW& key, - _In_ IUnknown* pContext) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - HRESULT hr = S_OK; - - // Insert this into the map - POSITION elementPosition = m_Map.SetAt(key, pContext); - if(elementPosition != NULL) - { - // AddRef since we are holding onto it - pContext->AddRef(); - } - else - { - hr = E_OUTOFMEMORY; - } - - return hr; - } - - void Remove( - _In_ const CAtlStringW& key) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - // Get the element - IUnknown* pContext = NULL; - - if (m_Map.Lookup(key, pContext) == true) - { - // Remove the entry for it - m_Map.RemoveKey(key); - - // Release it - pContext->Release(); - } - } - - // Returns the context pointer. If not found, return value is NULL. - // If non-NULL, caller is responsible for Releasing when it is done, - // since this method will AddRef the context. - IUnknown* GetContext( - _In_ const CAtlStringW& key) - { - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - // Get the element - IUnknown* pContext = NULL; - - if (m_Map.Lookup(key, pContext) == true) - { - // AddRef - pContext->AddRef(); - } - return pContext; - } - -private: - CComAutoCriticalSection m_CriticalSection; - CAtlMap<CAtlStringW, IUnknown*> m_Map; - DWORD m_cRef; -}; diff --git a/wpd/WpdWudfSampleDriver/Device.cpp b/wpd/WpdWudfSampleDriver/Device.cpp deleted file mode 100644 index 5887e5ed..00000000 --- a/wpd/WpdWudfSampleDriver/Device.cpp +++ /dev/null @@ -1,365 +0,0 @@ -// Device.cpp : Implementation of CDevice - -#include "stdafx.h" -#include "Device.h" -#include "WpdWudfSampleDriver_i.c" - -#include "Device.tmh" - -// CDevice -STDMETHODIMP_(HRESULT) -CDevice::OnD0Entry(_In_ IWDFDevice* /*pDevice*/, - WDF_POWER_DEVICE_STATE /*previousState*/) -{ - HRESULT hr = S_OK; - return hr; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnD0Exit(_In_ IWDFDevice* /*pDevice*/, - WDF_POWER_DEVICE_STATE /*newState*/) -{ - return S_OK; -} - -STDMETHODIMP_(VOID) -CDevice::OnSurpriseRemoval(_In_ IWDFDevice* /*pDevice*/) -{ - return; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnQueryRemove(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnQueryStop(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(VOID) -CDevice::OnSelfManagedIoCleanup(_In_ IWDFDevice* /*pDevice*/) -{ - return; -} - -STDMETHODIMP_(VOID) -CDevice::OnSelfManagedIoFlush(_In_ IWDFDevice* /*pDevice*/) -{ - return; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoInit(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoSuspend(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoRestart(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnSelfManagedIoStop(_In_ IWDFDevice* /*pDevice*/) -{ - return S_OK; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnPrepareHardware(_In_ IWDFDevice* pDevice) -{ - HRESULT hr = S_OK; - - if (m_pPortableDeviceClassExtension == NULL) - { - hr = CoCreateInstance(CLSID_PortableDeviceClassExtension, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceClassExtension, - (VOID**)&m_pPortableDeviceClassExtension); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceClassLibrary"); - - // Initialize the WPD Class Extension. This will enable the appropriate WPD interface GUID, - // as well as do any additional initialization (e.g. enabling Legacy Compatibility layers for those drivers - // which requsted support in their INF). - if (hr == S_OK) - { - CComPtr<IPortableDeviceValues> pOptions; - CComPtr<IPortableDevicePropVariantCollection> pContentTypes; - - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pOptions); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceClassLibrary"); - - if (hr == S_OK) - { - hr = GetSupportedContentTypes(&pContentTypes); - CHECK_HR(hr, "Failed to get supported content types"); - - // Add the supported types to the options - if (hr == S_OK) - { - hr = pOptions->SetIPortableDevicePropVariantCollectionValue(WPD_CLASS_EXTENSION_OPTIONS_SUPPORTED_CONTENT_TYPES, pContentTypes); - CHECK_HR(hr, "Failed to set WPD_CLASS_EXTENSION_OPTIONS_SUPPORTED_CONTENT_TYPES"); - } - - if (hr == S_OK) - { - hr = m_pPortableDeviceClassExtension->Initialize(pDevice, pOptions); - CHECK_HR(hr, "Failed to Initialize portable device class extension object"); - } - } - } - - if (hr == S_OK) - { - DWORD dwLength = 0; - WCHAR* pszDeviceName = NULL; - hr = pDevice->RetrieveDeviceName(NULL, &dwLength); - if(dwLength > 0) - { - pszDeviceName = new WCHAR[dwLength + 1]; - if(pszDeviceName) - { - DWORD dwLengthTemp = dwLength; - hr = pDevice->RetrieveDeviceName(pszDeviceName, &dwLengthTemp); - CHECK_HR(hr, "Failed to get device name"); - if (hr == S_OK) - { - pszDeviceName[dwLength] = L'\0'; - if (m_pWpdBaseDriver != NULL) - { - hr = m_pWpdBaseDriver->Initialize(pszDeviceName, m_pPortableDeviceClassExtension); - CHECK_HR(hr, "Failed to initialize the fake device"); - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "NULL driver class used, Driver may not be initialized"); - } - } - delete[] pszDeviceName; - pszDeviceName = NULL; - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate memory for device name"); - } - } - else - { - CHECK_HR(hr, "Failed to get device name length"); - } - } - - // Send the latest device friendly name to the Portable Device class extension library to process - if (hr == S_OK) - { - LPWSTR pwszDeviceFriendlyName = NULL; - - HRESULT hrTemp = GetDeviceFriendlyName(&pwszDeviceFriendlyName); - CHECK_HR(hrTemp, "Failed to get the device friendly name"); - - if (hrTemp == S_OK && pwszDeviceFriendlyName != NULL) - { - hrTemp = UpdateDeviceFriendlyName(m_pPortableDeviceClassExtension, pwszDeviceFriendlyName); - CHECK_HR(hrTemp, "Failed to update device friendly name information"); - } - - CoTaskMemFree(pwszDeviceFriendlyName); - pwszDeviceFriendlyName = NULL; - } - } - return hr; -} - -STDMETHODIMP_(HRESULT) -CDevice::OnReleaseHardware(_In_ IWDFDevice* pDevice) -{ - UNREFERENCED_PARAMETER(pDevice); - if (m_pWpdBaseDriver != NULL) - { - m_pWpdBaseDriver->Uninitialize(); - } - - if (m_pPortableDeviceClassExtension != NULL) - { - m_pPortableDeviceClassExtension = NULL; - } - - return S_OK; -} - -HRESULT CDevice::GetSupportedContentTypes( - _Outptr_ IPortableDevicePropVariantCollection** ppContentTypes) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - - if(ppContentTypes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *ppContentTypes = NULL; - - // Prepare to make a call to query for the content types - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - - if(SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues for results"); - } - - // Set the params - if(SUCCEEDED(hr)) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - if(SUCCEEDED(hr)) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - if(SUCCEEDED(hr)) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY, WPD_FUNCTIONAL_CATEGORY_ALL); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY")); - } - - // Make the call - if(SUCCEEDED(hr)) - { - hr = m_pWpdBaseDriver->DispatchWpdMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to dispatch message to get supported content types")); - } - - if(SUCCEEDED(hr)) - { - hr = pResults->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES, ppContentTypes); - CHECK_HR(hr, ("Failed to get WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES")); - } - - return hr; -} - -HRESULT CDevice::GetDeviceFriendlyName( - _Outptr_result_maybenull_ LPWSTR* pwszDeviceFriendlyName) -{ - HRESULT hr = S_OK; - - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<IPortableDeviceKeyCollection> pKeys; - CComPtr<IPortableDeviceValues> pValues; - - if (pwszDeviceFriendlyName == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *pwszDeviceFriendlyName = NULL; - - // Prepare to make a call to query for the device friendly name - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, NULL, CLSCTX_INPROC_SERVER, IID_IPortableDeviceValues, (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, NULL, CLSCTX_INPROC_SERVER, IID_IPortableDeviceValues, (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, NULL, CLSCTX_INPROC_SERVER, IID_IPortableDeviceKeyCollection, (VOID**)&pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection for results"); - } - - // Set the params - if (hr == S_OK) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_OBJECT_PROPERTIES_GET.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - - if (hr == S_OK) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_OBJECT_PROPERTIES_GET.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - - if (hr == S_OK) - { - hr = pParams->SetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, WPD_DEVICE_OBJECT_ID); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID")); - } - - if (hr == S_OK) - { - hr = pKeys->Add(WPD_DEVICE_FRIENDLY_NAME); - CHECK_HR(hr, ("Failed to add WPD_DEVICE_FRIENDLY_NAME to key collection")); - } - - if (hr == S_OK) - { - hr = pParams->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, pKeys); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS")); - } - - // Make the call - if (hr == S_OK) - { - hr = m_pWpdBaseDriver->DispatchWpdMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to dispatch message to get supported content types")); - } - - if (hr == S_OK) - { - hr = pResults->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, &pValues); - CHECK_HR(hr, ("Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES")); - } - - if (hr == S_OK) - { - hr = pValues->GetStringValue(WPD_DEVICE_FRIENDLY_NAME, pwszDeviceFriendlyName); - CHECK_HR(hr, ("Failed to get WPD_DEVICE_FRIENDLY_NAME")); - } - - return hr; -} - diff --git a/wpd/WpdWudfSampleDriver/Device.h b/wpd/WpdWudfSampleDriver/Device.h deleted file mode 100644 index 1d4ce01c..00000000 --- a/wpd/WpdWudfSampleDriver/Device.h +++ /dev/null @@ -1,119 +0,0 @@ -// Device.h : Declaration of the CDevice - -/*++ - -Copyright (c) 2004 Microsoft Corporation - -Module Name: - - Device.h - -Abstract: - - CWudf class declaration. This class provides the entry points for the - host process to call into. - -Author: - - Ray Patrick (raypat) - -Environment: - - User mode only - -Revision History: - - Created - 09/07/2004. - ---*/ - -#pragma once -#include "resource.h" -#include "WpdWudfSampleDriver.h" - -class ATL_NO_VTABLE CDevice : - public CComObjectRootEx<CComMultiThreadModel>, - public IPnpCallback, - public IPnpCallbackSelfManagedIo, - public IPnpCallbackHardware -{ -public: - CDevice() : - m_pWpdBaseDriver(NULL) - { - } - - DECLARE_NOT_AGGREGATABLE(CDevice) - - BEGIN_COM_MAP(CDevice) - COM_INTERFACE_ENTRY(IPnpCallback) - COM_INTERFACE_ENTRY(IPnpCallbackSelfManagedIo) - COM_INTERFACE_ENTRY(IPnpCallbackHardware) - END_COM_MAP() - -public: - static HRESULT - CreateInstance( - _In_ IWDFDeviceInitialize* pDeviceInit, - _In_ WpdBaseDriver* pWpdBaseDriver, - _COM_Outptr_ IUnknown** ppUnkwn) - { - *ppUnkwn = NULL; - - // - // Set device properties. - // - pDeviceInit->SetLockingConstraint(None); - - CComObject< CDevice> *pMyDevice = NULL; - HRESULT hr = CComObject<CDevice>::CreateInstance( &pMyDevice ); - if( SUCCEEDED (hr) ) - { - pMyDevice->AddRef(); - hr = pMyDevice->QueryInterface( __uuidof(IUnknown), - (void **) ppUnkwn - ); - if (hr == S_OK) - { - pMyDevice->m_pWpdBaseDriver = pWpdBaseDriver; - } - pMyDevice->Release(); - pMyDevice = NULL; - } - - return hr; - } - - // IPnpCallback - // - STDMETHOD_(HRESULT, OnD0Entry) (_In_ IWDFDevice* pDevice, WDF_POWER_DEVICE_STATE previousState); - STDMETHOD_(HRESULT, OnD0Exit) (_In_ IWDFDevice* pDevice, WDF_POWER_DEVICE_STATE newState); - STDMETHOD_(VOID, OnSurpriseRemoval)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnQueryRemove) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnQueryStop) (_In_ IWDFDevice* pDevice); - - // IPnpCallbackSelfManagedIo - // - STDMETHOD_(VOID, OnSelfManagedIoCleanup)(_In_ IWDFDevice* pDevice); - STDMETHOD_(VOID, OnSelfManagedIoFlush) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoInit) (_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoSuspend)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoRestart)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnSelfManagedIoStop) (_In_ IWDFDevice* pDevice); - - // IPnpCallbackHardware - // - STDMETHOD_(HRESULT, OnPrepareHardware)(_In_ IWDFDevice* pDevice); - STDMETHOD_(HRESULT, OnReleaseHardware)(_In_ IWDFDevice* pDevice); - -private: - - HRESULT GetSupportedContentTypes(_Outptr_ IPortableDevicePropVariantCollection** ppContentTypes); - - HRESULT GetDeviceFriendlyName( - _Outptr_result_maybenull_ LPWSTR* pwszDeviceFriendlyName); - - WpdBaseDriver* m_pWpdBaseDriver; - CComPtr<IPortableDeviceClassExtension> m_pPortableDeviceClassExtension; -}; - diff --git a/wpd/WpdWudfSampleDriver/DeviceObjectFakeContent.h b/wpd/WpdWudfSampleDriver/DeviceObjectFakeContent.h deleted file mode 100644 index 884d078b..00000000 --- a/wpd/WpdWudfSampleDriver/DeviceObjectFakeContent.h +++ /dev/null @@ -1,410 +0,0 @@ -#include "DeviceObjectFakeContent.h.tmh" - -#define DEVICE_PROTOCOL_VALUE L"WPD Sample Driver Protocol ver 1.00" -#define DEVICE_FIRMWARE_VERSION_VALUE L"1.0.0.0" -#define DEVICE_MODEL_VALUE L"Sample Device 1000" -#define DEVICE_MANUFACTURER_VALUE L"Windows Portable Devices Group" -#define DEVICE_SERIAL_NUMBER_VALUE L"12309342465230-12390123432111" -#define DEVICE_POWER_LEVEL_VALUE 100 -#define DEVICE_FRIENDLY_NAME L"My Sample Device 1000" - -__declspec(selectany) BYTE g_NetworkIdentifier[] = { 0x01, 0x02, 0x03, 0xff, 0xff, 0x04, 0x05, 0x06 }; - -class DeviceObjectFakeContent : public FakeContent -{ -public: - DeviceObjectFakeContent( - _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension) : FakeContent() - { - FriendlyName = DEVICE_FRIENDLY_NAME; - SyncPartner = L""; - m_pPortableDeviceClassExtension = pPortableDeviceClassExtension; - } - - DeviceObjectFakeContent(const FakeContent& src) - { - *this = src; - } - - virtual ~DeviceObjectFakeContent() - { - } - - virtual HRESULT GetSupportedProperties(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - if (SUCCEEDED(hr)) - { - hr = AddSupportedProperties(WPD_FUNCTIONAL_CATEGORY_DEVICE, ppKeys); - CHECK_HR(hr, "Failed to add additional properties for DeviceObjectFakeContent"); - } - return hr; - } - - virtual HRESULT GetAllValues( - _In_ IPortableDeviceValues* pValues) - { - HRESULT hr = S_OK; - HRESULT hrSetValue = S_OK; - - if(pValues == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Call the base class to fill in the standard properties - hr = FakeContent::GetAllValues(pValues); - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get basic property set"); - return hr; - } - - // Add WPD_DEVICE_SUPPORTS_NON_CONSUMABLE - hrSetValue = pValues->SetBoolValue(WPD_DEVICE_SUPPORTS_NON_CONSUMABLE, TRUE); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_DEVICE_SUPPORTS_NON_CONSUMABLE"); - return hrSetValue; - } - - // Add WPD_OBJECT_CONTENT_TYPE - hrSetValue = pValues->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_OBJECT_CONTENT_TYPE"); - return hrSetValue; - } - - // Add WPD_FUNCTIONAL_OBJECT_CATEGORY - hrSetValue = pValues->SetGuidValue(WPD_FUNCTIONAL_OBJECT_CATEGORY, WPD_FUNCTIONAL_CATEGORY_DEVICE); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_FUNCTIONAL_OBJECT_CATEGORY"); - return hrSetValue; - } - - // Add WPD_DEVICE_FIRMWARE_VERSION - hrSetValue = pValues->SetStringValue(WPD_DEVICE_FIRMWARE_VERSION, DEVICE_FIRMWARE_VERSION_VALUE); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_DEVICE_FIRMWARE_VERSION"); - return hrSetValue; - } - - // Add WPD_DEVICE_POWER_LEVEL - hrSetValue = pValues->SetUnsignedIntegerValue(WPD_DEVICE_POWER_LEVEL, DEVICE_POWER_LEVEL_VALUE); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_DEVICE_POWER_LEVEL"); - return hrSetValue; - } - - // Add WPD_DEVICE_POWER_SOURCE - hrSetValue = pValues->SetUnsignedIntegerValue(WPD_DEVICE_POWER_SOURCE, WPD_POWER_SOURCE_EXTERNAL); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_DEVICE_POWER_SOURCE"); - return hrSetValue; - } - - // Add WPD_DEVICE_PROTOCOL - hrSetValue = pValues->SetStringValue(WPD_DEVICE_PROTOCOL, DEVICE_PROTOCOL_VALUE); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_DEVICE_PROTOCOL"); - return hrSetValue; - } - - // Add WPD_DEVICE_MODEL - hrSetValue = pValues->SetStringValue(WPD_DEVICE_MODEL, DEVICE_MODEL_VALUE); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_DEVICE_MODEL"); - return hrSetValue; - } - - // Add WPD_DEVICE_FRIENDLY_NAME - hrSetValue = pValues->SetStringValue(WPD_DEVICE_FRIENDLY_NAME, FriendlyName); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_DEVICE_FRIENDLY_NAME"); - return hrSetValue; - } - - // Add WPD_DEVICE_SERIAL_NUMBER - hrSetValue = pValues->SetStringValue(WPD_DEVICE_SERIAL_NUMBER, DEVICE_SERIAL_NUMBER_VALUE); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_DEVICE_SERIAL_NUMBER"); - return hrSetValue; - } - - // Add WPD_DEVICE_MANUFACTURER - hrSetValue = pValues->SetStringValue(WPD_DEVICE_MANUFACTURER, DEVICE_MANUFACTURER_VALUE); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_DEVICE_MANUFACTURER"); - return hrSetValue; - } - - // Add WPD_DEVICE_TYPE - hrSetValue = pValues->SetUnsignedIntegerValue(WPD_DEVICE_TYPE, WPD_DEVICE_TYPE_PHONE); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_DEVICE_TYPE"); - return hrSetValue; - } - - // Add WPD_DEVICE_SYNC_PARTNER - hrSetValue = pValues->SetStringValue(WPD_DEVICE_SYNC_PARTNER, SyncPartner); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_DEVICE_SYNC_PARTNER"); - return hrSetValue; - } - - // Add WPD_DEVICE_NETWORK_IDENTIFIER - if (sizeof(ULONGLONG) == sizeof(g_NetworkIdentifier)) - { - ULONGLONG ullTemp; - - CopyMemory(&ullTemp, g_NetworkIdentifier, sizeof(ULONGLONG)); - hrSetValue = pValues->SetUnsignedLargeIntegerValue(WPD_DEVICE_NETWORK_IDENTIFIER, ullTemp); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_DEVICE_NETWORK_IDENTIFIER"); - return hrSetValue; - } - } - else - { - hr = E_UNEXPECTED; // This is a coding error - CHECK_HR(hr, "Failed to set WPD_DEVICE_NETWORK_IDENTIFIER"); - } - - return hr; - } - - virtual HRESULT WriteValue( - _In_ REFPROPERTYKEY key, - _In_ REFPROPVARIANT Value) - { - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(IsEqualPropertyKey(key, WPD_DEVICE_FRIENDLY_NAME)) - { - if(Value.vt == VT_LPWSTR) - { - if (Value.pwszVal != NULL && Value.pwszVal[0] != L'\0') - { - FriendlyName = Value.pwszVal; - // Let the Class Extension know about the change in Friendly Name so it can update the registry value of the same name - HRESULT hrTemp = UpdateDeviceFriendlyName(m_pPortableDeviceClassExtension, Value.pwszVal); - CHECK_HR(hrTemp, "Failed to update device friendly name"); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_DEVICE_FRIENDLY_NAME because value was an empty string"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_DEVICE_FRIENDLY_NAME because type was not VT_LPWSTR"); - } - } - else if(IsEqualPropertyKey(key, WPD_DEVICE_SYNC_PARTNER)) - { - if (Value.vt == VT_LPWSTR) - { - SyncPartner = Value.pwszVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_DEVICE_SYNC_PARTNER because type was not VT_LPWSTR"); - } - } - else - { - // Let the base class take care of any other property writes - hr = FakeContent::WriteValue(key, Value); - // No need to log the error since the base class already does it. - } - - return hr; - } - - virtual HRESULT GetSupportedResources(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - // Call the base class to fill in the standard resources if any - hr = FakeContent::GetSupportedResources(&pKeys); - CHECK_HR(hr, "Failed to get basic supported resources"); - } - - if (SUCCEEDED(hr)) - { - // Add the icon resource - hr = pKeys->Add(WPD_RESOURCE_ICON); - CHECK_HR(hr, "Failed to add WPD_RESOURCE_ICON to supported resource list"); - } - - if (SUCCEEDED(hr)) - { - hr = pKeys->QueryInterface(IID_IPortableDeviceKeyCollection, (VOID**) ppKeys); - CHECK_HR(hr, "Failed to QI for IPortableDeviceKeyCollection on IPortableDeviceKeyCollection"); - } - - return hr; - } - - virtual HRESULT GetResourceAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - UNREFERENCED_PARAMETER(Key); - - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pAttributes; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if (SUCCEEDED(hr)) - { - // Fill in the common resource attributes - hr = GetCommonResourceAttributes(&pAttributes); - CHECK_HR(hr, "Failed to get common resource attributes set"); - } - - if (SUCCEEDED(hr)) - { - if (IsEqualPropertyKey(Key, WPD_RESOURCE_ICON)) - { - // Override the size attribute for this resource. - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE, GetResourceSize(IDR_WPD_SAMPLEDRIVER_DEVICE_ICON)); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE"); - - // Override the format attribute for this resource. - hr = pAttributes->SetGuidValue(WPD_RESOURCE_ATTRIBUTE_FORMAT, WPD_OBJECT_FORMAT_ICON); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_FORMAT"); - } - } - - // Return the resource attributes - if (SUCCEEDED(hr)) - { - hr = pAttributes->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppAttributes); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on Wpd IPortableDeviceValues"); - } - return hr; - } - - // This sample driver uses a embedded image file resource as its data. - virtual HRESULT ReadData( - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) - { - HRESULT hr = S_OK; - DWORD dwBytesToTransfer = 0; - DWORD dwObjectDataSize = 0; - PBYTE pResource = NULL; - - if((pBuffer == NULL) || - (pdwNumBytesRead == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *pdwNumBytesRead = 0; - - if (IsEqualPropertyKey(ResourceKey, WPD_RESOURCE_DEFAULT)) - { - return FakeContent::ReadData(ResourceKey, dwStartByte, pBuffer, dwNumBytesToRead, pdwNumBytesRead); - } - - pResource = GetResourceData(IDR_WPD_SAMPLEDRIVER_DEVICE_ICON); - dwObjectDataSize = GetResourceSize(IDR_WPD_SAMPLEDRIVER_DEVICE_ICON); - - if (pResource == NULL) - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Failed to get resource representing the device icon data"); - } - - // Calculate how many bytes to transfer - if (hr == S_OK) - { - if (dwStartByte < dwObjectDataSize) - { - dwBytesToTransfer = (dwObjectDataSize - dwStartByte); - if (dwBytesToTransfer > dwNumBytesToRead) - { - dwBytesToTransfer = dwNumBytesToRead; - } - } - } - - // Copy the embedded image file data. - if ((hr == S_OK) && (dwBytesToTransfer > 0)) - { - memcpy(pBuffer, pResource + dwStartByte, dwBytesToTransfer); - } - - if (hr == S_OK) - { - *pdwNumBytesRead = dwBytesToTransfer; - } - - return hr; - } - - virtual GUID GetObjectFormat() - { - return FakeDeviceContent_Format; - } - -private: - CAtlStringW FriendlyName; - CAtlStringW SyncPartner; - CComPtr<IPortableDeviceClassExtension> m_pPortableDeviceClassExtension; -}; - diff --git a/wpd/WpdWudfSampleDriver/Driver.cpp b/wpd/WpdWudfSampleDriver/Driver.cpp deleted file mode 100644 index 49edc789..00000000 --- a/wpd/WpdWudfSampleDriver/Driver.cpp +++ /dev/null @@ -1,199 +0,0 @@ - -#include "stdafx.h" -#include "Driver.h" -#include "Device.h" -#include "Queue.h" - -CDriver::CDriver() -{ - - -} - -// -// The framework call this function when device is detected. This driver -// creates a device callback object and -// -HRESULT -CDriver::OnDeviceAdd( - _In_ IWDFDriver* pDriver, - _In_ IWDFDeviceInitialize* pDeviceInit - ) -/*++ - -Routine Description: - - The framework calls this function when a device is being added to - the driver stack. - -Arguments: - - IWDFDriver - Framework interface. The driver uses this - interface to create device objects. - IWDFDeviceInitialize - Framework interface. The driver uses this - interface to set device parameters before - creating the device obeject. - -Return Value: - - HRESULT S_OK - Device added successfully - ---*/ -{ - HRESULT hr = S_OK; - CComPtr<IUnknown> pDeviceCallback; - - WpdBaseDriver *pWpdBaseDriver = NULL; - - // - // Create the WPD driver object that handles all WPD messages for this device - // - pWpdBaseDriver = new WpdBaseDriver(); - if(pWpdBaseDriver == NULL) - { - hr = E_OUTOFMEMORY; - } - - if(SUCCEEDED(hr)) - { - // - // Create device callback object - // - hr = CDevice::CreateInstance(pDeviceInit, pWpdBaseDriver, &pDeviceCallback); - } - - // - // This driver has no special power management requirements and so - // we set power policy ownership to UMDF to indicate that UMDF should - // handle powermanagement for us. - // - pDeviceInit->SetPowerPolicyOwnership(FALSE); - - // - // Create WDFDevice. - // - CComPtr<IWDFDevice> pIWDFDevice; - if(SUCCEEDED(hr)) - { - hr = pDriver->CreateDevice( - pDeviceInit, - pDeviceCallback, - &pIWDFDevice); - } - - // - // Assign pWpdBaseDriver to the device object. Each UMDF device requires its own instance of - // a WpdBaseDriver to handle WPD messages. - // - if(SUCCEEDED(hr)) - { - hr = pIWDFDevice->AssignContext(this, (void*)pWpdBaseDriver); - if(SUCCEEDED(hr)) - { - // AddRef the WpdBaseDriver object since it is not stored with the - // device context. - pWpdBaseDriver->AddRef(); - } - } - - // - // Create queue callback object - // - CComPtr<IUnknown> pIUnknown; - if(S_OK == hr) - { - hr = CQueue::CreateInstance(&pIUnknown); - } - - // - // Configure the default queue. - // - if(S_OK == hr) - { - CComPtr<IWDFIoQueue> pDefaultQueue; - hr = pIWDFDevice->CreateIoQueue( - pIUnknown, - TRUE, // bDefaultQueue - WdfIoQueueDispatchSequential, - TRUE, // bPowerManaged - FALSE, // bAllowZeroLengthRequests - &pDefaultQueue); - } - - pDeviceCallback = NULL; - pIWDFDevice = NULL; - - // - // It is fine to release the interface on the callback object. - // The framework has its own refcount on this object and will - // provide an interface when calling into the driver. - // - pIUnknown = NULL; - - // Release the WpdBaseDriver object. If it was successfully added to the device context, - // it was already addref'd above. Releasing it here ensures it will be destroyed if - // an error occured and it could not be added to the device context. - SAFE_RELEASE(pWpdBaseDriver); - - return hr; -} - -void -CDriver::OnDeinitialize( - _In_ IWDFDriver* pDriver - ) -/*++ - -Routine Description: - - The framework calls this function just before de-initializing itself. All - WDF framework resources should be released by driver before returning from this call. - -Arguments: - -Return Value: - ---*/ -{ - UNREFERENCED_PARAMETER(pDriver); - return; -} - -HRESULT -CDriver::OnInitialize( - _In_ IWDFDriver* pDriver - ) -/*++ - -Routine Description: - - The framework calls this function just after loading the driver. The driver can - perform any global, device independent intialization in this routine. - -Arguments: - -Return Value: - ---*/ -{ - UNREFERENCED_PARAMETER(pDriver); - return S_OK; -} - -STDMETHODIMP_ (void) -CDriver::OnCleanup( - _In_ IWDFObject* pWdfObject - ) -{ - // Release the base driver object - HRESULT hr = S_OK; - WpdBaseDriver* pWpdBaseDriver = NULL; - - hr = pWdfObject->RetrieveContext((void**)&pWpdBaseDriver); - if((hr == S_OK) && (pWpdBaseDriver != NULL)) - { - pWpdBaseDriver->Release(); - pWpdBaseDriver = NULL; - } -} - diff --git a/wpd/WpdWudfSampleDriver/Driver.h b/wpd/WpdWudfSampleDriver/Driver.h deleted file mode 100644 index 8b754ed7..00000000 --- a/wpd/WpdWudfSampleDriver/Driver.h +++ /dev/null @@ -1,48 +0,0 @@ - -#pragma once -#include "resource.h" -#include "WpdWudfSampleDriver.h" - - -class ATL_NO_VTABLE CDriver : - public CComObjectRootEx<CComMultiThreadModel>, - public CComCoClass<CDriver, &CLSID_WpdWudfSampleDriver>, - public IDriverEntry, - public IObjectCleanup -{ -public: - CDriver(); - - DECLARE_REGISTRY_RESOURCEID(IDR_WpdWudfSampleDriver) - - DECLARE_NOT_AGGREGATABLE(CDriver) - - BEGIN_COM_MAP(CDriver) - COM_INTERFACE_ENTRY(IDriverEntry) - END_COM_MAP() - -public: - // - // IDriverEntry - // - STDMETHOD (OnInitialize)( - _In_ IWDFDriver* pDriver - ); - STDMETHOD (OnDeviceAdd)( - _In_ IWDFDriver* pDriver, - _In_ IWDFDeviceInitialize* pDeviceInit - ); - STDMETHOD_ (void, OnDeinitialize)( - _In_ IWDFDriver* pDriver - ); - - // - // IObjectCleanup - // - STDMETHOD_ (void, OnCleanup)( - _In_ IWDFObject* pWdfObject - ); -}; - -OBJECT_ENTRY_AUTO(__uuidof(WpdWudfSampleDriver), CDriver) - diff --git a/wpd/WpdWudfSampleDriver/FakeContactContent.h b/wpd/WpdWudfSampleDriver/FakeContactContent.h deleted file mode 100644 index 2f5ea76a..00000000 --- a/wpd/WpdWudfSampleDriver/FakeContactContent.h +++ /dev/null @@ -1,442 +0,0 @@ -#include "FakeContactContent.h.tmh" - -class FakeContactContent : public FakeContent -{ -public: - FakeContactContent() : - bHasContactPhoto(FALSE) - { - } - - FakeContactContent(BOOL bHasPhoto) - { - bHasContactPhoto = bHasPhoto; - } - - FakeContactContent(const FakeContent& src) - { - *this = src; - } - - virtual ~FakeContactContent() - { - } - - virtual HRESULT GetSupportedProperties(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - hr = AddSupportedProperties(WPD_OBJECT_FORMAT_VCARD2, ppKeys); - CHECK_HR(hr, "Failed to add additional properties for FakeContactContent"); - } - - return hr; - } - - virtual HRESULT GetAllValues( - _In_ IPortableDeviceValues* pStore) - { - HRESULT hr = S_OK; - HRESULT hrSetValue = S_OK; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Call the base class to fill in the standard properties - hr = FakeContent::GetAllValues(pStore); - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get basic property values"); - return hr; - } - - // Add WPD_OBJECT_ORIGINAL_FILE_NAME. We construct the original filename from the display name plus the ".vcf" extension, - // since this object's default resource is a VCARD. - CAtlStringW strFileName; - strFileName.Format(L"%ws.vcf", DisplayName.GetString()); - hrSetValue = pStore->SetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, strFileName); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_CONTACT_DISPLAY_NAME")); - return hrSetValue; - } - - // Add WPD_CONTACT_DISPLAY_NAME - hrSetValue = pStore->SetStringValue(WPD_CONTACT_DISPLAY_NAME, DisplayName); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_CONTACT_DISPLAY_NAME")); - return hrSetValue; - } - - // Add WPD_CONTACT_PRIMARY_PHONE - hrSetValue = pStore->SetStringValue(WPD_CONTACT_PRIMARY_PHONE, PrimaryPhone); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_CONTACT_PRIMARY_PHONE")); - return hrSetValue; - } - - // Add WPD_CONTACT_BUSINESS_PHONE - hrSetValue = pStore->SetStringValue(WPD_CONTACT_BUSINESS_PHONE, WorkPhone); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_CONTACT_BUSINESS_PHONE")); - return hrSetValue; - } - - // Add WPD_CONTACT_MOBILE_PHONE - hrSetValue = pStore->SetStringValue(WPD_CONTACT_MOBILE_PHONE, CellPhone); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_CONTACT_MOBILE_PHONE")); - return hrSetValue; - } - - // Add WPD_OBJECT_SIZE. Object Size is defined to be the same size as the default resource. - // In this case the Contact Photo resource (if the object has one) is not counted in the object size. This is - // because the default resource for this object contains text-only VCARD2 data, and doesn't include the Contact Photo. - // When an application transfers the default resource for this object, it will only get the VCARD2 text data, and the - // Contact Photo resource has to be transferred separately. - // This is done mainly for illustrative purposes (and convenience in the sample). In most cases, it is better to - // embed the non-default resource data in the default resource when the file format allows it - // (e.g. a VCARD2 with an embedded contact photo rather than a separate one). It does involve more work - // (because the driver has to extract the embedded data) but is usually a better experience. - CAtlStringA strVCard; - DWORD dwSize = 0; - hr = CreateVCard(pStore, strVCard); - if (hr == S_OK) - { - dwSize = strVCard.GetLength() + 1; - // Add WPD_OBJECT_SIZE - hrSetValue = pStore->SetUnsignedIntegerValue(WPD_OBJECT_SIZE, dwSize); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_SIZE")); - return hrSetValue; - } - } - return hr; - } - - virtual HRESULT WriteValue( - _In_ REFPROPERTYKEY key, - _In_ REFPROPVARIANT Value) - { - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(IsEqualPropertyKey(key, WPD_CONTACT_DISPLAY_NAME) || - IsEqualPropertyKey(key, WPD_CONTACT_PERSONAL_PHONE) || - IsEqualPropertyKey(key, WPD_CONTACT_BUSINESS_PHONE) || - IsEqualPropertyKey(key, WPD_CONTACT_MOBILE_PHONE)) - { - if(Value.vt == VT_LPWSTR) - { - if (Value.pwszVal != NULL && Value.pwszVal[0] != L'\0') - { - // Basic validation passed, so save the value appropriately - if(IsEqualPropertyKey(key, WPD_CONTACT_DISPLAY_NAME)) - { - DisplayName = Value.pwszVal; - } - else if(IsEqualPropertyKey(key, WPD_CONTACT_PRIMARY_PHONE)) - { - PrimaryPhone = Value.pwszVal; - } - else if(IsEqualPropertyKey(key, WPD_CONTACT_BUSINESS_PHONE)) - { - WorkPhone = Value.pwszVal; - } - else if(IsEqualPropertyKey(key, WPD_CONTACT_MOBILE_PHONE)) - { - CellPhone = Value.pwszVal; - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set property because value was an empty string"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set property because type was not VT_LPWSTR"); - } - } - else - { - // Call the base class to write the standard properties - hr = FakeContent::WriteValue(key, Value); - CHECK_HR(hr, "Failed to write basic value"); - } - - return hr; - } - - virtual HRESULT GetSupportedResources(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - // Call the base class to fill in the standard resources if any - hr = FakeContent::GetSupportedResources(&pKeys); - CHECK_HR(hr, "Failed to get basic supported resources"); - } - - if (SUCCEEDED(hr)) - { - // Add WPD_RESOURCE_DEFAULT - hr = pKeys->Add(WPD_RESOURCE_DEFAULT); - CHECK_HR(hr, "Failed to add WPD_RESOURCE_DEFAULT to collection"); - } - - if (SUCCEEDED(hr) && (bHasContactPhoto == TRUE)) - { - // Add the contact photo resource - hr = pKeys->Add(WPD_RESOURCE_CONTACT_PHOTO); - CHECK_HR(hr, "Failed to add WPD_RESOURCE_CONTACT_PHOTO to supported resource list"); - } - - if (SUCCEEDED(hr)) - { - hr = pKeys->QueryInterface(IID_IPortableDeviceKeyCollection, (VOID**) ppKeys); - CHECK_HR(hr, "Failed to QI for IPortableDeviceKeyCollection on IPortableDeviceKeyCollection"); - } - - return hr; - } - - virtual HRESULT GetResourceAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - UNREFERENCED_PARAMETER(Key); - - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pAttributes; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if (SUCCEEDED(hr)) - { - // Fill in the common resource attributes - hr = GetCommonResourceAttributes(&pAttributes); - CHECK_HR(hr, "Failed to get common resource attributes set"); - } - - // Override the size attribute for this resource. - if (SUCCEEDED(hr)) - { - DWORD dwSize = 0; - if (IsEqualPropertyKey(Key, WPD_RESOURCE_DEFAULT)) - { - CAtlStringA strVCard; - hr = GetVCardString(strVCard); - if (hr == S_OK) - { - dwSize = strVCard.GetLength() + 1; - } - } - else if((IsEqualPropertyKey(Key, WPD_RESOURCE_CONTACT_PHOTO)) && (bHasContactPhoto == TRUE)) - { - dwSize = GetResourceSize(IDR_WPD_SAMPLEDRIVER_CONTACT_PHOTO); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Could not return resource attributes for unknown resource %ws.%d", (LPWSTR)CComBSTR(Key.fmtid), Key.pid); - } - - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE, dwSize); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE"); - } - } - - if (SUCCEEDED(hr) && (IsEqualPropertyKey(Key, WPD_RESOURCE_CONTACT_PHOTO))) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_MEDIA_WIDTH, 100); - CHECK_HR(hr, "Failed to set WPD_MEDIA_WIDTH"); - - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_MEDIA_HEIGHT, 134); - CHECK_HR(hr, "Failed to set WPD_MEDIA_HEIGHT"); - } - - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_IMAGE_BITDEPTH, 32); - CHECK_HR(hr, "Failed to set WPD_IMAGE_BITDEPTH"); - } - - if (SUCCEEDED(hr)) - { - // Override the format attribute for this resource. - hr = pAttributes->SetGuidValue(WPD_RESOURCE_ATTRIBUTE_FORMAT, WPD_OBJECT_FORMAT_PNG); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_FORMAT"); - } - } - - // Return the resource attributes - if (SUCCEEDED(hr)) - { - hr = pAttributes->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppAttributes); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on Wpd IPortableDeviceValues"); - } - return hr; - } - - // This sample driver uses a embedded image file resource as its data. - virtual HRESULT ReadData( - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) - { - HRESULT hr = S_OK; - DWORD dwBytesToTransfer = 0; - DWORD dwObjectDataSize = 0; - PBYTE pResource = NULL; - CAtlStringA strVCard; - - if((pBuffer == NULL) || - (pdwNumBytesRead == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *pdwNumBytesRead = 0; - - if (IsEqualPropertyKey(ResourceKey, WPD_RESOURCE_DEFAULT)) - { - hr = GetVCardString(strVCard); - if (hr == S_OK) - { - pResource = (PBYTE) strVCard.GetString(); - dwObjectDataSize = strVCard.GetLength() + 1; - } - } - else if((IsEqualPropertyKey(ResourceKey, WPD_RESOURCE_CONTACT_PHOTO)) && (bHasContactPhoto == TRUE)) - { - pResource = GetResourceData(IDR_WPD_SAMPLEDRIVER_CONTACT_PHOTO); - dwObjectDataSize = GetResourceSize(IDR_WPD_SAMPLEDRIVER_CONTACT_PHOTO); - } - - if (pResource == NULL) - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Failed to get DLL resource representing WPD resource data"); - } - - // Calculate how many bytes to transfer - if (hr == S_OK) - { - if (dwStartByte < dwObjectDataSize) - { - dwBytesToTransfer = (dwObjectDataSize - dwStartByte); - if (dwBytesToTransfer > dwNumBytesToRead) - { - dwBytesToTransfer = dwNumBytesToRead; - } - - // Copy the embedded image file data. - if (dwBytesToTransfer > 0) - { - memcpy(pBuffer, pResource + dwStartByte, dwBytesToTransfer); - *pdwNumBytesRead = dwBytesToTransfer; - } - } - } - return hr; - } - - virtual GUID GetObjectFormat() - { - return WPD_OBJECT_FORMAT_VCARD2; - } - - virtual HRESULT EnableResource( - _In_ REFPROPERTYKEY ResourceKey) - { - UNREFERENCED_PARAMETER(ResourceKey); - bHasContactPhoto = TRUE; - return S_OK; - } - - HRESULT GetVCardString( - _Out_ CAtlStringA& strVCard) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pContactProperties; - - strVCard = L""; - - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pContactProperties); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - - if (hr == S_OK) - { - hr = GetAllValues(pContactProperties); - CHECK_HR(hr, "Failed to get all values for contact object [%ws]", ObjectID); - } - - if (hr == S_OK) - { - hr = CreateVCard(pContactProperties, strVCard); - CHECK_HR(hr, "Failed to create VCard string"); - } - - return hr; - } - - CAtlStringW DisplayName; - CAtlStringW PrimaryPhone; - CAtlStringW WorkPhone; - CAtlStringW CellPhone; - BOOL bHasContactPhoto; -}; - diff --git a/wpd/WpdWudfSampleDriver/FakeContent.h b/wpd/WpdWudfSampleDriver/FakeContent.h deleted file mode 100644 index 6e427793..00000000 --- a/wpd/WpdWudfSampleDriver/FakeContent.h +++ /dev/null @@ -1,576 +0,0 @@ -#include "FakeContent.h.tmh" - -class FakeContent -{ -public: - FakeContent() : - MarkedForDeletion(FALSE), - CanDelete(TRUE), - IsHidden(FALSE), - IsSystem(FALSE), - NonConsumable(FALSE) - { - ContentType = WPD_CONTENT_TYPE_UNSPECIFIED; - } - - FakeContent(const FakeContent& src) : - MarkedForDeletion(FALSE), - CanDelete(TRUE), - IsHidden(FALSE), - IsSystem(FALSE), - NonConsumable(FALSE) - { - *this = src; - } - - virtual ~FakeContent() - { - } - - virtual FakeContent& operator= (const FakeContent& src) - { - ObjectID = src.ObjectID; - PersistentUniqueID = src.PersistentUniqueID; - ParentID = src.ParentID; - Name = src.Name; - FileName = src.FileName; - ContentType = src.ContentType; - MarkedForDeletion = src.MarkedForDeletion; - CanDelete = src.CanDelete; - IsHidden = src.IsHidden; - IsSystem = src.IsSystem; - NonConsumable = src.NonConsumable; - - return *this; - } - - virtual HRESULT GetSupportedProperties(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - hr = AddSupportedProperties(GetObjectFormat(), ppKeys); - CHECK_HR(hr, ("Failed to add supported proeprties for FakeContent")); - return hr; - } - - virtual HRESULT GetAllValues(_In_ IPortableDeviceValues* pStore) - { - HRESULT hr = S_OK; - HRESULT hrSetValue = S_OK; - PropVariantWrapper pvValue; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Add WPD_OBJECT_ID - pvValue = ObjectID; - hrSetValue = pStore->SetValue(WPD_OBJECT_ID, &pvValue); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_ID")); - return hrSetValue; - } - - // Add WPD_OBJECT_PERSISTENT_UNIQUE_ID - pvValue = this->PersistentUniqueID; - hrSetValue = pStore->SetValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, &pvValue); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_PERSISTENT_UNIQUE_ID")); - return hrSetValue; - } - - // Add WPD_OBJECT_PARENT_ID - pvValue = ParentID; - hrSetValue = pStore->SetValue(WPD_OBJECT_PARENT_ID, &pvValue); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_PARENT_ID")); - return hrSetValue; - } - - // Add WPD_OBJECT_NAME - pvValue = Name; - hrSetValue = pStore->SetValue(WPD_OBJECT_NAME, &pvValue); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_NAME")); - return hrSetValue; - } - - // Add WPD_OBJECT_CONTENT_TYPE - hrSetValue = pStore->SetGuidValue(WPD_OBJECT_CONTENT_TYPE, ContentType); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_CONTENT_TYPE")); - return hrSetValue; - } - - // Add WPD_OBJECT_FORMAT - hrSetValue = pStore->SetGuidValue(WPD_OBJECT_FORMAT, GetObjectFormat()); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_FORMAT")); - return hrSetValue; - } - - // Add WPD_OBJECT_CAN_DELETE - hrSetValue = pStore->SetBoolValue(WPD_OBJECT_CAN_DELETE, CanDelete); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_CAN_DELETE")); - return hrSetValue; - } - - // Add WPD_OBJECT_ISHIDDEN - hrSetValue = pStore->SetBoolValue(WPD_OBJECT_ISHIDDEN, IsHidden); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_ISHIDDEN")); - return hrSetValue; - } - - // Add WPD_OBJECT_ISSYSTEM - hrSetValue = pStore->SetBoolValue(WPD_OBJECT_ISSYSTEM, IsSystem); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_ISSYSTEM")); - return hrSetValue; - } - - // Add WPD_OBJECT_NON_CONSUMABLE - hrSetValue = pStore->SetBoolValue(WPD_OBJECT_NON_CONSUMABLE, NonConsumable); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_NON_CONSUMABLE")); - return hrSetValue; - } - - // Add WPD_FOLDER_CONTENT_TYPES_ALLOWED if necessary - if(!RestrictToContentTypes.IsEmpty()) - { - CComPtr<IPortableDevicePropVariantCollection> pContentTypes; - hrSetValue = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pContentTypes); - CHECK_HR(hrSetValue, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - - if (hrSetValue == S_OK) - { - PROPVARIANT pvContentType = {0}; - PropVariantInit(&pvContentType); - pvContentType.vt = VT_CLSID; // Don't PropVariantClear this since we won't allocate memory for it - - size_t numElems = RestrictToContentTypes.GetCount(); - for(size_t typeIndex = 0; hrSetValue == S_OK && typeIndex < numElems; typeIndex++) - { - pvContentType.puuid = &RestrictToContentTypes[typeIndex]; - hrSetValue = pContentTypes->Add(&pvContentType); - CHECK_HR(hrSetValue, "Failed to add content type"); - } - - if (hrSetValue == S_OK) - { - hrSetValue = pStore->SetIPortableDevicePropVariantCollectionValue(WPD_FOLDER_CONTENT_TYPES_ALLOWED, pContentTypes); - CHECK_HR(hrSetValue, "Failed to set WPD_FOLDER_CONTENT_TYPES_ALLOWED"); - } - - if (FAILED(hrSetValue)) - { - hr = hrSetValue; - } - } - } - - return hr; - } - - virtual HRESULT WriteValue( - _In_ REFPROPERTYKEY key, - _In_ REFPROPVARIANT Value) - { - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(IsEqualPropertyKey(key, WPD_OBJECT_NAME)) - { - if(Value.vt == VT_LPWSTR) - { - if (Value.pwszVal != NULL && Value.pwszVal[0] != L'\0') - { - Name = Value.pwszVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME because value was an empty string"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_NAME because type was not VT_LPWSTR"); - } - } - else if (IsEqualPropertyKey(key, WPD_OBJECT_NON_CONSUMABLE)) - { - if(Value.vt == VT_BOOL) - { - NonConsumable = Value.boolVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_NON_CONSUMABLE because type was not VT_BOOL"); - } - } - else - { - hr = E_ACCESSDENIED; - CHECK_HR(hr, "Property %ws.%d on [%ws] does not support set value operation", CComBSTR(key.fmtid), key.pid, ObjectID); - } - - return hr; - } - - virtual HRESULT GetAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pAttributes; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (SUCCEEDED(hr)) - { - hr = AddFixedPropertyAttributes(GetObjectFormat(), Key, pAttributes); - CHECK_HR(hr, "Failed to add fixed property attributes for %ws.%d on FakeContent", CComBSTR(Key.fmtid), Key.pid); - } - - // Some of our properties have extra attributes on top of the ones that are common to all - if(IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - CAtlStringW strDefaultName; - - strDefaultName.Format(L"%ws%ws", L"Name", ObjectID.GetString()); - - hr = pAttributes->SetStringValue(WPD_PROPERTY_ATTRIBUTE_DEFAULT_VALUE, strDefaultName.GetString());; - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_DEFAULT_VALUE"); - } - - // Return the property attributes - if (SUCCEEDED(hr)) - { - hr = pAttributes->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppAttributes); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on Wpd IPortableDeviceValues"); - } - return hr; - } - - virtual HRESULT GetSupportedResources(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // This object has no resources so return the empty collection - if (SUCCEEDED(hr)) - { - hr = pKeys->QueryInterface(IID_IPortableDeviceKeyCollection, (VOID**) ppKeys); - CHECK_HR(hr, "Failed to QI for IPortableDeviceKeyCollection on IPortableDeviceKeyCollection"); - } - - return hr; - } - - virtual HRESULT GetResourceAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - UNREFERENCED_PARAMETER(Key); - *ppAttributes = NULL; - - // This object has no resources therefore has no attributes to return. - - return E_NOTIMPL; - } - - virtual HRESULT ReadData( - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) - { - HRESULT hr = S_OK; - DWORD dwBytesToTransfer = 0; - - if((pBuffer == NULL) || - (pdwNumBytesRead == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *pdwNumBytesRead = 0; - UNREFERENCED_PARAMETER(ResourceKey); - - // Calculate how many bytes to transfer - if (hr == S_OK) - { - if (dwStartByte < FAKE_DATA_SIZE) - { - dwBytesToTransfer = (FAKE_DATA_SIZE - dwStartByte); - if (dwBytesToTransfer > dwNumBytesToRead) - { - dwBytesToTransfer = dwNumBytesToRead; - } - } - } - - // This sample driver does not have any real data content, - // so we generate fake data content. - // The content we generate is made up of the Name string repeated - // in the data buffer. - if ((hr == S_OK) && (dwBytesToTransfer > 0)) - { - DWORD dwOffset = 0; - DWORD dwSourceStringSizeInBytes = (Name.GetLength() * sizeof(WCHAR)) + sizeof(L'\0'); - for (DWORD counter = 0; counter < (dwBytesToTransfer / dwSourceStringSizeInBytes); counter++) - { - _Analysis_assume_((dwOffset + dwSourceStringSizeInBytes) <= dwNumBytesToRead); - memcpy(pBuffer + dwOffset, Name.GetString(), dwSourceStringSizeInBytes); - dwOffset += dwSourceStringSizeInBytes; - } - memset(pBuffer + dwOffset, 0, dwBytesToTransfer % dwSourceStringSizeInBytes); - } - - if (hr == S_OK) - { - *pdwNumBytesRead = dwBytesToTransfer; - } - - return hr; - } - - virtual HRESULT WriteData( - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _In_reads_(dwNumBytesToWrite) BYTE* pBuffer, - DWORD dwNumBytesToWrite, - _Out_ DWORD* pdwNumBytesWritten) - { - HRESULT hr = S_OK; - - if((pBuffer == NULL) || - (pdwNumBytesWritten == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *pdwNumBytesWritten = 0; - UNREFERENCED_PARAMETER(ResourceKey); - UNREFERENCED_PARAMETER(dwStartByte); - // This fake driver does nothing with the data. The write method is simply - // a dummy one. - // Normally, a driver would copy the contents from the buffer to the device. - - if (hr == S_OK) - { - *pdwNumBytesWritten = dwNumBytesToWrite; - } - - return hr; - } - - virtual GUID GetObjectFormat() - { - return FakeContent_Format; - } - - virtual HRESULT EnableResource( - _In_ REFPROPERTYKEY ResourceKey) - { - UNREFERENCED_PARAMETER(ResourceKey); - return E_NOTIMPL; - } - - CAtlStringW ObjectID; - CAtlStringW PersistentUniqueID; - CAtlStringW ParentID; - CAtlStringW Name; - CAtlStringW FileName; - GUID ContentType; - BOOL MarkedForDeletion; - BOOL CanDelete; - BOOL IsHidden; - BOOL IsSystem; - BOOL NonConsumable; - CAtlArray<GUID> RestrictToContentTypes; -}; - -class FakeGenericFileContent : public FakeContent -{ -public: - - virtual HRESULT GetAllValues( - _In_ IPortableDeviceValues* pStore) - { - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Call the base class to fill in the standard properties - hr = FakeContent::GetAllValues(pStore); - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get basic property set"); - return hr; - } - - // Add WPD_OBJECT_ORIGINAL_FILE_NAME - pvValue = FileName; - hr = pStore->SetValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &pvValue); - if (hr != S_OK) - { - CHECK_HR(hr, ("Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME")); - return hr; - } - - return hr; - } - - virtual HRESULT GetSupportedResources(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - // Call the base class to fill in the standard resources if any - hr = FakeContent::GetSupportedResources(&pKeys); - CHECK_HR(hr, "Failed to get basic supported resources"); - } - - if (SUCCEEDED(hr)) - { - // Add WPD_RESOURCE_DEFAULT - hr = pKeys->Add(WPD_RESOURCE_DEFAULT); - CHECK_HR(hr, "Failed to add WPD_RESOURCE_DEFAULT to collection"); - } - - if (SUCCEEDED(hr)) - { - hr = pKeys->QueryInterface(IID_IPortableDeviceKeyCollection, (VOID**) ppKeys); - CHECK_HR(hr, "Failed to QI for IPortableDeviceKeyCollection on IPortableDeviceKeyCollection"); - } - - return hr; - } - - virtual HRESULT GetResourceAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pAttributes; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if (SUCCEEDED(hr)) - { - // Fill in the common resource attributes - hr = GetCommonResourceAttributes(&pAttributes); - CHECK_HR(hr, "Failed to get common resource attributes set"); - } - - // Override the necessary attributes for this resource. - if ((hr == S_OK) && (IsEqualPropertyKey(Key, WPD_RESOURCE_DEFAULT))) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_WRITE, TRUE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_WRITE"); - } - - // Return the resource attributes - if (SUCCEEDED(hr)) - { - hr = pAttributes->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppAttributes); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on Wpd IPortableDeviceValues"); - } - return hr; - } -}; diff --git a/wpd/WpdWudfSampleDriver/FakeDevice.h b/wpd/WpdWudfSampleDriver/FakeDevice.h deleted file mode 100644 index 56b9990a..00000000 --- a/wpd/WpdWudfSampleDriver/FakeDevice.h +++ /dev/null @@ -1,2415 +0,0 @@ -#include "FakeDevice.h.tmh" - -#define NUM_VERTICAL_OBJECTS 7 -#define NUM_IMAGE_OBJECTS 31 -#define NUM_MUSIC_OBJECTS 8 -#define NUM_VIDEO_OBJECTS 4 -#define NUM_MEMO_OBJECTS 2 -#define NUM_CONTACT_OBJECTS 5 -#define STORAGE1_OBJECT_ID L"Storage1" -#define STORAGE2_OBJECT_ID L"Storage2" -#define RENDERING_INFORMATION_OBJECT_ID L"RenderingInformation" -#define NETWORK_CONFIG_OBJECT_ID L"NetworkConfig" -#define UNTYPEDDATA_FOLDER_OBJECT_ID L"UntypedData" -#define CONTACT_FOLDER_OBJECT_ID L"Phonebook" -#define MEDIA_FOLDER_OBJECT_ID L"Media folder" -#define MEMO_FOLDER_OBJECT_ID L"Memo folder" -#define IMAGE_FOLDER_OBJECT_ID L"Picture folder" -#define MUSIC_FOLDER_OBJECT_ID L"Music folder" -#define VIDEO_FOLDER_OBJECT_ID L"Video folder" - -/** - * This class represents an abstraction of a real device. - * Driver implementors should replace this with their own - * device I/O classes/libraries. - */ -class FakeDevice -{ -public: - FakeDevice() : - m_dwLastObjectID(0) - { - - } - - ~FakeDevice() - { - for(size_t index = 0; index < m_Content.GetCount(); index++) - { - delete m_Content[index]; - m_Content[index] = NULL; - } - } - - HRESULT InitializeContent( - _In_ IPortableDeviceClassExtension *pPortableDeviceClassExtension) - { - HRESULT hr = S_OK; - - if(pPortableDeviceClassExtension == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Add device object - CAutoPtr<DeviceObjectFakeContent> pDeviceObjectContent(new DeviceObjectFakeContent(pPortableDeviceClassExtension)); - if (pDeviceObjectContent) - { - pDeviceObjectContent->Name = L"Fake Device"; - pDeviceObjectContent->ParentID = L""; - pDeviceObjectContent->ObjectID = WPD_DEVICE_OBJECT_ID; - pDeviceObjectContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pDeviceObjectContent->ObjectID.GetString()); - pDeviceObjectContent->CanDelete = FALSE; - pDeviceObjectContent->IsHidden = TRUE; - pDeviceObjectContent->ContentType = WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT; - - _ATLTRY - { - m_Content.Add(pDeviceObjectContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding DeviceObjectFakeContent"); - return hr; - } - pDeviceObjectContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - - // Add Toplevel object: Storage1 - CAutoPtr<StorageObjectFakeContent> pStorageContent(new StorageObjectFakeContent()); - if (pStorageContent) - { - pStorageContent->Name = STORAGE1_OBJECT_ID; - pStorageContent->ParentID = WPD_DEVICE_OBJECT_ID; - pStorageContent->ObjectID = pStorageContent->Name; - pStorageContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pStorageContent->ObjectID.GetString()); - pStorageContent->CanDelete = FALSE; - pStorageContent->ContentType = WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT; - pStorageContent->IsExternalStorage = FALSE; - pStorageContent->Capacity = 120034890000; - pStorageContent->FreeSpaceInBytes = 60017445000; - - _ATLTRY - { - m_Content.Add(pStorageContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding StorageObjectFakeContent"); - return hr; - } - pStorageContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - - // Add Toplevel object: Storage2 - pStorageContent.Attach(new StorageObjectFakeContent()); - if (pStorageContent) - { - pStorageContent->Name = STORAGE2_OBJECT_ID; - pStorageContent->ParentID = WPD_DEVICE_OBJECT_ID; - pStorageContent->ObjectID = pStorageContent->Name; - pStorageContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pStorageContent->ObjectID.GetString()); - pStorageContent->CanDelete = FALSE; - pStorageContent->ContentType = WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT; - pStorageContent->IsExternalStorage = TRUE; - pStorageContent->Capacity = 80000000000; - pStorageContent->FreeSpaceInBytes = 75000000000; - - _ATLTRY - { - m_Content.Add(pStorageContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding StorageObjectFakeContent"); - return hr; - } - pStorageContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - - // Add Toplevel object: RenderingInformation - CAutoPtr<RenderingInformationFakeContent> pRenderingInformationContent(new RenderingInformationFakeContent()); - if (pRenderingInformationContent) - { - pRenderingInformationContent->Name = RENDERING_INFORMATION_OBJECT_ID; - pRenderingInformationContent->ParentID = WPD_DEVICE_OBJECT_ID; - pRenderingInformationContent->ObjectID = pRenderingInformationContent->Name; - pRenderingInformationContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pRenderingInformationContent->ObjectID.GetString()); - pRenderingInformationContent->CanDelete = FALSE; - pRenderingInformationContent->IsHidden = TRUE; - pRenderingInformationContent->ContentType = WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT; - - _ATLTRY - { - m_Content.Add(pRenderingInformationContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding RenderingInformationFakeContent"); - return hr; - } - pRenderingInformationContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - - // Add Toplevel object: NetworkConfig - CAutoPtr<NetworkConfigFakeContent> pNetworkConfigContent(new NetworkConfigFakeContent()); - if (pNetworkConfigContent) - { - pNetworkConfigContent->Name = NETWORK_CONFIG_OBJECT_ID; - pNetworkConfigContent->ParentID = WPD_DEVICE_OBJECT_ID; - pNetworkConfigContent->ObjectID = pNetworkConfigContent->Name; - pNetworkConfigContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pNetworkConfigContent->ObjectID.GetString()); - pNetworkConfigContent->CanDelete = FALSE; - pNetworkConfigContent->IsHidden = TRUE; - pNetworkConfigContent->ContentType = WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT; - pNetworkConfigContent->RestrictToContentTypes.Add(WPD_CONTENT_TYPE_NETWORK_ASSOCIATION); - pNetworkConfigContent->RestrictToContentTypes.Add(WPD_CONTENT_TYPE_WIRELESS_PROFILE); - - _ATLTRY - { - m_Content.Add(pNetworkConfigContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding NetworkConfigFakeContent"); - return hr; - } - pNetworkConfigContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - - // Add Toplevel object: Untyped data folder - CAutoPtr<FakeFolderContent> pFolderContent(new FakeFolderContent()); - if (pFolderContent) - { - pFolderContent->Name = UNTYPEDDATA_FOLDER_OBJECT_ID; - pFolderContent->ParentID = STORAGE2_OBJECT_ID; - pFolderContent->ObjectID = pFolderContent->Name; - pFolderContent->FileName = pFolderContent->Name; - pFolderContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pFolderContent->ObjectID.GetString()); - pFolderContent->CanDelete = FALSE; - pFolderContent->ContentType = WPD_CONTENT_TYPE_FOLDER; - - _ATLTRY - { - m_Content.Add(pFolderContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeFolderContent"); - return hr; - } - pFolderContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - - // Add Toplevel object: Phonebook folder - pFolderContent.Attach(new FakeFolderContent()); - if (pFolderContent) - { - pFolderContent->Name = CONTACT_FOLDER_OBJECT_ID; - pFolderContent->ParentID = STORAGE1_OBJECT_ID; - pFolderContent->ObjectID = pFolderContent->Name; - pFolderContent->FileName = pFolderContent->Name; - pFolderContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pFolderContent->ObjectID.GetString()); - pFolderContent->CanDelete = FALSE; - pFolderContent->ContentType = WPD_CONTENT_TYPE_FOLDER; - pFolderContent->RestrictToContentTypes.Add(WPD_CONTENT_TYPE_CONTACT); - - _ATLTRY - { - m_Content.Add(pFolderContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeFolderContent"); - return hr; - } - pFolderContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - - // Add Toplevel folder object with custom icon: Memos - CAutoPtr<FakeMemoFolderContent> pMemoFolderContent(new FakeMemoFolderContent()); - if (pMemoFolderContent) - { - pMemoFolderContent->Name = MEMO_FOLDER_OBJECT_ID; - pMemoFolderContent->ParentID = STORAGE1_OBJECT_ID; - pMemoFolderContent->ObjectID = pMemoFolderContent->Name; - pMemoFolderContent->FileName = pMemoFolderContent->Name; - pMemoFolderContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pMemoFolderContent->ObjectID.GetString()); - pMemoFolderContent->CanDelete = FALSE; - pMemoFolderContent->ContentType = WPD_CONTENT_TYPE_FOLDER; - pMemoFolderContent->RestrictToContentTypes.Add(WPD_CONTENT_TYPE_MEMO); - - _ATLTRY - { - m_Content.Add(pMemoFolderContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeMemoFolderContent"); - return hr; - } - pMemoFolderContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - - // Add Toplevel object: Media folder - pFolderContent.Attach(new FakeFolderContent()); - if (pFolderContent) - { - pFolderContent->Name = MEDIA_FOLDER_OBJECT_ID; - pFolderContent->ParentID = STORAGE1_OBJECT_ID; - pFolderContent->ObjectID = pFolderContent->Name; - pFolderContent->FileName = pFolderContent->Name; - pFolderContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pFolderContent->ObjectID.GetString()); - pFolderContent->CanDelete = FALSE; - pFolderContent->ContentType = WPD_CONTENT_TYPE_FOLDER; - pFolderContent->RestrictToContentTypes.Add(WPD_CONTENT_TYPE_FOLDER); - - _ATLTRY - { - m_Content.Add(pFolderContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeFolderContent"); - return hr; - } - pFolderContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - - // Add Media folder: Picture folder - pFolderContent.Attach(new FakeFolderContent()); - if (pFolderContent) - { - pFolderContent->Name = IMAGE_FOLDER_OBJECT_ID; - pFolderContent->ParentID = MEDIA_FOLDER_OBJECT_ID; - pFolderContent->ObjectID = pFolderContent->Name; - pFolderContent->FileName = pFolderContent->Name; - pFolderContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pFolderContent->ObjectID.GetString()); - pFolderContent->CanDelete = FALSE; - pFolderContent->ContentType = WPD_CONTENT_TYPE_FOLDER; - pFolderContent->RestrictToContentTypes.Add(WPD_CONTENT_TYPE_IMAGE); - - _ATLTRY - { - m_Content.Add(pFolderContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeFolderContent"); - return hr; - } - pFolderContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - - // Add Media folder: Music folder - pFolderContent.Attach(new FakeFolderContent()); - if (pFolderContent) - { - pFolderContent->Name = MUSIC_FOLDER_OBJECT_ID; - pFolderContent->ParentID = MEDIA_FOLDER_OBJECT_ID; - pFolderContent->ObjectID = pFolderContent->Name; - pFolderContent->FileName = pFolderContent->Name; - pFolderContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pFolderContent->ObjectID.GetString()); - pFolderContent->CanDelete = FALSE; - pFolderContent->ContentType = WPD_CONTENT_TYPE_FOLDER; - pFolderContent->RestrictToContentTypes.Add(WPD_CONTENT_TYPE_AUDIO); - - _ATLTRY - { - m_Content.Add(pFolderContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeFolderContent"); - return hr; - } - pFolderContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - - // Add Media folder: Video folder - pFolderContent.Attach(new FakeFolderContent()); - if (pFolderContent) - { - pFolderContent->Name = VIDEO_FOLDER_OBJECT_ID; - pFolderContent->ParentID = MEDIA_FOLDER_OBJECT_ID; - pFolderContent->ObjectID = pFolderContent->Name; - pFolderContent->FileName = pFolderContent->Name; - pFolderContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pFolderContent->ObjectID.GetString()); - pFolderContent->CanDelete = FALSE; - pFolderContent->ContentType = WPD_CONTENT_TYPE_FOLDER; - pFolderContent->RestrictToContentTypes.Add(WPD_CONTENT_TYPE_VIDEO); - - _ATLTRY - { - m_Content.Add(pFolderContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeFolderContent"); - return hr; - } - pFolderContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - - // Add generic file content objects to storage 1 - for(DWORD dwIndex = 0; dwIndex < NUM_VERTICAL_OBJECTS; dwIndex++) - { - m_dwLastObjectID++; - - CAutoPtr<FakeGenericFileContent> pGenericFileContent(new FakeGenericFileContent()); - if (pGenericFileContent) - { - pGenericFileContent->Name.Format(L"Name%d", m_dwLastObjectID); - pGenericFileContent->ParentID = STORAGE1_OBJECT_ID; - pGenericFileContent->ObjectID.Format(L"%d", m_dwLastObjectID); - pGenericFileContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pGenericFileContent->ObjectID.GetString()); - pGenericFileContent->ContentType = WPD_CONTENT_TYPE_UNSPECIFIED; - pGenericFileContent->CanDelete = FALSE; - pGenericFileContent->IsHidden = TRUE; - pGenericFileContent->IsSystem = TRUE; - pGenericFileContent->FileName = pGenericFileContent->Name; - - _ATLTRY - { - m_Content.Add(pGenericFileContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeGenericFileContent"); - return hr; - } - pGenericFileContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - } - - // Add image objects to the image folder - for(DWORD dwImageIndex = 0; dwImageIndex < NUM_IMAGE_OBJECTS; dwImageIndex++) - { - m_dwLastObjectID++; - - CAutoPtr<FakeImageContent> pImageContent(new FakeImageContent()); - if (pImageContent) - { - pImageContent->Name.Format(L"Image%d", m_dwLastObjectID); - pImageContent->ParentID = IMAGE_FOLDER_OBJECT_ID; - pImageContent->ObjectID.Format(L"%d", m_dwLastObjectID); - pImageContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pImageContent->ObjectID.GetString()); - pImageContent->ContentType = WPD_CONTENT_TYPE_IMAGE; - pImageContent->FileName.Format(L"ImageFile_%d.jpg", m_dwLastObjectID); - - _ATLTRY - { - m_Content.Add(pImageContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeImageContent"); - return hr; - } - pImageContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - } - - // Add music objects to the music folder - for(DWORD dwMusicIndex = 0; dwMusicIndex < NUM_MUSIC_OBJECTS; dwMusicIndex++) - { - m_dwLastObjectID++; - - CAutoPtr<FakeMusicContent> pMusicContent(new FakeMusicContent()); - if (pMusicContent) - { - pMusicContent->Name.Format(L"Music%d", m_dwLastObjectID); - pMusicContent->ParentID = MUSIC_FOLDER_OBJECT_ID; - pMusicContent->ObjectID.Format(L"%d", m_dwLastObjectID); - pMusicContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pMusicContent->ObjectID.GetString()); - pMusicContent->ContentType = WPD_CONTENT_TYPE_AUDIO; - pMusicContent->FileName.Format(L"MusicFile_%d.wma", m_dwLastObjectID); - - _ATLTRY - { - m_Content.Add(pMusicContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeMusicContent"); - return hr; - } - pMusicContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - } - - // Add video objects to the video folder - for(DWORD dwVideoIndex = 0; dwVideoIndex < NUM_VIDEO_OBJECTS; dwVideoIndex++) - { - m_dwLastObjectID++; - - CAutoPtr<FakeVideoContent> pVideoContent(new FakeVideoContent()); - if (pVideoContent) - { - pVideoContent->Name.Format(L"Video%d", m_dwLastObjectID); - pVideoContent->ParentID = VIDEO_FOLDER_OBJECT_ID; - pVideoContent->ObjectID.Format(L"%d", m_dwLastObjectID); - pVideoContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pVideoContent->ObjectID.GetString()); - pVideoContent->ContentType = WPD_CONTENT_TYPE_VIDEO; - pVideoContent->FileName.Format(L"VideoFile_%d.wmv", m_dwLastObjectID); - - _ATLTRY - { - m_Content.Add(pVideoContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeVideoContent"); - return hr; - } - pVideoContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - } - - // Add contact objects to the contact folder - for(DWORD dwContactIndex = 0; dwContactIndex < NUM_CONTACT_OBJECTS; dwContactIndex++) - { - m_dwLastObjectID++; - - CAutoPtr<FakeContactContent> pContactContent(new FakeContactContent()); - if (pContactContent) - { - if ((m_dwLastObjectID % 2) == 0) // Mark every second contact as having a photo - { - pContactContent->bHasContactPhoto = TRUE; - } - pContactContent->Name.Format(L"Contact%d", m_dwLastObjectID); - pContactContent->ParentID = CONTACT_FOLDER_OBJECT_ID; - pContactContent->ObjectID.Format(L"%d", m_dwLastObjectID); - pContactContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pContactContent->ObjectID.GetString()); - pContactContent->ContentType = WPD_CONTENT_TYPE_CONTACT; - pContactContent->DisplayName.Format(L"Surname%d, FirstName%d", dwContactIndex, dwContactIndex); - pContactContent->PrimaryPhone = L"(425) 555 0821"; - pContactContent->WorkPhone = L"(425) 556 6010"; - pContactContent->CellPhone = L"(206) 557 1441"; - - _ATLTRY - { - m_Content.Add(pContactContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeContactContent"); - return hr; - } - pContactContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - } - - // Add memo objects to the memo folder - for(DWORD dwMemoIndex = 0; dwMemoIndex < NUM_MEMO_OBJECTS; dwMemoIndex++) - { - m_dwLastObjectID++; - - CAutoPtr<FakeMemoContent> pMemoContent(new FakeMemoContent()); - if (pMemoContent) - { - pMemoContent->Name.Format(L"Memo%d", m_dwLastObjectID); - pMemoContent->ParentID = MEMO_FOLDER_OBJECT_ID; - pMemoContent->ObjectID.Format(L"%d", m_dwLastObjectID); - pMemoContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pMemoContent->ObjectID.GetString()); - pMemoContent->ContentType = WPD_CONTENT_TYPE_MEMO; - pMemoContent->FileName.Format(L"MemoFile_%d.mem", m_dwLastObjectID); - - _ATLTRY - { - m_Content.Add(pMemoContent); - } - _ATLCATCH(e) - { - hr = e; - CHECK_HR(hr, "ATL Exception when adding FakeMemoContent"); - return hr; - } - pMemoContent.Detach(); - } - else - { - hr = E_OUTOFMEMORY; - return hr; - } - } - - return hr; - } - - bool FindNext( const DWORD dwStartIndex, - _In_ const CAtlStringW& strParentID, - _Out_ CAtlStringW& strObjectID, - _Out_ DWORD* pdwNextStartIndex) - { - DWORD curIndex = 0; - bool bFound = false; - strObjectID = L""; - *pdwNextStartIndex = 0; - - if(dwStartIndex >= m_Content.GetCount()) - { - return false; - } - - for(curIndex = dwStartIndex; curIndex < m_Content.GetCount(); curIndex++) - { - if(m_Content[curIndex]->ParentID == strParentID) - { - strObjectID = m_Content[curIndex]->ObjectID; - bFound = true; - break; - } - } - - if(bFound) - { - *pdwNextStartIndex = curIndex + 1; - } - else - { - *pdwNextStartIndex = (DWORD) m_Content.GetCount(); - } - - return bFound; - } - - /** - * Returns a pointer to the fake content in pElement corresponding to - * the specified ObjectID. - * Return value is true if found, otherwise false. - */ - _Success_(return) - bool GetContent(_In_ LPCWSTR pszObjectID, _Outptr_result_nullonfailure_ FakeContent** ppElement) - { - bool bFound = false; - - if((pszObjectID == NULL) || - (ppElement == NULL)) - { - return false; - } - - *ppElement = NULL; - - for(DWORD Index = 0; Index < m_Content.GetCount(); Index++) - { - if(m_Content[Index]->ObjectID == pszObjectID) - { - *ppElement = m_Content[Index]; - bFound = true; - break; - } - } - - return bFound; - } - - /** - * Returns the index of the fake content corresponding to the - * specified ObjectID. - * Return value is true if found, otherwise false. - */ - bool GetContentIndex(_In_ LPCWSTR pszObjectID, _Out_ DWORD* pIndex) - { - bool bFound = false; - - if((pszObjectID == NULL) || - (pIndex == NULL)) - { - return false; - } - - *pIndex = 0; - - for(DWORD Index = 0; Index < m_Content.GetCount(); Index++) - { - if(m_Content[Index]->ObjectID == pszObjectID) - { - *pIndex = Index; - bFound = true; - break; - } - } - - return bFound; - } - - HRESULT GetSupportedProperties( - _In_ LPCWSTR pszObjectID, - _COM_Outptr_ IPortableDeviceKeyCollection** ppCollection) - { - HRESULT hr = S_OK; - FakeContent* pElement = NULL; - - *ppCollection = NULL; - - if(GetContent(pszObjectID, &pElement)) - { - hr = pElement->GetSupportedProperties(ppCollection); - CHECK_HR(hr, "Failed to get supported properties on element [%ws]", pszObjectID ? pszObjectID : L"NULL"); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszObjectID ? pszObjectID : L"NULL"); - } - - return hr; - } - - HRESULT GetAllValues( - _In_ LPCWSTR pszObjectID, - _COM_Outptr_ IPortableDeviceValues** ppValues) - { - HRESULT hr = S_OK; - FakeContent* pElement = NULL; - - if(ppValues == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppValues = NULL; - - if(GetContent(pszObjectID, &pElement)) - { - CComPtr<IPortableDeviceValues> pValues; - - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - - if (SUCCEEDED(hr)) - { - hr = pElement->GetAllValues(pValues); - CHECK_HR(hr, "Failed to fill property values"); - - if (SUCCEEDED(hr)) - { - // Keep hr intact in case it is S_FALSE - HRESULT hrTemp = pValues->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppValues); - - if (FAILED(hrTemp)) - { - hr = hrTemp; - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on Wpd IPortableDeviceValues"); - } - } - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszObjectID ? pszObjectID : L"NULL"); - } - - return hr; - } - - /** - * This fake device is an unrealistic example from a performance standpoint, since - * requesting some values is more costly than requesting all values. - * The reason for this is that is is easier for the underlying objects to simply return all the - * values, and for us to filter out only the ones we want here. - * It is not expected that real devices function this way. - */ - HRESULT GetValues( - _In_ LPCWSTR pszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys, - _COM_Outptr_ IPortableDeviceValues** ppValues) - { - HRESULT hr = S_OK; - BOOL bError = FALSE; - CComPtr<IPortableDeviceValues> pAllValues; - CComPtr<IPortableDeviceValues> pValues; - - if((pszObjectID == NULL) || - (pKeys == NULL) || - (ppValues == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - *ppValues = NULL; - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Get ALL values (NOTE: This is inefficient) - if (SUCCEEDED(hr)) - { - hr = GetAllValues(pszObjectID, &pAllValues); - CHECK_HR(hr, "Failed to get property values [%ws]", pszObjectID); - } - - // Return only the requested values - if (SUCCEEDED(hr)) - { - PROPVARIANT pv = {0}; - DWORD dwIndex = 0; - PROPERTYKEY Key = WPD_PROPERTY_NULL; - while(SUCCEEDED(hr) && pKeys->GetAt(dwIndex, &Key) == S_OK) - { - hr = pAllValues->GetValue(Key, &pv); - if(FAILED(hr)) - { - bError = TRUE; - hr = pValues->SetErrorValue(Key, hr); - CHECK_HR(hr, "Failed to set error value for %ws.%d", (LPWSTR)CComBSTR(Key.fmtid),Key.pid); - } - else - { - hr = pValues->SetValue(Key, &pv); - CHECK_HR(hr, "Failed to set property value %ws.%d", (LPWSTR)CComBSTR(Key.fmtid),Key.pid); - } - - PropVariantClear(&pv); - dwIndex++; - } - } - - if (SUCCEEDED(hr)) - { - hr = pValues->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppValues); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on Wpd IPortableDeviceValues"); - } - - if (SUCCEEDED(hr) && - (bError == TRUE)) - { - hr = S_FALSE; - } - - return hr; - } - - HRESULT WriteProperty( - _In_ LPCWSTR pszObjectID, - _In_ REFPROPERTYKEY key, - _In_ REFPROPVARIANT Value) - { - HRESULT hr = S_OK; - FakeContent* pElement = NULL; - - if(GetContent(pszObjectID, &pElement)) - { - hr = pElement->WriteValue(key, Value); - CHECK_HR(hr, "Failed to write property value"); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszObjectID ? pszObjectID : L"NULL"); - } - - return hr; - } - - HRESULT WritePropertiesOnObject( - _In_ LPCWSTR pszObjectID, - _In_ IPortableDeviceValues* pValues, - _COM_Outptr_ IPortableDeviceValues** ppWriteResults) - { - HRESULT hr = S_OK; - bool bErrorOnWrite = false; - DWORD cValues = 0; - CComPtr<IPortableDeviceValues> pWriteResults; - - *ppWriteResults = NULL; - - // Create property store for values - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pWriteResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (SUCCEEDED(hr)) - { - hr = pValues->GetCount(&cValues); - CHECK_HR(hr, "Failed to get property count"); - } - - if (SUCCEEDED(hr)) - { - for(DWORD dwIndex = 0; dwIndex < cValues; dwIndex++) - { - HRESULT hrWrite = S_OK; - PROPERTYKEY Key = {0}; - PropVariantWrapper pvValue; - PropVariantWrapper pvWriteResult; - - hrWrite = pValues->GetAt(dwIndex, &Key, &pvValue); - CHECK_HR(hrWrite, "Failed to get property key/value at index %d", dwIndex); - - if (SUCCEEDED(hrWrite)) - { - FakeContent* pElement = NULL; - if(GetContent(pszObjectID, &pElement)) - { - hr = pElement->WriteValue(Key, pvValue); - CHECK_HR(hr, "Failed to write property value"); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszObjectID ? pszObjectID : L"NULL"); - } - } - - // Always set the write result for this property - pvWriteResult.SetErrorValue(hrWrite); - if(FAILED(hrWrite)) - { - bErrorOnWrite = true; - } - - hrWrite = pWriteResults->SetValue(Key, &pvWriteResult); - CHECK_HR(hrWrite, "Failed to set write result for property %ws.%d", CComBSTR(Key.fmtid), Key.pid); - } - } - - if (SUCCEEDED(hr)) - { - hr = pWriteResults->QueryInterface(IID_IPortableDeviceValues, (VOID**)ppWriteResults); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on IPortableDeviceValues"); - } - - // Remember to set the hr to S_FALSE if there were any failures writing a property. - if((hr == S_OK) && - (bErrorOnWrite == true)) - { - hr = S_FALSE; - } - - return hr; - } - - HRESULT GetAttributes( - _In_ LPCWSTR pszObjectID, - _In_ REFPROPERTYKEY key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - HRESULT hr = S_OK; - FakeContent* pElement = NULL; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if(GetContent(pszObjectID, &pElement)) - { - hr = pElement->GetAttributes(key, ppAttributes); - CHECK_HR(hr, "Failed to get attributes for %ws.%d", CComBSTR(key.fmtid), key.pid); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszObjectID); - } - return hr; - } - - HRESULT GetSupportedResources( - _In_ LPCWSTR pszObjectID, - _COM_Outptr_ IPortableDeviceKeyCollection** ppCollection) - { - HRESULT hr = S_OK; - FakeContent* pElement = NULL; - - *ppCollection = NULL; - - if(GetContent(pszObjectID, &pElement)) - { - hr = pElement->GetSupportedResources(ppCollection); - CHECK_HR(hr, "Failed to get supported resources on element [%ws]", pszObjectID ? pszObjectID : L"NULL"); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszObjectID ? pszObjectID : L"NULL"); - } - - return hr; - } - - HRESULT GetResourceAttributes( - _In_ LPCWSTR pszObjectID, - _In_ REFPROPERTYKEY key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - HRESULT hr = S_OK; - FakeContent* pElement = NULL; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if(GetContent(pszObjectID, &pElement)) - { - hr = pElement->GetResourceAttributes(key, ppAttributes); - CHECK_HR(hr, "Failed to get resource attributes for %ws.%d", CComBSTR(key.fmtid), key.pid); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszObjectID); - } - return hr; - } - - HRESULT ReadData( - _In_ LPCWSTR pszObjectID, - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) - { - HRESULT hr = S_OK; - FakeContent* pElement = NULL; - - if((pBuffer == NULL) || - (pdwNumBytesRead == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *pdwNumBytesRead = 0; - - if(GetContent(pszObjectID, &pElement)) - { - hr = pElement->ReadData(ResourceKey, dwStartByte, pBuffer, dwNumBytesToRead, pdwNumBytesRead); - CHECK_HR(hr, "Failed to read resource data for %ws.%d", CComBSTR(ResourceKey.fmtid), ResourceKey.pid); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszObjectID); - } - return hr; - } - - HRESULT WriteData( - _In_ LPCWSTR pszObjectID, - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _In_reads_(dwNumBytesToWrite) BYTE* pBuffer, - DWORD dwNumBytesToWrite, - _Out_ DWORD* pdwNumBytesWritten) - { - HRESULT hr = S_OK; - FakeContent* pElement = NULL; - - if((pBuffer == NULL) || - (pdwNumBytesWritten == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *pdwNumBytesWritten = 0; - - if(GetContent(pszObjectID, &pElement)) - { - hr = pElement->WriteData(ResourceKey, dwStartByte, pBuffer, dwNumBytesToWrite, pdwNumBytesWritten); - CHECK_HR(hr, "Failed to write resource data for %ws.%d", CComBSTR(ResourceKey.fmtid), ResourceKey.pid); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszObjectID); - } - return hr; - } - - HRESULT MarkChildrenForDeletion( - _In_ LPCWSTR pszParentObjectID) - { - HRESULT hr = S_OK; - - CAtlStringW strParentObjectID = pszParentObjectID; - for (size_t Index = 0; Index < m_Content.GetCount(); Index++) - { - if (m_Content[Index]->ParentID == strParentObjectID) - { - // Mark this object - m_Content[Index]->MarkedForDeletion = TRUE; - hr = MarkChildrenForDeletion(m_Content[Index]->ObjectID); - if (FAILED(hr)) - { - break; - } - } - } - return hr; - } - - HRESULT RemoveObjectsMarkedForDeletion() - { - HRESULT hr = S_OK; - - for (size_t Index = m_Content.GetCount(); Index > 0; Index--) - { - if (m_Content[Index - 1]->MarkedForDeletion == TRUE) - { - // Delete this object - FakeContent* pContent = m_Content[Index - 1]; - m_Content.RemoveAt(Index - 1); - delete pContent; - } - } - - // Removes empty elements - m_Content.FreeExtra(); - - return hr; - } - - BOOL CanDeleteObject( - _In_ LPCWSTR pszObjectID) - { - BOOL bCanDelete = FALSE; - - for (size_t Index = 0; Index < m_Content.GetCount(); Index++) - { - if (m_Content[Index]->ObjectID == pszObjectID) - { - bCanDelete = m_Content[Index]->CanDelete; - break; - } - } - return bCanDelete; - } - - HRESULT DeleteObject( - DWORD dwOptions, - _In_ LPCWSTR pszObjectID) - { - HRESULT hr = S_OK; - DWORD dwIndex = 0; - - if(pszObjectID == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Do an access check to verify whether the object may be deleted - if(CanDeleteObject(pszObjectID) == FALSE) - { - hr = E_ACCESSDENIED; - CHECK_HR(hr, "Failed to delete read-only object %ws", pszObjectID); - } - - // Objects can only be deleted with the no recursion flag - // if they have no children. - if ((dwOptions == PORTABLE_DEVICE_DELETE_NO_RECURSION) && - (HasChildren(pszObjectID) == TRUE)) - { - hr = HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION); - return hr; - } - - // Loop through the objects and delete the children only if - // the recursive option is specified. - if (dwOptions == PORTABLE_DEVICE_DELETE_WITH_RECURSION) - { - hr = MarkChildrenForDeletion(pszObjectID); - CHECK_HR(hr, "Error attempting to mark objects for (recursive) deletion"); - } - - // Mark this object for deletion - if (hr == S_OK) - { - if(GetContentIndex(pszObjectID, &dwIndex)) - { - m_Content[dwIndex]->MarkedForDeletion = TRUE; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszObjectID); - } - } - - // Delete the objects - if (hr == S_OK) - { - hr = RemoveObjectsMarkedForDeletion(); - CHECK_HR(hr, "Failed to remove objects marked for deletion"); - } - - return hr; - } - - BOOL HasChildren( - _In_ LPCWSTR pszObjectID) - { - BOOL bHasChild = FALSE; - - if (pszObjectID == NULL) - { - bHasChild = FALSE; - return bHasChild; - } - - CAtlStringW strObjectID = pszObjectID; - for (size_t Index = 0; Index < m_Content.GetCount(); Index++) - { - if (m_Content[Index]->ParentID == strObjectID) - { - bHasChild = TRUE; - break; - } - } - - return bHasChild; - } - - HRESULT SaveNewObject( - _In_ IPortableDeviceValues* pObjectProperties, - _Outptr_result_nullonfailure_ LPWSTR* ppszObjectID) - { - HRESULT hr = S_OK; - DWORD dwParentIndex = 0; - LPWSTR pszObjectName = NULL; - LPWSTR pszParentID = NULL; - GUID guidContentType = WPD_CONTENT_TYPE_UNSPECIFIED; - - if(pObjectProperties == NULL || ppszObjectID == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - *ppszObjectID = NULL; - - // Get the content type - hr = pObjectProperties->GetGuidValue(WPD_OBJECT_CONTENT_TYPE, &guidContentType); - CHECK_HR(hr, "Failed to get WPD_OBJECT_CONTENT_TYPE"); - - // Get ParentID from pValues - if (SUCCEEDED(hr)) - { - hr = pObjectProperties->GetStringValue(WPD_OBJECT_PARENT_ID, &pszParentID); - CHECK_HR(hr, "Failed to get WPD_OBJECT_PARENT_ID"); - } - - // Get Object Name from pValues - if (SUCCEEDED(hr)) - { - hr = pObjectProperties->GetStringValue(WPD_OBJECT_NAME, &pszObjectName); - CHECK_HR(hr, "Failed to get WPD_OBJECT_NAME"); - } - - if (SUCCEEDED(hr) && !GetContentIndex(pszParentID, &dwParentIndex)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid Parent ObjectID [%ws]", pszParentID); - } - - // Check whether the parent can hold objects of this content type - if (SUCCEEDED(hr)) - { - hr = IsValidContentType(guidContentType, m_Content[dwParentIndex]->RestrictToContentTypes); - CHECK_HR(hr, "Object named [%ws] could not be created, because parent [%ws] does not support this content type", pszObjectName, pszParentID); - } - - if (SUCCEEDED(hr)) - { - FakeContent* pContent; - - // Create the object - hr = CreateContentObject(pszObjectName, pszParentID, guidContentType, pObjectProperties, &pContent); - CHECK_HR(hr, "Failed to create object named %ws", pszObjectName); - - // Add it to the sample driver's internal list of content objects - if (SUCCEEDED(hr)) - { - m_Content.Add(pContent); - *ppszObjectID = AtlAllocTaskWideString(pContent->ObjectID); - if(*ppszObjectID == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Faield to allocate memory for newly created object's ID"); - } - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszParentID); - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszObjectName); - - return hr; - } - - const CAtlStringW GetParentID( - _In_ LPCWSTR pszObjectID) - { - CAtlStringW strParent = L""; - - for (size_t Index = 0; Index < m_Content.GetCount(); Index++) - { - if(m_Content[Index]->ObjectID.CompareNoCase(pszObjectID) == 0) - { - strParent = m_Content[Index]->ParentID; - break; - } - } - - return strParent; - } - - BOOL GetDepthFromParent( - _In_ LPCWSTR pszObjectID, - _In_ LPCWSTR pszParentObjectID, - _Out_ DWORD* pdwDepth) - { - HRESULT hr = S_OK; - BOOL bDescendant = FALSE; - - if((pszObjectID == NULL) || - (pszParentObjectID == NULL) || - (pdwDepth == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return bDescendant; - } - - *pdwDepth = 0; - - DWORD dwDepth = 0; - CAtlStringW strCurObject = pszObjectID; - - while((strCurObject.CompareNoCase(pszParentObjectID) != 0) && - (strCurObject.GetLength() > 0)) - { - strCurObject = GetParentID(strCurObject); - dwDepth++; - } - - if(strCurObject.CompareNoCase(pszParentObjectID) == 0) - { - bDescendant = TRUE; - *pdwDepth = dwDepth; - } - - return bDescendant; - } - -#pragma warning(suppress: 6388) // PREFast bug means here there is a false positive for the call to CComPtr<>::QueryInterface(). - HRESULT GetObjectIDsByFormat( - _In_ REFGUID guidObjectFormat, - _In_ LPCWSTR pszParentObjectID, - DWORD dwDepth, - _COM_Outptr_ IPortableDevicePropVariantCollection** ppObjectIDs) - { - HRESULT hr = S_OK; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - - if(ppObjectIDs == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - *ppObjectIDs = NULL; - - // Create the ObjectID collection. Since this sample driver does not - // have any real hardware, it cannot take advantage of the devices - // 'bulk' operations, and so we must simulate it here. - // For simplicity, this sample driver simply walks the list of - // objects, finds out whether they are of the specified format and depth, and - // if the are then adds them to an object list. This is - // easy to do, but not the most efficient way to do it. - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pObjectIDs); - CHECK_HR(hr, "Failed to CoCreate CLSID_IPortableDevicePropVariantCollection"); - } - - if (SUCCEEDED(hr)) - { - // Walk the list of objects - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - pv.vt = VT_LPWSTR; - for (size_t Index = 0; Index < m_Content.GetCount(); Index++) - { - // Check whether the object is of the correct format - if((m_Content[Index]->GetObjectFormat() == guidObjectFormat) || (guidObjectFormat == WPD_OBJECT_FORMAT_ALL)) - { - DWORD dwObjectDepth = 0; - // find out the depth of this object from the parent - if(GetDepthFromParent(m_Content[Index]->ObjectID, pszParentObjectID, &dwObjectDepth)) - { - // If it is within the appropriate depth, add it - if(dwObjectDepth <= dwDepth) - { - pv.pwszVal = (LPWSTR) m_Content[Index]->ObjectID.GetString(); - hr = pObjectIDs->Add(&pv); - CHECK_HR(hr, "Failed to add next ObjectID to collection"); - if(FAILED(hr)) - { - break; - } - } - } - } - } - } - - if (SUCCEEDED(hr)) - { - hr = pObjectIDs->QueryInterface(IID_PPV_ARGS(ppObjectIDs)); - CHECK_HR(hr, "Failed to QI IPortableDevicePropVariantCollection for IPortableDevicePropVariantCollection"); - } - - return hr; - } - - HRESULT GetObjectIDFromPersistentID( - _In_ LPCWSTR pszPersistentID, - _Outptr_result_nullonfailure_ LPWSTR* ppszObjectID) - { - HRESULT hr = S_OK; - - if((pszPersistentID == NULL) || - (ppszObjectID == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - *ppszObjectID = NULL; - - for (size_t Index = 0; Index < m_Content.GetCount(); Index++) - { - if(m_Content[Index]->PersistentUniqueID.CompareNoCase(pszPersistentID) == 0) - { - *ppszObjectID = AtlAllocTaskWideString(m_Content[Index]->ObjectID); - if(*ppszObjectID == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Could not allocate memory for ObjectID"); - } - break; - } - } - - if ((hr == S_OK) && (*ppszObjectID == NULL)) - { - // We reached the end of the content but did not find the element - hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); - } - - return hr; - } - - /** - * Since this is a fake device with no hardware or real contents, we simulate - * a format by deleting the contents of a storage object. - **/ - HRESULT FormatStorage( - _In_ LPCWSTR pszObjectID, - _In_ IPortableDeviceValues* pCommandParams) - { - HRESULT hr = S_OK; - CAtlStringW strObjectID = pszObjectID; - - // Validate that the object specified is one of our storage objects - if((strObjectID.CompareNoCase(STORAGE1_OBJECT_ID) == 0) || - (strObjectID.CompareNoCase(STORAGE2_OBJECT_ID) == 0)) - { - CComPtr<IPortableDeviceValues> pEventParams; - - hr = GetObjectPropertiesForEvent(strObjectID.GetString(), &pEventParams); - CHECK_HR(hr, "Failed to get storage object properties for event"); - - // Indicate that format has started - hr = PostWpdEventWithProgress(pCommandParams, pEventParams, WPD_EVENT_STORAGE_FORMAT, WPD_OPERATION_STATE_STARTED, 0); - CHECK_HR(hr, "Failed to send format event progress: WPD_OPERATION_STATE_STARTED"); - - if (hr == S_OK) - { - hr = MarkChildrenForDeletion(pszObjectID); - CHECK_HR(hr, "Failed to mark children of storage for deletion"); - - // Indicate that format is halfway there - hr = PostWpdEventWithProgress(pCommandParams, pEventParams, WPD_EVENT_STORAGE_FORMAT, WPD_OPERATION_STATE_RUNNING, 50); - CHECK_HR(hr, "Failed to send format progress notification"); - - // Delete the objects - if (hr == S_OK) - { - hr = RemoveObjectsMarkedForDeletion(); - CHECK_HR(hr, "Failed to remove objects marked for deletion"); - } - - } - - // Indicate that format is done - hr = PostWpdEventWithProgress(pCommandParams, pEventParams, WPD_EVENT_STORAGE_FORMAT, WPD_OPERATION_STATE_FINISHED, 100); - CHECK_HR(hr, "Failed to send format event progress: WPD_OPERATION_STATE_FINISHED"); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Cannot format object [%ws] because it is not a storage", pszObjectID); - } - - return hr; - } - - HRESULT MoveObject( - _In_ LPCWSTR pszObjectID, - _In_ LPCWSTR pszDestinationID) - { - HRESULT hr = S_OK; - FakeContent* pSource = NULL; - FakeContent* pDestFolder = NULL; - - if(GetContent(pszObjectID, &pSource)) - { - // Verify that this is a content object. Functional objects cannot be moved. - if(pSource->ContentType != WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT) - { - // Verify that the source is not the same as the destination - if(pSource->ObjectID.CompareNoCase(pszDestinationID) != 0) - { - // Verify that the destination is a folder - if(GetContent(pszDestinationID, &pDestFolder)) - { - if(pDestFolder->ContentType == WPD_CONTENT_TYPE_FOLDER) - { - pSource->ParentID = pszDestinationID; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Destination [%ws] for move object is not a folder", pszDestinationID); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszDestinationID ? pszDestinationID : L"NULL"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Object [%ws] cannot be moved to itself", pszObjectID); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Attempting to move functional object %ws", pszObjectID); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszObjectID ? pszObjectID : L"NULL"); - } - - return hr; - } - - HRESULT CopyObject( - _In_ LPCWSTR pszObjectID, - _In_ LPCWSTR pszDestinationID, - _Outptr_result_nullonfailure_ LPWSTR* ppNewObjectID) - { - HRESULT hr = S_OK; - FakeContent* pSource = NULL; - FakeContent* pDestFolder = NULL; - CComPtr<IPortableDeviceValues> pNewContentProperties; - LPWSTR pwszNewObjectID = NULL; - - if(ppNewObjectID == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - *ppNewObjectID = NULL; - - if(GetContent(pszObjectID, &pSource)) - { - // Verify that this is a content object. Functional objects cannot be copied. - if(pSource->ContentType != WPD_CONTENT_TYPE_FUNCTIONAL_OBJECT) - { - // Verify that the source is not the same as the destination - if(pSource->ObjectID.CompareNoCase(pszDestinationID) != 0) - { - // Verify that the destination is a folder - if(GetContent(pszDestinationID, &pDestFolder)) - { - if(pDestFolder->ContentType == WPD_CONTENT_TYPE_FOLDER) - { - hr = GetAllValues(pSource->ObjectID, &pNewContentProperties); - CHECK_HR(hr, "Failed to get ALL values for [%ws]", pSource->ObjectID); - - if (SUCCEEDED(hr)) - { - hr = pNewContentProperties->SetStringValue(WPD_OBJECT_PARENT_ID, pDestFolder->ObjectID); - CHECK_HR(hr, "Failed to update WPD_OBJECT_PARENT_ID value to content object[%ws] on new copied content", pDestFolder->ObjectID); - } - - if (SUCCEEDED(hr)) - { - hr = SaveNewObject(pNewContentProperties, &pwszNewObjectID); - CHECK_HR(hr, "Failed Create new content from object[%ws]", pSource->ObjectID); - } - - // If the object we just copied was a folder and it contained child objects we need to copy the contents as well. - if (SUCCEEDED(hr) && (pSource->ContentType == WPD_CONTENT_TYPE_FOLDER) && (HasChildren(pSource->ObjectID) == TRUE)) - { - hr = CopyChildrenToNewParent(pSource->ObjectID, pwszNewObjectID); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Destination [%ws] for move object is not a folder", pszDestinationID); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszDestinationID ? pszDestinationID : L"NULL"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Object [%ws] cannot be copied to itself", pszObjectID); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Attempting to move functional object %ws", pszObjectID); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszObjectID ? pszObjectID : L"NULL"); - } - - // If we failed, free the allocated object ID. - if (FAILED(hr)) - { - if (pwszNewObjectID != NULL) - { - CoTaskMemFree(pwszNewObjectID); - pwszNewObjectID = NULL; - } - } - - if (pwszNewObjectID != NULL) - { - // The newly created object ID is given to the caller to manage and free - *ppNewObjectID = pwszNewObjectID; - } - - return hr; - } - - HRESULT GetObjectPropertiesForEvent( - _In_ LPCWSTR pszObjectID, - _COM_Outptr_ IPortableDeviceValues** ppValues) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - CComPtr<IPortableDeviceValues> pValues; - - *ppValues = NULL; - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - // Add the keys we need in order to fill out event parameters - if (SUCCEEDED(hr)) - { - hr = pKeys->Add(WPD_OBJECT_PERSISTENT_UNIQUE_ID); - CHECK_HR(hr, "Failed to add WPD_OBJECT_PERSISTENT_UNIQUE_ID"); - - if (SUCCEEDED(hr)) - { - hr = pKeys->Add(WPD_OBJECT_NAME); - CHECK_HR(hr, "Failed to add WPD_OBJECT_NAME"); - } - if (SUCCEEDED(hr)) - { - hr = pKeys->Add(WPD_OBJECT_CONTENT_TYPE); - CHECK_HR(hr, "Failed to add WPD_OBJECT_CONTENT_TYPE"); - } - - //These properties may or may not exist on the object - if (SUCCEEDED(hr)) - { - hr = pKeys->Add(WPD_FUNCTIONAL_OBJECT_CATEGORY); - CHECK_HR(hr, "Failed to add WPD_FUNCTIONAL_OBJECT_CATEGORY"); - } - if (SUCCEEDED(hr)) - { - hr = pKeys->Add(WPD_OBJECT_ORIGINAL_FILE_NAME); - CHECK_HR(hr, "Failed to add WPD_OBJECT_ORIGINAL_FILE_NAME"); - } - if (SUCCEEDED(hr)) - { - hr = pKeys->Add(WPD_OBJECT_PARENT_ID); - CHECK_HR(hr, "Failed to add WPD_OBJECT_PARENT_ID"); - } - } - - // Get the values - if (SUCCEEDED(hr)) - { - hr = GetValues(pszObjectID, pKeys, &pValues); - if (hr == S_FALSE) - { - hr = S_OK; - } - - // Some objects supported by this driver don't support WPD_OBJECT_ORIGINAL_FILE_NAME - // (e.g. functional objects) so remove it if there was an error reading it. - if (SUCCEEDED(hr)) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - - hr = pValues->GetValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &pv); - CHECK_HR(hr, "Failed to get WPD_OBJECT_ORIGINAL_FILE_NAME"); - - if(SUCCEEDED(hr)) - { - if(pv.vt == VT_ERROR) - { - hr = pValues->RemoveValue(WPD_OBJECT_ORIGINAL_FILE_NAME); - CHECK_HR(hr, "Failed to remove WPD_OBJECT_ORIGINAL_FILE_NAME"); - } - } - - PropVariantClear(&pv); - - // None of the above is fatal - hr = S_OK; - } - - // Add the WPD_EVENT_PARAMETER_OBJECT_PARENT_PERSISTENT_UNIQUE_ID - if (SUCCEEDED(hr)) - { - CAtlStringW strDevice = WPD_DEVICE_OBJECT_ID; - // If this is the device object, set the parent's persistent unique ID to to the empty string since it has no parent. - // Esle, get the persistent unique ID from the parent. - if(strDevice.CompareNoCase(pszObjectID) == 0) - { - pValues->SetStringValue(WPD_EVENT_PARAMETER_OBJECT_PARENT_PERSISTENT_UNIQUE_ID, L""); - } - else - { - CComPtr<IPortableDeviceValues> pParentValues; - HRESULT hrTemp = S_OK; - LPWSTR pszParentID = NULL; - LPWSTR pszParentUID = NULL; - - hrTemp = pValues->GetStringValue(WPD_OBJECT_PARENT_ID, &pszParentID); - if (SUCCEEDED(hrTemp)) - { - hrTemp = GetValues(pszParentID, pKeys, &pParentValues); - if (SUCCEEDED(hrTemp)) - { - hrTemp = pParentValues->GetStringValue(WPD_OBJECT_PERSISTENT_UNIQUE_ID, &pszParentUID); - if (SUCCEEDED(hrTemp)) - { - pValues->SetStringValue(WPD_EVENT_PARAMETER_OBJECT_PARENT_PERSISTENT_UNIQUE_ID, pszParentUID); - CoTaskMemFree(pszParentUID); - } - CHECK_HR(hrTemp, "Failed to get parent unique id"); - } - CoTaskMemFree(pszParentID); - CHECK_HR(hrTemp, "Failed to get values for parent id"); - } - CHECK_HR(hrTemp, "Failed to get parent id"); - } - } - CHECK_HR(hr, "Failed to get properties to use in event information"); - } - - if (SUCCEEDED(hr)) - { - *ppValues = pValues.Detach(); - } - - return hr; - } - - - HRESULT CreateContentObject( - _In_ LPCWSTR pszObjectName, - _In_ LPCWSTR pszParentID, - _In_ REFGUID guidContentType, - _In_ IPortableDeviceValues* pObjectProperties, - _Outptr_result_nullonfailure_ FakeContent** ppContent) - { - HRESULT hr = S_OK; - HRESULT hrTemp = S_OK; - LPWSTR wszOriginalFileName = NULL; - - *ppContent = NULL; - - if(guidContentType == WPD_CONTENT_TYPE_FOLDER) - { - FakeContent* pContent = NULL; - - pContent = new FakeContent(); - if (pContent) - { - pContent->Name = pszObjectName; - pContent->ParentID = pszParentID; - m_dwLastObjectID++; - pContent->ObjectID.Format(L"%d", m_dwLastObjectID); - pContent->ContentType = guidContentType; - pContent->FileName = pszObjectName; - pContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pContent->ObjectID.GetString()); - - BOOL bTemp = FALSE; - // Get next optional property WPD_OBJECT_CAN_DELETE - hrTemp = pObjectProperties->GetBoolValue(WPD_OBJECT_CAN_DELETE, &bTemp); - if(hrTemp == S_OK) - { - pContent->CanDelete = bTemp; - } - // Get next optional property WPD_OBJECT_ISHIDDEN - hrTemp = pObjectProperties->GetBoolValue(WPD_OBJECT_ISHIDDEN, &bTemp); - if(hrTemp == S_OK) - { - pContent->IsHidden = bTemp; - } - // Get next optional property WPD_OBJECT_NON_CONSUMABLE - hrTemp = pObjectProperties->GetBoolValue(WPD_OBJECT_NON_CONSUMABLE, &bTemp); - if(hrTemp == S_OK) - { - pContent->NonConsumable = bTemp; - } - - *ppContent = pContent; - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new FakeContent object"); - } - } - else if(guidContentType == WPD_CONTENT_TYPE_CONTACT) - { - FakeContactContent* pContent = NULL; - - pContent = new FakeContactContent(); - if (pContent) - { - pContent->Name = pszObjectName; - pContent->ParentID = pszParentID; - m_dwLastObjectID++; - pContent->ObjectID.Format(L"%d", m_dwLastObjectID); - pContent->ContentType = guidContentType; - pContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pContent->ObjectID.GetString()); - - // Get the other contact properties. - LPWSTR pszTempString = NULL; - - hr = pObjectProperties->GetStringValue(WPD_CONTACT_DISPLAY_NAME, &pszTempString); - CHECK_HR(hr, "Failed to get required contact property: WPD_CONTACT_DISPLAY_NAME"); - if (SUCCEEDED(hr)) - { - pContent->DisplayName = pszTempString; - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszTempString); - - // Get next optional property WPD_CONTACT_PRIMARY_PHONE - hrTemp = pObjectProperties->GetStringValue(WPD_CONTACT_PRIMARY_PHONE, &pszTempString); - if(hrTemp == S_OK) - { - pContent->PrimaryPhone = pszTempString; - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszTempString); - } - - // Get next optional property WPD_CONTACT_MOBILE_PHONE - hrTemp = pObjectProperties->GetStringValue(WPD_CONTACT_MOBILE_PHONE, &pszTempString); - if(hrTemp == S_OK) - { - pContent->CellPhone = pszTempString; - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszTempString); - } - - // Get next optional property WPD_CONTACT_BUSINESS_PHONE - hrTemp = pObjectProperties->GetStringValue(WPD_CONTACT_BUSINESS_PHONE, &pszTempString); - if(hrTemp == S_OK) - { - pContent->WorkPhone = pszTempString; - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszTempString); - } - - // Get next optional property WPD_OBJECT_ORIGINAL_FILE_NAME - hrTemp = pObjectProperties->GetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &pszTempString); - if(hrTemp == S_OK) - { - pContent->FileName = pszTempString; - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszTempString); - } - - *ppContent = pContent; - } - else - { - delete pContent; - } - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new FakeContactContent object"); - } - } - else if(guidContentType == WPD_CONTENT_TYPE_AUDIO) - { - FakeMusicContent* pContent = NULL; - - pContent = new FakeMusicContent(); - if (pContent) - { - pContent->Name = pszObjectName; - pContent->ParentID = pszParentID; - m_dwLastObjectID++; - pContent->ObjectID.Format(L"%d", m_dwLastObjectID); - pContent->ContentType = guidContentType; - pContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pContent->ObjectID.GetString()); - - hrTemp = pObjectProperties->GetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &wszOriginalFileName); - if (hrTemp == S_OK) - { - pContent->FileName = wszOriginalFileName; - } - - *ppContent = pContent; - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new FakeMusicContent object"); - } - } - else if(guidContentType == WPD_CONTENT_TYPE_VIDEO) - { - FakeVideoContent* pContent = NULL; - - pContent = new FakeVideoContent(); - if (pContent) - { - pContent->Name = pszObjectName; - pContent->ParentID = pszParentID; - m_dwLastObjectID++; - pContent->ObjectID.Format(L"%d", m_dwLastObjectID); - pContent->ContentType = guidContentType; - pContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pContent->ObjectID.GetString()); - - hrTemp = pObjectProperties->GetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &wszOriginalFileName); - if (hrTemp == S_OK) - { - pContent->FileName = wszOriginalFileName; - } - - *ppContent = pContent; - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new FakeVideoContent object"); - } - } - else if(guidContentType == WPD_CONTENT_TYPE_IMAGE) - { - FakeImageContent* pContent = NULL; - - pContent = new FakeImageContent(); - if (pContent) - { - pContent->Name = pszObjectName; - pContent->ParentID = pszParentID; - m_dwLastObjectID++; - pContent->ObjectID.Format(L"%d", m_dwLastObjectID); - pContent->ContentType = guidContentType; - pContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pContent->ObjectID.GetString()); - - hrTemp = pObjectProperties->GetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &wszOriginalFileName); - if (hrTemp == S_OK) - { - pContent->FileName = wszOriginalFileName; - } - - *ppContent = pContent; - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new FakeImageContent object"); - } - } - else if(guidContentType == WPD_CONTENT_TYPE_NETWORK_ASSOCIATION) - { - FakeNetworkAssociationContent* pContent = NULL; - - pContent = new FakeNetworkAssociationContent(); - if (pContent) - { - BYTE *pValue = NULL; - DWORD cbValue = 0; - - pContent->Name = pszObjectName; - pContent->ParentID = pszParentID; - m_dwLastObjectID++; - pContent->ObjectID.Format(L"%d", m_dwLastObjectID); - pContent->ContentType = guidContentType; - pContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pContent->ObjectID.GetString()); - - // Get required property WPD_NETWORK_ASSOCIATION_HOST_NETWORK_IDENTIFIERS - hr = pObjectProperties->GetBufferValue(WPD_NETWORK_ASSOCIATION_HOST_NETWORK_IDENTIFIERS, &pValue, &cbValue); - if (SUCCEEDED(hr)) - { - // Make sure the HostEUI64Array is the correct length - if ((cbValue % 8) == 0) - { - // Avoid copy by manually updating the PROPVARIANT - pContent->HostEUI64Array.vt = VT_VECTOR | VT_UI1; - pContent->HostEUI64Array.caub.cElems = cbValue; - pContent->HostEUI64Array.caub.pElems = pValue; - } - else - { - CoTaskMemFree(pValue); - pValue = NULL; - - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid value for HostEUI64Array"); - } - } - - if (SUCCEEDED(hr)) - { - *ppContent = pContent; - } - else - { - delete pContent; - } - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new FakeNetworkAssociationContent object"); - } - } - else if(guidContentType == WPD_CONTENT_TYPE_WIRELESS_PROFILE) - { - FakeWirelessProfileContent* pContent = NULL; - - pContent = new FakeWirelessProfileContent(); - if (pContent) - { - pContent->Name = pszObjectName; - pContent->ParentID = pszParentID; - m_dwLastObjectID++; - pContent->ObjectID.Format(L"%d", m_dwLastObjectID); - pContent->ContentType = guidContentType; - pContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pContent->ObjectID.GetString()); - - hrTemp = pObjectProperties->GetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &wszOriginalFileName); - if (hrTemp == S_OK) - { - pContent->FileName = wszOriginalFileName; - } - - *ppContent = pContent; - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new FakeWirelessProfileContent object"); - } - } - else - { - FakeContent* pContent; - - // Add generic file object - pContent = new FakeGenericFileContent(); - if (pContent) - { - pContent->Name = pszObjectName; - pContent->ParentID = pszParentID; - m_dwLastObjectID++; - pContent->ObjectID.Format(L"%d", m_dwLastObjectID); - pContent->ContentType = guidContentType; - pContent->PersistentUniqueID.Format(L"PersistentUniqueID_%ws", pContent->ObjectID.GetString()); - - BOOL bTemp = FALSE; - // Get next optional property WPD_OBJECT_CAN_DELETE - hrTemp = pObjectProperties->GetBoolValue(WPD_OBJECT_CAN_DELETE, &bTemp); - if(hrTemp == S_OK) - { - pContent->CanDelete = bTemp; - } - // Get next optional property WPD_OBJECT_ISHIDDEN - hrTemp = pObjectProperties->GetBoolValue(WPD_OBJECT_ISHIDDEN, &bTemp); - if(hrTemp == S_OK) - { - pContent->IsHidden = bTemp; - } - // Get next optional property WPD_OBJECT_NON_CONSUMABLE - hrTemp = pObjectProperties->GetBoolValue(WPD_OBJECT_NON_CONSUMABLE, &bTemp); - if(hrTemp == S_OK) - { - pContent->NonConsumable = bTemp; - } - - hrTemp = pObjectProperties->GetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &wszOriginalFileName); - if (hrTemp == S_OK) - { - pContent->FileName = wszOriginalFileName; - } - - *ppContent = pContent; - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new FakeContent object"); - } - } - - if (wszOriginalFileName != NULL) - { - CoTaskMemFree(wszOriginalFileName); - wszOriginalFileName = NULL; - } - - return hr; - } - - HRESULT GetContentFormat( - _In_ LPCWSTR pszObjectID, - _Out_ GUID& guidObjectFormat) - { - HRESULT hr = S_OK; - FakeContent* pContent = NULL; - guidObjectFormat = GUID_NULL; - - if (GetContent(pszObjectID, &pContent) == true) - { - guidObjectFormat = pContent->GetObjectFormat(); - } - else - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); - } - - return hr; - } - - HRESULT EnableResource( - _In_ LPCWSTR pszObjectID, - _In_ REFPROPERTYKEY ResourceKey) - { - HRESULT hr = S_OK; - FakeContent* pContent = NULL; - - if (GetContent(pszObjectID, &pContent) == true) - { - hr = pContent->EnableResource(ResourceKey); - } - else - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); - } - - return hr; - } - - HRESULT CopyChildrenToNewParent( - _In_ LPCWSTR pszParentObjectID, - _In_ LPCWSTR pszNewParentObjectID) - { - HRESULT hr = S_OK; - - CAtlStringW strParentObjectID = pszParentObjectID; - for (size_t Index = 0; Index < m_Content.GetCount(); Index++) - { - if (m_Content[Index]->ParentID == strParentObjectID) - { - LPWSTR pwszNewObjectID = NULL; - // Copy this object - hr = CopyObject(m_Content[Index]->ObjectID, pszNewParentObjectID, &pwszNewObjectID); - - // Free allocate new object ID - if (pwszNewObjectID != NULL) - { - CoTaskMemFree(pwszNewObjectID); - pwszNewObjectID = NULL; - } - - if (FAILED(hr)) - { - break; - } - } - } - return hr; - } - - HRESULT SupportsResource( - _In_ LPCWSTR pszObjectID, - _In_ REFPROPERTYKEY ResourceKey, - _Out_ BOOL* pbSupportsResource) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if((pszObjectID == NULL) || (pbSupportsResource == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *pbSupportsResource = FALSE; - hr = GetSupportedResources(pszObjectID, &pKeys); - CHECK_HR(hr, "Failed to get supported resources for validation"); - - if (hr == S_OK) - { - DWORD dwIndex = 0; - PROPERTYKEY TempKey = WPD_PROPERTY_NULL; - while(pKeys->GetAt(dwIndex++, &TempKey) == S_OK) - { - if(IsEqualPropertyKey(ResourceKey, TempKey)) - { - *pbSupportsResource = TRUE; - } - } - } - - return hr; - } - - HRESULT UpdateContentObject( - _In_ LPCWSTR pszObjectID, - _In_ IPortableDeviceValues* pObjectProperties) - { - HRESULT hr = S_OK; - FakeContent* pElement = NULL; - - if (GetContent(pszObjectID, &pElement)) - { - HRESULT hrTemp = S_OK; - LPWSTR wszOriginalFileName = NULL; - LPWSTR wszObjectName = NULL; - - // Update selected properties; other properties will be discarded. - hrTemp = pObjectProperties->GetStringValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &wszOriginalFileName); - if(hrTemp == S_OK) - { - pElement->FileName = wszOriginalFileName; - CoTaskMemFree(wszOriginalFileName); - } - - hrTemp = pObjectProperties->GetStringValue(WPD_OBJECT_NAME, &wszObjectName); - if(hrTemp == S_OK) - { - pElement->Name = wszObjectName; - CoTaskMemFree(wszObjectName); - } - - // Note: This fake driver does nothing with the data. The WriteData method is simply - // a dummy one, and the data size is a constant. - // Normally, a driver would also update the WPD_OBJECT_SIZE to the new data size. - } - else - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); - CHECK_HR(hr, "Failed to find the object '%ws'", pszObjectID); - } - - return hr; - } - -private: - CAtlArray<FakeContent*> m_Content; - DWORD m_dwLastObjectID; -}; - - diff --git a/wpd/WpdWudfSampleDriver/FakeFolderContent.h b/wpd/WpdWudfSampleDriver/FakeFolderContent.h deleted file mode 100644 index 1241a650..00000000 --- a/wpd/WpdWudfSampleDriver/FakeFolderContent.h +++ /dev/null @@ -1,234 +0,0 @@ -#include "mmsystem.h" -#include "FakeFolderContent.h.tmh" - -class FakeFolderContent : public FakeContent -{ -public: - FakeFolderContent() - { - } - - FakeFolderContent(const FakeContent& src) - { - *this = src; - } - - virtual ~FakeFolderContent() - { - } - - - virtual HRESULT GetAllValues( - _In_ IPortableDeviceValues* pStore) - { - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Call the base class to fill in the standard properties - hr = FakeContent::GetAllValues(pStore); - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get basic property set"); - return hr; - } - - // Add WPD_OBJECT_ORIGINAL_FILE_NAME - pvValue = FileName; - hr = pStore->SetValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &pvValue); - if (hr != S_OK) - { - CHECK_HR(hr, ("Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME")); - return hr; - } - - return hr; - } - -}; - - -class FakeMemoFolderContent : public FakeFolderContent -{ -public: - FakeMemoFolderContent() - { - } - - FakeMemoFolderContent(const FakeContent& src) - { - *this = src; - } - - virtual ~FakeMemoFolderContent() - { - } - - virtual HRESULT GetSupportedResources(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - // Call the base class to fill in the standard resources if any - hr = FakeContent::GetSupportedResources(&pKeys); - CHECK_HR(hr, "Failed to get basic supported resources"); - } - - if (SUCCEEDED(hr)) - { - // Add WPD_RESOURCE_ICON - hr = pKeys->Add(WPD_RESOURCE_ICON); - CHECK_HR(hr, "Failed to add WPD_RESOURCE_ICON to collection"); - } - - if (SUCCEEDED(hr)) - { - hr = pKeys->QueryInterface(IID_IPortableDeviceKeyCollection, (VOID**) ppKeys); - CHECK_HR(hr, "Failed to QI for IPortableDeviceKeyCollection on IPortableDeviceKeyCollection"); - } - - return hr; - } - - virtual HRESULT GetResourceAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pAttributes; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if (IsEqualPropertyKey(Key, WPD_RESOURCE_ICON)) - { - // Fill in the common resource attributes - hr = GetCommonResourceAttributes(&pAttributes); - CHECK_HR(hr, "Failed to get common resource attributes set"); - - // Override the size attribute for this resource. - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE, GetResourceSize(IDR_WPD_SAMPLEDRIVER_MEMO_FOLDER_ICON)); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE"); - } - - // Override the format attribute for this resource. - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetGuidValue(WPD_RESOURCE_ATTRIBUTE_FORMAT, WPD_OBJECT_FORMAT_ICON); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_FORMAT"); - } - - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Object does not support this resource"); - } - - // Return the resource attributes - if (SUCCEEDED(hr)) - { - hr = pAttributes->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppAttributes); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on Wpd IPortableDeviceValues"); - } - - return hr; - } - - // This sample driver uses a embedded icon resource as its data. - virtual HRESULT ReadData( - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) - { - HRESULT hr = S_OK; - DWORD dwBytesToTransfer = 0; - DWORD dwObjectDataSize = 0; - PBYTE pResource = NULL; - - if((pBuffer == NULL) || - (pdwNumBytesRead == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *pdwNumBytesRead = 0; - - if (IsEqualPropertyKey(ResourceKey, WPD_RESOURCE_ICON)) - { - pResource = GetResourceData(IDR_WPD_SAMPLEDRIVER_MEMO_FOLDER_ICON); - dwObjectDataSize = GetResourceSize(IDR_WPD_SAMPLEDRIVER_MEMO_FOLDER_ICON); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Object does not support this resource"); - } - - if (hr == S_OK) - { - if (pResource == NULL) - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Failed to get resource representing image data"); - } - - // Calculate how many bytes to transfer - if (hr == S_OK) - { - if (dwStartByte < dwObjectDataSize) - { - dwBytesToTransfer = (dwObjectDataSize - dwStartByte); - if (dwBytesToTransfer > dwNumBytesToRead) - { - dwBytesToTransfer = dwNumBytesToRead; - } - } - } - - // Copy the embedded data. - if ((hr == S_OK) && (dwBytesToTransfer > 0)) - { - memcpy(pBuffer, pResource + dwStartByte, dwBytesToTransfer); - } - - if (hr == S_OK) - { - *pdwNumBytesRead = dwBytesToTransfer; - } - } - - return hr; - } - -}; - diff --git a/wpd/WpdWudfSampleDriver/FakeImageContent.h b/wpd/WpdWudfSampleDriver/FakeImageContent.h deleted file mode 100644 index 64a6f02d..00000000 --- a/wpd/WpdWudfSampleDriver/FakeImageContent.h +++ /dev/null @@ -1,402 +0,0 @@ -#include "mmsystem.h" -#include "FakeImageContent.h.tmh" - -class FakeImageContent : public FakeContent -{ -public: - FakeImageContent() - { - } - - FakeImageContent(const FakeContent& src) - { - *this = src; - } - - virtual ~FakeImageContent() - { - } - - virtual HRESULT GetSupportedProperties(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - hr = AddSupportedProperties(WPD_OBJECT_FORMAT_EXIF, ppKeys); - CHECK_HR(hr, "Failed to add additional properties for WPD_OBJECT_FORMAT_EXIF"); - } - - return hr; - } - - virtual HRESULT GetAllValues( - _In_ IPortableDeviceValues* pStore) - { - HRESULT hr = S_OK; - HRESULT hrSetValue = S_OK; - PropVariantWrapper pvValue; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Call the base class to fill in the standard properties - hr = FakeContent::GetAllValues(pStore); - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get basic property set"); - return hr; - } - - // Add WPD_MEDIA_WIDTH - hrSetValue = pStore->SetUnsignedIntegerValue(WPD_MEDIA_WIDTH, 800); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_MEDIA_WIDTH")); - return hrSetValue; - } - - // Add WPD_MEDIA_HEIGHT - hrSetValue = pStore->SetUnsignedIntegerValue(WPD_MEDIA_HEIGHT, 600); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_MEDIA_HEIGHT")); - return hrSetValue; - } - - // Add WPD_OBJECT_DATE_CREATED - SYSTEMTIME systemtime = {0}; - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - pv.vt = VT_DATE; - systemtime.wDay = 26; - systemtime.wDayOfWeek = 0; - systemtime.wHour = 5; - systemtime.wMinute = 30; - systemtime.wMilliseconds = 100; - systemtime.wMonth = 6; - systemtime.wSecond = 15; - systemtime.wYear = 2004; - - SystemTimeToVariantTime(&systemtime, &pv.date); - - hrSetValue = pStore->SetValue(WPD_OBJECT_DATE_CREATED , &pv); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_DATE_CREATED")); - return hrSetValue; - } - - PropVariantClear(&pv); - - // Add WPD_OBJECT_ORIGINAL_FILE_NAME - pvValue = FileName; - hrSetValue = pStore->SetValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &pvValue); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME")); - return hrSetValue; - } - - // Add WPD_OBJECT_SIZE - hrSetValue = pStore->SetUnsignedLargeIntegerValue(WPD_OBJECT_SIZE, GetResourceSize(IDR_WPD_SAMPLEDRIVER_IMAGE)); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_SIZE")); - return hrSetValue; - } - - return hr; - } - - virtual HRESULT WriteValue( - _In_ REFPROPERTYKEY key, - _In_ REFPROPVARIANT Value) - { - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(IsEqualPropertyKey(key, WPD_OBJECT_ORIGINAL_FILE_NAME)) - { - if(Value.vt == VT_LPWSTR) - { - if (Value.pwszVal != NULL && Value.pwszVal[0] != L'\0') - { - FileName = Value.pwszVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME because value was an empty string"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME because type was not VT_LPWSTR"); - } - } - else - { - hr = FakeContent::WriteValue(key, Value); - CHECK_HR(hr, "Property %ws.%d on [%ws] does not support set value operation", CComBSTR(key.fmtid), key.pid, ObjectID); - } - - return hr; - } - - virtual HRESULT GetSupportedResources(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - // Call the base class to fill in the standard resources if any - hr = FakeContent::GetSupportedResources(&pKeys); - CHECK_HR(hr, "Failed to get basic supported resources"); - } - - if (SUCCEEDED(hr)) - { - // Add WPD_RESOURCE_DEFAULT - hr = pKeys->Add(WPD_RESOURCE_DEFAULT); - CHECK_HR(hr, "Failed to add WPD_RESOURCE_DEFAULT to collection"); - } - - if (SUCCEEDED(hr)) - { - // Add the thumbnail resource - hr = pKeys->Add(WPD_RESOURCE_THUMBNAIL); - CHECK_HR(hr, "Failed to add WPD_RESOURCE_THUMBNAIL to supported resource list"); - } - - if (SUCCEEDED(hr)) - { - // Add the audio annotation resource - hr = pKeys->Add(WPD_RESOURCE_AUDIO_CLIP); - CHECK_HR(hr, "Failed to add WPD_RESOURCE_AUDIO_CLIP to supported resource list"); - } - - if (SUCCEEDED(hr)) - { - hr = pKeys->QueryInterface(IID_IPortableDeviceKeyCollection, (VOID**) ppKeys); - CHECK_HR(hr, "Failed to QI for IPortableDeviceKeyCollection on IPortableDeviceKeyCollection"); - } - - return hr; - } - - virtual HRESULT GetResourceAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pAttributes; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if (SUCCEEDED(hr)) - { - // Fill in the common resource attributes - hr = GetCommonResourceAttributes(&pAttributes); - CHECK_HR(hr, "Failed to get common resource attributes set"); - } - - // Override the size attribute for this resource. - if (SUCCEEDED(hr)) - { - DWORD dwSize = 0; - if (IsEqualPropertyKey(Key, WPD_RESOURCE_DEFAULT)) - { - dwSize = GetResourceSize(IDR_WPD_SAMPLEDRIVER_IMAGE); - } - else if(IsEqualPropertyKey(Key, WPD_RESOURCE_THUMBNAIL)) - { - dwSize = GetResourceSize(IDR_WPD_SAMPLEDRIVER_IMAGE_THUMBNAIL); - } - else if(IsEqualPropertyKey(Key, WPD_RESOURCE_AUDIO_CLIP)) - { - dwSize = GetResourceSize(IDR_WPD_SAMPLEDRIVER_AUDIO_ANNOTATION); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Could not return resource attributes for unknown resource %ws.%d", (LPWSTR)CComBSTR(Key.fmtid), Key.pid); - } - - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE, dwSize); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE"); - } - } - - if (SUCCEEDED(hr) && (IsEqualPropertyKey(Key, WPD_RESOURCE_THUMBNAIL))) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_MEDIA_WIDTH, 96); - CHECK_HR(hr, "Failed to set WPD_MEDIA_WIDTH"); - - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_MEDIA_HEIGHT, 96); - CHECK_HR(hr, "Failed to set WPD_MEDIA_HEIGHT"); - } - - // Override the format attribute for this resource. - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetGuidValue(WPD_RESOURCE_ATTRIBUTE_FORMAT, WPD_OBJECT_FORMAT_EXIF); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_FORMAT"); - } - } - - if (SUCCEEDED(hr) && (IsEqualPropertyKey(Key, WPD_RESOURCE_AUDIO_CLIP))) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_AUDIO_BITRATE, 180224 /* 176kbps */); - CHECK_HR(hr, "Failed to set WPD_AUDIO_BITRATE"); - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetFloatValue(WPD_AUDIO_CHANNEL_COUNT, 1.0f /* Mono */); - CHECK_HR(hr, "Failed to set WPD_AUDIO_CHANNEL_COUNT"); - } - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_AUDIO_FORMAT_CODE, WAVE_FORMAT_PCM); - CHECK_HR(hr, "Failed to set WPD_AUDIO_FORMAT_CODE"); - } - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_MEDIA_SAMPLE_RATE, 22000 /* 22kHz */); - CHECK_HR(hr, "Failed to set WPD_MEDIA_SAMPLE_RATE"); - } - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_AUDIO_BIT_DEPTH, 8); - CHECK_HR(hr, "Failed to set WPD_AUDIO_BIT_DEPTH"); - } - - // Override the format attribute for this resource. - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetGuidValue(WPD_RESOURCE_ATTRIBUTE_FORMAT, WPD_OBJECT_FORMAT_WAVE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_FORMAT"); - } - } - - // Return the resource attributes - if (SUCCEEDED(hr)) - { - hr = pAttributes->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppAttributes); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on Wpd IPortableDeviceValues"); - } - return hr; - } - - // This sample driver uses a embedded image file resource as its data. - virtual HRESULT ReadData( - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) - { - HRESULT hr = S_OK; - DWORD dwBytesToTransfer = 0; - DWORD dwObjectDataSize = 0; - PBYTE pResource = NULL; - - if((pBuffer == NULL) || - (pdwNumBytesRead == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *pdwNumBytesRead = 0; - - if (IsEqualPropertyKey(ResourceKey, WPD_RESOURCE_DEFAULT)) - { - pResource = GetResourceData(IDR_WPD_SAMPLEDRIVER_IMAGE); - dwObjectDataSize = GetResourceSize(IDR_WPD_SAMPLEDRIVER_IMAGE); - } - else if(IsEqualPropertyKey(ResourceKey, WPD_RESOURCE_THUMBNAIL)) - { - pResource = GetResourceData(IDR_WPD_SAMPLEDRIVER_IMAGE_THUMBNAIL); - dwObjectDataSize = GetResourceSize(IDR_WPD_SAMPLEDRIVER_IMAGE_THUMBNAIL); - } - else if(IsEqualPropertyKey(ResourceKey, WPD_RESOURCE_AUDIO_CLIP)) - { - pResource = GetResourceData(IDR_WPD_SAMPLEDRIVER_AUDIO_ANNOTATION); - dwObjectDataSize = GetResourceSize(IDR_WPD_SAMPLEDRIVER_AUDIO_ANNOTATION); - } - - if (pResource == NULL) - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Failed to get DLL resource representing WPD resource data"); - } - - // Calculate how many bytes to transfer - if (hr == S_OK) - { - if (dwStartByte < dwObjectDataSize) - { - dwBytesToTransfer = (dwObjectDataSize - dwStartByte); - if (dwBytesToTransfer > dwNumBytesToRead) - { - dwBytesToTransfer = dwNumBytesToRead; - } - } - } - - // Copy the embedded image file data. - if ((hr == S_OK) && (dwBytesToTransfer > 0)) - { - memcpy(pBuffer, pResource + dwStartByte, dwBytesToTransfer); - } - - if (hr == S_OK) - { - *pdwNumBytesRead = dwBytesToTransfer; - } - - return hr; - } - - virtual GUID GetObjectFormat() - { - return WPD_OBJECT_FORMAT_EXIF; - } -}; - diff --git a/wpd/WpdWudfSampleDriver/FakeMemoContent.h b/wpd/WpdWudfSampleDriver/FakeMemoContent.h deleted file mode 100644 index a726336c..00000000 --- a/wpd/WpdWudfSampleDriver/FakeMemoContent.h +++ /dev/null @@ -1,347 +0,0 @@ -#include "FakeMemoContent.h.tmh" - -class FakeMemoContent : public FakeContent -{ -public: - FakeMemoContent() - { - } - - FakeMemoContent(const FakeMemoContent& src) - { - *this = src; - } - - virtual ~FakeMemoContent() - { - } - - virtual HRESULT GetSupportedProperties(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (hr == S_OK) - { - hr = AddSupportedProperties(FakeMemoContent_Format, ppKeys); - CHECK_HR(hr, "Failed to add additional properties for FakeMemoContent"); - } - - return hr; - } - - virtual HRESULT GetAllValues( - _In_ IPortableDeviceValues* pStore) - { - HRESULT hr = S_OK; - HRESULT hrSetValue = S_OK; - CAtlStringW strVal; - PropVariantWrapper pvValue; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Call the base class to fill in the standard properties - hr = FakeContent::GetAllValues(pStore); - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get basic property set"); - return hr; - } - - // Add WPD_OBJECT_SIZE - hrSetValue = pStore->SetUnsignedLargeIntegerValue(WPD_OBJECT_SIZE, GetResourceSize(IDR_WPD_SAMPLEDRIVER_MEMO)); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_SIZE")); - return hrSetValue; - } - - // Add WPD_OBJECT_DATE_AUTHORED and WPD_OBJECT_DATE_MODIFIED - SYSTEMTIME systemtime = {0}; - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - pv.vt = VT_DATE; - systemtime.wDay = 26; - systemtime.wDayOfWeek = 0; - systemtime.wHour = 5; - systemtime.wMinute = 30; - systemtime.wMilliseconds = 100; - systemtime.wMonth = 6; - systemtime.wSecond = 15; - systemtime.wYear = 2004; - - SystemTimeToVariantTime(&systemtime, &pv.date); - - hrSetValue = pStore->SetValue(WPD_OBJECT_DATE_AUTHORED , &pv); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_DATE_AUTHORED ")); - return hrSetValue; - } - hrSetValue = pStore->SetValue(WPD_OBJECT_DATE_MODIFIED , &pv); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_DATE_MODIFIED ")); - return hrSetValue; - } - - PropVariantClear(&pv); - - // Add WPD_OBJECT_ORIGINAL_FILE_NAME - pvValue = FileName; - hrSetValue = pStore->SetValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &pvValue); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME")); - return hrSetValue; - } - - return hr; - } - - virtual HRESULT WriteValue( - _In_ REFPROPERTYKEY key, - _In_ REFPROPVARIANT Value) - { - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(IsEqualPropertyKey(key, WPD_OBJECT_ORIGINAL_FILE_NAME)) - { - if(Value.vt == VT_LPWSTR) - { - if (Value.pwszVal != NULL && Value.pwszVal[0] != L'\0') - { - FileName = Value.pwszVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME because value was an empty string"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME because type was not VT_LPWSTR"); - } - } - else - { - hr = FakeContent::WriteValue(key, Value); - CHECK_HR(hr, "Property %ws.%d on [%ws] does not support set value operation", CComBSTR(key.fmtid), key.pid, ObjectID); - } - - return hr; - } - - virtual HRESULT GetSupportedResources(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - // Call the base class to fill in the standard resources if any - hr = FakeContent::GetSupportedResources(&pKeys); - CHECK_HR(hr, "Failed to get basic supported resources"); - } - - if (SUCCEEDED(hr)) - { - // Add WPD_RESOURCE_DEFAULT - hr = pKeys->Add(WPD_RESOURCE_DEFAULT); - CHECK_HR(hr, "Failed to add WPD_RESOURCE_DEFAULT to collection"); - } - - if (SUCCEEDED(hr)) - { - // Add WPD_RESOURCE_ICON - hr = pKeys->Add(WPD_RESOURCE_ICON); - CHECK_HR(hr, "Failed to add WPD_RESOURCE_ICON to collection"); - } - - if (SUCCEEDED(hr)) - { - hr = pKeys->QueryInterface(IID_IPortableDeviceKeyCollection, (VOID**) ppKeys); - CHECK_HR(hr, "Failed to QI for IPortableDeviceKeyCollection on IPortableDeviceKeyCollection"); - } - - return hr; - } - - virtual HRESULT GetResourceAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pAttributes; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if (IsEqualPropertyKey(Key, WPD_RESOURCE_ICON)) - { - // Fill in the common resource attributes - hr = GetCommonResourceAttributes(&pAttributes); - CHECK_HR(hr, "Failed to get common resource attributes set"); - - // Override the size attribute for this resource. - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE, GetResourceSize(IDR_WPD_SAMPLEDRIVER_MEMO_ICON)); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE"); - } - - // Override the format attribute for this resource. - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetGuidValue(WPD_RESOURCE_ATTRIBUTE_FORMAT, WPD_OBJECT_FORMAT_ICON); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_FORMAT"); - } - - } - else if (IsEqualPropertyKey(Key, WPD_RESOURCE_DEFAULT)) - { - // Fill in the common resource attributes - hr = GetCommonResourceAttributes(&pAttributes); - CHECK_HR(hr, "Failed to get common resource attributes set"); - - // Override the size attribute for this resource. - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE, GetResourceSize(IDR_WPD_SAMPLEDRIVER_MEMO)); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE"); - } - - // Override the format attribute for this resource. - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetGuidValue(WPD_RESOURCE_ATTRIBUTE_FORMAT, FakeMemoContent_Format); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_FORMAT"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Object does not support this resource"); - } - - // Return the resource attributes - if (SUCCEEDED(hr)) - { - hr = pAttributes->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppAttributes); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on Wpd IPortableDeviceValues"); - } - - return hr; - } - - // This sample driver uses a embedded resources as its data. - virtual HRESULT ReadData( - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) - { - HRESULT hr = S_OK; - DWORD dwBytesToTransfer = 0; - DWORD dwObjectDataSize = 0; - PBYTE pResource = NULL; - - if((pBuffer == NULL) || - (pdwNumBytesRead == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *pdwNumBytesRead = 0; - - if (IsEqualPropertyKey(ResourceKey, WPD_RESOURCE_ICON)) - { - pResource = GetResourceData(IDR_WPD_SAMPLEDRIVER_MEMO_ICON); - dwObjectDataSize = GetResourceSize(IDR_WPD_SAMPLEDRIVER_MEMO_ICON); - } - else if (IsEqualPropertyKey(ResourceKey, WPD_RESOURCE_DEFAULT)) - { - pResource = GetResourceData(IDR_WPD_SAMPLEDRIVER_MEMO); - dwObjectDataSize = GetResourceSize(IDR_WPD_SAMPLEDRIVER_MEMO); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Object does not support this resource"); - } - - if (hr == S_OK) - { - if (pResource == NULL) - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Failed to get resource representing image data"); - } - - // Calculate how many bytes to transfer - if (hr == S_OK) - { - if (dwStartByte < dwObjectDataSize) - { - dwBytesToTransfer = (dwObjectDataSize - dwStartByte); - if (dwBytesToTransfer > dwNumBytesToRead) - { - dwBytesToTransfer = dwNumBytesToRead; - } - } - } - - // Copy the embedded data. - if ((hr == S_OK) && (dwBytesToTransfer > 0)) - { - memcpy(pBuffer, pResource + dwStartByte, dwBytesToTransfer); - } - - if (hr == S_OK) - { - *pdwNumBytesRead = dwBytesToTransfer; - } - } - - return hr; - } - - virtual GUID GetObjectFormat() - { - return FakeMemoContent_Format; - } -}; diff --git a/wpd/WpdWudfSampleDriver/FakeMusicContent.h b/wpd/WpdWudfSampleDriver/FakeMusicContent.h deleted file mode 100644 index 846a2f84..00000000 --- a/wpd/WpdWudfSampleDriver/FakeMusicContent.h +++ /dev/null @@ -1,354 +0,0 @@ -#include "FakeMusicContent.h.tmh" - -class FakeMusicContent : public FakeContent -{ -public: - FakeMusicContent() - { - } - - FakeMusicContent(const FakeMusicContent& src) - { - *this = src; - } - - virtual ~FakeMusicContent() - { - } - - virtual HRESULT GetSupportedProperties(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - hr = AddSupportedProperties(WPD_OBJECT_FORMAT_WMA, ppKeys); - CHECK_HR(hr, "Failed to add additional properties for FakeMusicContent"); - } - - return hr; - } - - virtual HRESULT GetAllValues( - _In_ IPortableDeviceValues* pStore) - { - HRESULT hr = S_OK; - HRESULT hrSetValue = S_OK; - CAtlStringW strVal; - PropVariantWrapper pvValue; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Call the base class to fill in the standard properties - hr = FakeContent::GetAllValues(pStore); - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get basic property set"); - return hr; - } - - // Add WPD_MEDIA_TITLE - strVal.Format(L"Song_%ws", ObjectID.GetString()); - hrSetValue = pStore->SetStringValue(WPD_MEDIA_TITLE, strVal.GetString()); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_MEDIA_TITLE")); - return hrSetValue; - } - - // Add WPD_MEDIA_ARTIST - strVal.Format(L"Artist_%ws", ObjectID.GetString()); - hrSetValue = pStore->SetStringValue(WPD_MEDIA_ARTIST, strVal.GetString()); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_MEDIA_ARTIST")); - return hrSetValue; - } - - // Add WPD_MEDIA_DURATION - ULONGLONG ulDuration = 210000; - hrSetValue = pStore->SetUnsignedLargeIntegerValue(WPD_MEDIA_DURATION, ulDuration); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_MUSIC_DURATION")); - return hrSetValue; - } - - // Add WPD_OBJECT_SIZE - hrSetValue = pStore->SetUnsignedLargeIntegerValue(WPD_OBJECT_SIZE, GetResourceSize(IDR_WPD_SAMPLEDRIVER_MUSIC)); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_SIZE")); - return hrSetValue; - } - - // Add WPD_OBJECT_DATE_AUTHORED and WPD_OBJECT_DATE_MODIFIED - SYSTEMTIME systemtime = {0}; - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - pv.vt = VT_DATE; - systemtime.wDay = 26; - systemtime.wDayOfWeek = 0; - systemtime.wHour = 5; - systemtime.wMinute = 30; - systemtime.wMilliseconds = 100; - systemtime.wMonth = 6; - systemtime.wSecond = 15; - systemtime.wYear = 2004; - - SystemTimeToVariantTime(&systemtime, &pv.date); - - hrSetValue = pStore->SetValue(WPD_OBJECT_DATE_AUTHORED , &pv); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_DATE_AUTHORED ")); - return hrSetValue; - } - hrSetValue = pStore->SetValue(WPD_OBJECT_DATE_MODIFIED , &pv); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_DATE_MODIFIED ")); - return hrSetValue; - } - - PropVariantClear(&pv); - - // Add WPD_MUSIC_ALBUM - strVal.Format(L"Album_%ws", ObjectID.GetString()); - hrSetValue = pStore->SetStringValue(WPD_MUSIC_ALBUM, strVal.GetString()); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_MUSIC_ALBUM")); - return hrSetValue; - } - - // Add WPD_MEDIA_GENRE - hrSetValue = pStore->SetStringValue(WPD_MEDIA_GENRE, L"Top 40"); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_MEDIA_GENRE")); - return hrSetValue; - } - - // Add WPD_MUSIC_TRACK - hrSetValue = pStore->SetUnsignedIntegerValue(WPD_MUSIC_TRACK, 3); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_MUSIC_TRACK")); - return hrSetValue; - } - - // Add WPD_OBJECT_ORIGINAL_FILE_NAME - pvValue = FileName; - hrSetValue = pStore->SetValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &pvValue); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME")); - return hrSetValue; - } - - return hr; - } - - virtual HRESULT WriteValue( - _In_ REFPROPERTYKEY key, - _In_ REFPROPVARIANT Value) - { - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(IsEqualPropertyKey(key, WPD_OBJECT_ORIGINAL_FILE_NAME)) - { - if(Value.vt == VT_LPWSTR) - { - if (Value.pwszVal != NULL && Value.pwszVal[0] != L'\0') - { - FileName = Value.pwszVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME because value was an empty string"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME because type was not VT_LPWSTR"); - } - } - else - { - hr = FakeContent::WriteValue(key, Value); - CHECK_HR(hr, "Property %ws.%d on [%ws] does not support set value operation", CComBSTR(key.fmtid), key.pid, ObjectID); - } - - return hr; - } - - virtual HRESULT GetSupportedResources(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - // Call the base class to fill in the standard resources if any - hr = FakeContent::GetSupportedResources(&pKeys); - CHECK_HR(hr, "Failed to get basic supported resources"); - } - - if (SUCCEEDED(hr)) - { - // Add WPD_RESOURCE_DEFAULT - hr = pKeys->Add(WPD_RESOURCE_DEFAULT); - CHECK_HR(hr, "Failed to add WPD_RESOURCE_DEFAULT to collection"); - } - - if (SUCCEEDED(hr)) - { - hr = pKeys->QueryInterface(IID_IPortableDeviceKeyCollection, (VOID**) ppKeys); - CHECK_HR(hr, "Failed to QI for IPortableDeviceKeyCollection on IPortableDeviceKeyCollection"); - } - - return hr; - } - - virtual HRESULT GetResourceAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - UNREFERENCED_PARAMETER(Key); - - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pAttributes; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if (SUCCEEDED(hr)) - { - // Fill in the common resource attributes - hr = GetCommonResourceAttributes(&pAttributes); - CHECK_HR(hr, "Failed to get common resource attributes set"); - } - - // Override the size attribute for this resource. - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE, GetResourceSize(IDR_WPD_SAMPLEDRIVER_MUSIC)); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE"); - } - - // Override the format attribute for this resource. - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetGuidValue(WPD_RESOURCE_ATTRIBUTE_FORMAT, WPD_OBJECT_FORMAT_WMA); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_FORMAT"); - } - - // Return the resource attributes - if (SUCCEEDED(hr)) - { - hr = pAttributes->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppAttributes); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on Wpd IPortableDeviceValues"); - } - return hr; - } - - // This sample driver uses a embedded music file resource as its data. - virtual HRESULT ReadData( - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) - { - HRESULT hr = S_OK; - DWORD dwBytesToTransfer = 0; - DWORD dwObjectDataSize = 0; - PBYTE pResource = NULL; - - UNREFERENCED_PARAMETER(ResourceKey); - - if((pBuffer == NULL) || - (pdwNumBytesRead == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *pdwNumBytesRead = 0; - - pResource = GetResourceData(IDR_WPD_SAMPLEDRIVER_MUSIC); - dwObjectDataSize = GetResourceSize(IDR_WPD_SAMPLEDRIVER_MUSIC); - - if (pResource == NULL) - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Failed to get resource representing image data"); - } - - // Calculate how many bytes to transfer - if (hr == S_OK) - { - if (dwStartByte < dwObjectDataSize) - { - dwBytesToTransfer = (dwObjectDataSize - dwStartByte); - if (dwBytesToTransfer > dwNumBytesToRead) - { - dwBytesToTransfer = dwNumBytesToRead; - } - } - } - - // Copy the embedded music file data. - if ((hr == S_OK) && (dwBytesToTransfer > 0)) - { - memcpy(pBuffer, pResource + dwStartByte, dwBytesToTransfer); - } - - if (hr == S_OK) - { - *pdwNumBytesRead = dwBytesToTransfer; - } - - return hr; - } - - virtual GUID GetObjectFormat() - { - return WPD_OBJECT_FORMAT_WMA; - } -}; - diff --git a/wpd/WpdWudfSampleDriver/FakeVideoContent.h b/wpd/WpdWudfSampleDriver/FakeVideoContent.h deleted file mode 100644 index 1fa0d8a1..00000000 --- a/wpd/WpdWudfSampleDriver/FakeVideoContent.h +++ /dev/null @@ -1,368 +0,0 @@ -#include "FakeVideoContent.h.tmh" - -class FakeVideoContent : public FakeContent -{ -public: - FakeVideoContent() - { - } - - FakeVideoContent(const FakeVideoContent& src) - { - *this = src; - } - - virtual ~FakeVideoContent() - { - } - - virtual HRESULT GetSupportedProperties(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - hr = AddSupportedProperties(WPD_OBJECT_FORMAT_WMV, ppKeys); - CHECK_HR(hr, "Failed to add additional properties for FakeVideoContent"); - } - - return hr; - } - - virtual HRESULT GetAllValues( - _In_ IPortableDeviceValues* pStore) - { - HRESULT hr = S_OK; - HRESULT hrSetValue = S_OK; - CAtlStringW strVal; - PropVariantWrapper pvValue; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Call the base class to fill in the standard properties - hr = FakeContent::GetAllValues(pStore); - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get basic property set"); - return hr; - } - - // Add WPD_MEDIA_TITLE - strVal.Format(L"Video_%ws", ObjectID.GetString()); - hrSetValue = pStore->SetStringValue(WPD_MEDIA_TITLE, strVal.GetString()); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_MEDIA_TITLE")); - return hrSetValue; - } - - // Add WPD_MEDIA_DURATION - ULONGLONG ulDuration = 6000; - hrSetValue = pStore->SetUnsignedLargeIntegerValue(WPD_MEDIA_DURATION, ulDuration); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_MUSIC_DURATION")); - return hrSetValue; - } - - // Add WPD_OBJECT_SIZE - hrSetValue = pStore->SetUnsignedLargeIntegerValue(WPD_OBJECT_SIZE, GetResourceSize(IDR_WPD_SAMPLEDRIVER_VIDEO)); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_SIZE")); - return hrSetValue; - } - - // Add WPD_OBJECT_DATE_AUTHORED and WPD_OBJECT_DATE_MODIFIED - SYSTEMTIME systemtime = {0}; - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - pv.vt = VT_DATE; - systemtime.wDay = 27; - systemtime.wDayOfWeek = 1; - systemtime.wHour = 5; - systemtime.wMinute = 30; - systemtime.wMilliseconds = 100; - systemtime.wMonth = 6; - systemtime.wSecond = 15; - systemtime.wYear = 2004; - - SystemTimeToVariantTime(&systemtime, &pv.date); - - hrSetValue = pStore->SetValue(WPD_OBJECT_DATE_AUTHORED , &pv); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_DATE_AUTHORED ")); - return hrSetValue; - } - hrSetValue = pStore->SetValue(WPD_OBJECT_DATE_MODIFIED , &pv); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_DATE_MODIFIED ")); - return hrSetValue; - } - - PropVariantClear(&pv); - - // Add WPD_MEDIA_WIDTH - hrSetValue = pStore->SetUnsignedIntegerValue(WPD_MEDIA_WIDTH, 160); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_MEDIA_WIDTH")); - return hrSetValue; - } - - // Add WPD_MEDIA_HEIGHT - hrSetValue = pStore->SetUnsignedIntegerValue(WPD_MEDIA_HEIGHT, 120); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_MEDIA_HEIGHT")); - return hrSetValue; - } - - // Add WPD_OBJECT_ORIGINAL_FILE_NAME - pvValue = FileName; - hrSetValue = pStore->SetValue(WPD_OBJECT_ORIGINAL_FILE_NAME, &pvValue); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME")); - return hrSetValue; - } - - // Add WPD_VIDEO_SCAN_TYPE - hrSetValue = pStore->SetUnsignedIntegerValue(WPD_VIDEO_SCAN_TYPE, WPD_VIDEO_SCAN_TYPE_UNUSED); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_VIDEO_SCAN_TYPE")); - return hrSetValue; - } - - // Add WPD_VIDEO_BITRATE - hrSetValue = pStore->SetUnsignedIntegerValue(WPD_VIDEO_BITRATE, 40960); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_VIDEO_BITRATE")); - return hrSetValue; - } - - // Add WPD_VIDEO_FOURCC_CODE - hrSetValue = pStore->SetUnsignedIntegerValue(WPD_VIDEO_FOURCC_CODE, MAKEFOURCC('W', 'M', 'V', '3')); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_VIDEO_FOURCC_CODE")); - return hrSetValue; - } - - // Add WPD_OBJECT_GENERATE_THUMBNAIL_FROM_RESOURCE - hrSetValue = pStore->SetBoolValue(WPD_OBJECT_GENERATE_THUMBNAIL_FROM_RESOURCE, TRUE); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_OBJECT_GENERATE_THUMBNAIL_FROM_RESOURCE ")); - return hrSetValue; - } - - return hr; - } - - virtual HRESULT WriteValue( - _In_ REFPROPERTYKEY key, - _In_ REFPROPVARIANT Value) - { - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(IsEqualPropertyKey(key, WPD_OBJECT_ORIGINAL_FILE_NAME)) - { - if(Value.vt == VT_LPWSTR) - { - if (Value.pwszVal != NULL && Value.pwszVal[0] != L'\0') - { - FileName = Value.pwszVal; - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME because value was an empty string"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_OBJECT_ORIGINAL_FILE_NAME because type was not VT_LPWSTR"); - } - } - else - { - hr = FakeContent::WriteValue(key, Value); - CHECK_HR(hr, "Property %ws.%d on [%ws] does not support set value operation", CComBSTR(key.fmtid), key.pid, ObjectID); - } - - return hr; - } - - virtual HRESULT GetSupportedResources(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - // Call the base class to fill in the standard resources if any - hr = FakeContent::GetSupportedResources(&pKeys); - CHECK_HR(hr, "Failed to get basic supported resources"); - } - - if (SUCCEEDED(hr)) - { - // Add WPD_RESOURCE_DEFAULT - hr = pKeys->Add(WPD_RESOURCE_DEFAULT); - CHECK_HR(hr, "Failed to add WPD_RESOURCE_DEFAULT to collection"); - } - - if (SUCCEEDED(hr)) - { - hr = pKeys->QueryInterface(IID_IPortableDeviceKeyCollection, (VOID**) ppKeys); - CHECK_HR(hr, "Failed to QI for IPortableDeviceKeyCollection on IPortableDeviceKeyCollection"); - } - - return hr; - } - - virtual HRESULT GetResourceAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - UNREFERENCED_PARAMETER(Key); - - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pAttributes; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if (SUCCEEDED(hr)) - { - // Fill in the common resource attributes - hr = GetCommonResourceAttributes(&pAttributes); - CHECK_HR(hr, "Failed to get common resource attributes set"); - } - - // Override the size attribute for this resource. - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE, GetResourceSize(IDR_WPD_SAMPLEDRIVER_VIDEO)); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE"); - } - - // Override the format attribute for this resource. - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetGuidValue(WPD_RESOURCE_ATTRIBUTE_FORMAT, WPD_OBJECT_FORMAT_WMV); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_FORMAT"); - } - - // Return the resource attributes - if (SUCCEEDED(hr)) - { - hr = pAttributes->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppAttributes); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on Wpd IPortableDeviceValues"); - } - return hr; - } - - // This sample driver uses a embedded music file resource as its data. - virtual HRESULT ReadData( - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) - { - HRESULT hr = S_OK; - DWORD dwBytesToTransfer = 0; - DWORD dwObjectDataSize = 0; - PBYTE pResource = NULL; - - UNREFERENCED_PARAMETER(ResourceKey); - - if((pBuffer == NULL) || - (pdwNumBytesRead == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *pdwNumBytesRead = 0; - - pResource = GetResourceData(IDR_WPD_SAMPLEDRIVER_VIDEO); - dwObjectDataSize = GetResourceSize(IDR_WPD_SAMPLEDRIVER_VIDEO); - - if (pResource == NULL) - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Failed to get resource representing image data"); - } - - // Calculate how many bytes to transfer - if (hr == S_OK) - { - if (dwStartByte < dwObjectDataSize) - { - dwBytesToTransfer = (dwObjectDataSize - dwStartByte); - if (dwBytesToTransfer > dwNumBytesToRead) - { - dwBytesToTransfer = dwNumBytesToRead; - } - } - } - - // Copy the embedded music file data. - if ((hr == S_OK) && (dwBytesToTransfer > 0)) - { - memcpy(pBuffer, pResource + dwStartByte, dwBytesToTransfer); - } - - if (hr == S_OK) - { - *pdwNumBytesRead = dwBytesToTransfer; - } - - return hr; - } - - virtual GUID GetObjectFormat() - { - return WPD_OBJECT_FORMAT_WMV; - } -}; - diff --git a/wpd/WpdWudfSampleDriver/NetworkConfigFakeContent.h b/wpd/WpdWudfSampleDriver/NetworkConfigFakeContent.h deleted file mode 100644 index e428e278..00000000 --- a/wpd/WpdWudfSampleDriver/NetworkConfigFakeContent.h +++ /dev/null @@ -1,378 +0,0 @@ -#include "NetworkConfigFakeContent.h.tmh" - -class NetworkConfigFakeContent : public FakeContent -{ -public: - NetworkConfigFakeContent() - { - } - - virtual ~NetworkConfigFakeContent() - { - } - - virtual HRESULT GetSupportedProperties(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - hr = AddSupportedProperties(WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, ppKeys); - CHECK_HR(hr, "Failed to add additional properties for NetworkConfigFakeContent"); - } - return hr; - } - - virtual HRESULT GetAllValues( - _In_ IPortableDeviceValues* pStore) - { - HRESULT hr = S_OK; - HRESULT hrSetValue = S_OK; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Call the base class to fill in the standard properties - hr = FakeContent::GetAllValues(pStore); - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get basic property set"); - return hr; - } - - // Add WPD_FUNCTIONAL_OBJECT_CATEGORY - hrSetValue = pStore->SetGuidValue(WPD_FUNCTIONAL_OBJECT_CATEGORY, WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION); - if (hrSetValue != S_OK) - { - CHECK_HR(hr, "Failed to set WPD_FUNCTIONAL_OBJECT_CATEGORY"); - return hrSetValue; - } - - return hr; - } - - virtual HRESULT GetAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pAttributes; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (SUCCEEDED(hr)) - { - hr = AddFixedPropertyAttributes(WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, Key, pAttributes); - CHECK_HR(hr, "Failed to add fixed property attributes for %ws.%d on NetworkConfigFakeContent", CComBSTR(Key.fmtid), Key.pid); - } - - if (SUCCEEDED(hr)) - { - hr = pAttributes->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppAttributes); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on IPortableDeviceValues"); - } - return hr; - } - - virtual HRESULT GetSupportedResources(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - if (SUCCEEDED(hr)) - { - hr = pKeys->QueryInterface(IID_IPortableDeviceKeyCollection, (VOID**) ppKeys); - CHECK_HR(hr, "Failed to QI for IPortableDeviceKeyCollection on IPortableDeviceKeyCollection"); - } - - return hr; - } - - virtual HRESULT GetResourceAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - UNREFERENCED_PARAMETER(Key); - *ppAttributes = NULL; - return E_NOTIMPL; - } - - virtual HRESULT ReadData( - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) - { - UNREFERENCED_PARAMETER(ResourceKey); - UNREFERENCED_PARAMETER(dwStartByte); - UNREFERENCED_PARAMETER(pBuffer); - UNREFERENCED_PARAMETER(dwNumBytesToRead); - *pdwNumBytesRead = 0; - return E_NOTIMPL; - } - - virtual HRESULT WriteData( - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _In_reads_(dwNumBytesToWrite) BYTE* pBuffer, - DWORD dwNumBytesToWrite, - _Out_ DWORD* pdwNumBytesWritten) - { - UNREFERENCED_PARAMETER(ResourceKey); - UNREFERENCED_PARAMETER(dwStartByte); - UNREFERENCED_PARAMETER(pBuffer); - UNREFERENCED_PARAMETER(dwNumBytesToWrite); - *pdwNumBytesWritten = 0; - return E_NOTIMPL; - } - - virtual GUID GetObjectFormat() - { - return WPD_OBJECT_FORMAT_PROPERTIES_ONLY; - } -}; - -class FakeNetworkAssociationContent : public FakeContent -{ -public: - FakeNetworkAssociationContent() - { - PropVariantInit(&HostEUI64Array); - } - - virtual ~FakeNetworkAssociationContent() - { - } - - virtual HRESULT GetAllValues(_In_ IPortableDeviceValues* pStore) - { - HRESULT hr = S_OK; - HRESULT hrSetValue = S_OK; - PropVariantWrapper pvValue; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = FakeContent::GetAllValues(pStore); - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get basic property set"); - return hr; - } - - // Add WPD_NETWORK_ASSOCIATION_HOST_NETWORK_IDENTIFIERS - if (HostEUI64Array.vt == VT_EMPTY) - { - // This value is supposed to be available, but it is just a soft error if it is missing - pvValue.SetErrorValue(HRESULT_FROM_WIN32(ERROR_NOT_FOUND)); - hrSetValue = pStore->SetValue(WPD_NETWORK_ASSOCIATION_HOST_NETWORK_IDENTIFIERS, &pvValue); - - hr = S_FALSE; - } - else - { - hrSetValue = pStore->SetValue(WPD_NETWORK_ASSOCIATION_HOST_NETWORK_IDENTIFIERS, &HostEUI64Array); - } - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_NETWORK_ASSOCIATION_HOST_NETWORK_IDENTIFIERS")); - return hrSetValue; - } - - return hr; - } - - virtual HRESULT WriteValue( - _In_ REFPROPERTYKEY key, - _In_ REFPROPVARIANT Value) - { - HRESULT hr = S_OK; - PropVariantWrapper pvValue; - - if(IsEqualPropertyKey(key, WPD_NETWORK_ASSOCIATION_HOST_NETWORK_IDENTIFIERS)) - { - if (Value.vt == (VARTYPE)(VT_VECTOR | VT_UI1)) - { - if ((Value.caub.cElems % 8) == 0) - { - if (FAILED(PropVariantClear(&HostEUI64Array))) - { - PropVariantInit(&HostEUI64Array); - } - - hr = PropVariantCopy(&HostEUI64Array, &Value); - CHECK_HR(hr, "Error setting WPD_NETWORK_ASSOCIATION_HOST_NETWORK_IDENTIFIERS"); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_NETWORK_ASSOCIATION_HOST_NETWORK_IDENTIFIERS because value was the wrong length"); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to set WPD_NETWORK_ASSOCIATION_HOST_NETWORK_IDENTIFIERS because type was not VT_VECTOR|VT_UI1"); - } - } - else - { - hr = FakeContent::WriteValue(key, Value); - } - - return hr; - } - - virtual HRESULT GetSupportedResources(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pKeys); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - if (SUCCEEDED(hr)) - { - hr = pKeys->QueryInterface(IID_IPortableDeviceKeyCollection, (VOID**) ppKeys); - CHECK_HR(hr, "Failed to QI for IPortableDeviceKeyCollection on IPortableDeviceKeyCollection"); - } - - return hr; - } - - virtual HRESULT GetResourceAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - UNREFERENCED_PARAMETER(Key); - *ppAttributes = NULL; - return E_NOTIMPL; - } - - virtual HRESULT ReadData( - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) - { - UNREFERENCED_PARAMETER(ResourceKey); - UNREFERENCED_PARAMETER(dwStartByte); - UNREFERENCED_PARAMETER(pBuffer); - UNREFERENCED_PARAMETER(dwNumBytesToRead); - *pdwNumBytesRead = 0; - return E_NOTIMPL; - } - - virtual HRESULT WriteData( - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _In_reads_(dwNumBytesToWrite) BYTE* pBuffer, - DWORD dwNumBytesToWrite, - _Out_ DWORD* pdwNumBytesWritten) - { - UNREFERENCED_PARAMETER(ResourceKey); - UNREFERENCED_PARAMETER(dwStartByte); - UNREFERENCED_PARAMETER(pBuffer); - UNREFERENCED_PARAMETER(dwNumBytesToWrite); - *pdwNumBytesWritten = 0; - return E_NOTIMPL; - } - - virtual GUID GetObjectFormat() - { - return WPD_OBJECT_FORMAT_NETWORK_ASSOCIATION; - } - - PROPVARIANT HostEUI64Array; -}; - - -class FakeWirelessProfileContent : public FakeContent -{ -public: - FakeWirelessProfileContent() - { - } - - virtual ~FakeWirelessProfileContent() - { - } - - virtual GUID GetObjectFormat() - { - return WPD_OBJECT_FORMAT_MICROSOFT_WFC; - } -}; - - diff --git a/wpd/WpdWudfSampleDriver/Queue.cpp b/wpd/WpdWudfSampleDriver/Queue.cpp deleted file mode 100644 index 6741c920..00000000 --- a/wpd/WpdWudfSampleDriver/Queue.cpp +++ /dev/null @@ -1,334 +0,0 @@ -// Queue.cpp : Implementation of CQueue - -#include "stdafx.h" -#include "Queue.h" -#include <devioctl.h> -#include <initguid.h> - -#include "Queue.tmh" - -// Add table used to lookup the Access required for Wpd Commands -BEGIN_WPD_COMMAND_ACCESS_MAP(g_WpdCommandAccessMap) - DECLARE_WPD_STANDARD_COMMAND_ACCESS_ENTRIES - // Add any custom commands here e.g. - // WPD_COMMAND_ACCESS_ENTRY(MyCustomCommand, WPD_COMMAND_ACCESS_READWRITE) -END_WPD_COMMAND_ACCESS_MAP - -// This enables use to use VERIFY_WPD_COMMAND_ACCESS to check command access function for us. -DECLARE_VERIFY_WPD_COMMAND_ACCESS; - -/****************************************************************************** - * This function calls the WpdBaseDriver to handle the WPD message. In order - * to do this it does the following: - * - * - Deserializes pBuffer into an IPortableDeviceValues which holds the command - * input parameters from the WPD application. - * - Creates an IPortableDeviceValues for the results. - * - Calls the WpdBaseDriver to handle the message. (The results of this - * operation are put into the previously created results IPortableDeviceValues.) - * - The results IPortableDeviceValues is then serialized back into pBuffer, making - * sure that it does not overrun ulOutputBufferLength. - * - *****************************************************************************/ -HRESULT CQueue::ProcessWpdMessage( - ULONG ControlCode, - _In_ ContextMap* pClientContextMap, - _In_ IWDFDevice* pDevice, - _In_reads_bytes_(ulInputBufferLength) PVOID pInBuffer, - ULONG ulInputBufferLength, - _Out_writes_bytes_to_(ulOutputBufferLength, *pdwBytesWritten) PVOID pOutBuffer, - ULONG ulOutputBufferLength, - _Out_ DWORD* pdwBytesWritten) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<WpdBaseDriver> pWpdBaseDriver; - - *pdwBytesWritten = 0; - - if (hr == S_OK) - { - hr = m_pWpdSerializer->GetIPortableDeviceValuesFromBuffer((BYTE*)pInBuffer, - ulInputBufferLength, - &pParams); - CHECK_HR(hr, "Failed to deserialize command parameters from input buffer"); - } - - // Verify that that command was sent with the appropriate access - if (hr == S_OK) - { - hr = VERIFY_WPD_COMMAND_ACCESS(ControlCode, pParams, g_WpdCommandAccessMap); - CHECK_HR(hr, "Wpd Command was sent with incorrect access flags"); - } - - // Create the WPD results collection - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Insert the client context map as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the context map. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, pClientContextMap); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Insert the IWDFDevice interface as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the WUDF Device object. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT, pDevice); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT"); - } - - // Insert the IWpdSerializer interface as one of this driver's private properties. This is - // just a convenient place holder which allows other methods down the chain to - // access the WPD Serializer object. - if (hr == S_OK) - { - hr = pParams->SetIUnknownValue(PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT, m_pWpdSerializer); - CHECK_HR(hr, "Failed to set PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT"); - } - - // Get the WpdBaseDriver so we can dispatch the message - if (hr == S_OK) - { - hr = GetWpdBaseDriver(pDevice, &pWpdBaseDriver); - CHECK_HR(hr, "Failed to get WpdBaseDriver"); - } - - if (hr == S_OK) - { - hr = pWpdBaseDriver->DispatchWpdMessage(pParams, pResults); - CHECK_HR(hr, "Failed to handle WPD command"); - } - - if (hr == S_OK) - { - hr = m_pWpdSerializer->WriteIPortableDeviceValuesToBuffer(ulOutputBufferLength, - pResults, - (BYTE*)pOutBuffer, - pdwBytesWritten); - CHECK_HR(hr, "Failed to serialize results to output buffer"); - } - - return hr; -} - -/****************************************************************************** - * This method gets the WpdBaseDriver associated with the UMDF device object. - * The caller should Release *ppWpdBaseDriver when it is done. - * - * When this device was created, we assigned the WpdBaseDriver as the context. - * So, in order to retrieve the correct WpdBaseDriver for this device, we simply - * get the device context. - *****************************************************************************/ -HRESULT CQueue::GetWpdBaseDriver( - _In_ IWDFDevice* pDevice, - _Outptr_result_nullonfailure_ WpdBaseDriver** ppWpdBaseDriver) -{ - HRESULT hr = S_OK; - WpdBaseDriver* pContext = NULL; - - if((pDevice == NULL) || (ppWpdBaseDriver == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter for pDevice or ppWpdBaseDriver"); - } - - *ppWpdBaseDriver = NULL; - - if(SUCCEEDED(hr)) - { - hr = pDevice->RetrieveContext((void**)&pContext); - if(SUCCEEDED(hr)) - { - if(pContext != NULL) - { - pContext->AddRef(); - *ppWpdBaseDriver = pContext; - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Device context is NULL"); - } - } - } - - return hr; -} - -// CQueue - -STDMETHODIMP_ (void) -CQueue::OnCreateFile( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - _In_ IWDFFile* pFileObject - ) -{ - UNREFERENCED_PARAMETER(pQueue); - // This critical section protects the section of code where we - // Create the serializer and results interfaces used in handling I/O messages. - // We only need to create them once, then we hang on to them for the lifetime of this - // queue object. - CComCritSecLock<CComAutoCriticalSection> Lock(m_CriticalSection); - HRESULT hr = S_OK; - - // Create the WPD serializer - if ((hr == S_OK) && - (m_pWpdSerializer == NULL)) - { - hr = CoCreateInstance(CLSID_WpdSerializer, - NULL, - CLSCTX_INPROC_SERVER, - IID_IWpdSerializer, - (VOID**)&m_pWpdSerializer); - - CHECK_HR(hr, "Failed to CoCreate CLSID_WpdSerializer"); - } - - // Create the client context map and associate it with the File Object - // so we can obtain it on a per-client basis. - if (hr == S_OK) - { - ContextMap* pClientContextMap = new ContextMap(); - - if(pClientContextMap != NULL) - { - hr = pFileObject->AssignContext(this, (void*)pClientContextMap); - CHECK_HR(hr, "Failed to set client context map"); - - // Release the client context map if we cannot set it - // properly - if(FAILED(hr)) - { - pClientContextMap->Release(); - pClientContextMap = NULL; - } - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to create client context map"); - } - } - - pRequest->Complete(hr); - return; -} - -STDMETHODIMP_ (void) -CQueue::OnDeviceIoControl( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - ULONG ControlCode, - SIZE_T InputBufferSizeInBytes, - SIZE_T OutputBufferSizeInBytes - ) -{ - UNREFERENCED_PARAMETER(InputBufferSizeInBytes); - UNREFERENCED_PARAMETER(OutputBufferSizeInBytes); - HRESULT hr = S_OK; - DWORD dwBytesWritten = 0; - - if(IS_WPD_IOCTL(ControlCode)) - { - BYTE* pInputBuffer = NULL; - SIZE_T cbInputBuffer = 0; - BYTE* pOutputBuffer = NULL; - SIZE_T cbOutputBuffer = 0; - ContextMap* pClientContextMap = NULL; - CComPtr<IWDFMemory> pMemoryIn; - CComPtr<IWDFMemory> pMemoryOut; - CComPtr<IWDFDevice> pDevice; - CComPtr<IWDFFile> pFileObject; - - // - // Get input memory buffer, the memory object is always returned even if the - // underlying buffer is NULL - // - pRequest->GetInputMemory(&pMemoryIn); - pInputBuffer = (BYTE*) pMemoryIn->GetDataBuffer(&cbInputBuffer); - - // - // Get output memory buffer, the memory object is always returned even if the - // underlying buffer is NULL - // - pRequest->GetOutputMemory(&pMemoryOut); - pOutputBuffer = (BYTE*) pMemoryOut->GetDataBuffer(&cbOutputBuffer); - - // Get the Context map for this client - pRequest->GetFileObject(&pFileObject); - if (pFileObject != NULL) - { - hr = pFileObject->RetrieveContext((void**)&pClientContextMap); - CHECK_HR(hr, "Failed to get Contextmap from WDF File Object"); - - if (hr == S_OK) - { - // Get the device object - pQueue->GetDevice(&pDevice ); - hr = ProcessWpdMessage(ControlCode, - pClientContextMap, - pDevice, - pInputBuffer, - (DWORD)cbInputBuffer, - pOutputBuffer, - (DWORD)cbOutputBuffer, - &dwBytesWritten); - } - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "WDF File Object is NULL"); - } - } - else - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Received invalid/unsupported IOCTL code '0x%lx'",ControlCode); - } - - // Complete the request - if (hr == S_OK) - { - pRequest->CompleteWithInformation(hr, dwBytesWritten); - } - else - { - pRequest->Complete(hr); - } - - return; -} - -STDMETHODIMP_ (void) -CQueue::OnCleanup( - _In_ IWDFObject* pWdfObject - ) -{ - // Destroy the client context map - HRESULT hr = S_OK; - ContextMap* pClientContextMap = NULL; - - hr = pWdfObject->RetrieveContext((void**)&pClientContextMap); - if((hr == S_OK) && (pClientContextMap != NULL)) - { - pClientContextMap->Release(); - pClientContextMap = NULL; - } -} - diff --git a/wpd/WpdWudfSampleDriver/Queue.h b/wpd/WpdWudfSampleDriver/Queue.h deleted file mode 100644 index d53ce76e..00000000 --- a/wpd/WpdWudfSampleDriver/Queue.h +++ /dev/null @@ -1,93 +0,0 @@ -// Queue.h : Declaration of the CQueue - -#pragma once -#include "resource.h" // main symbols -#include "WpdWudfSampleDriver.h" - - -class ATL_NO_VTABLE CQueue : - public CComObjectRootEx<CComMultiThreadModel>, - public IQueueCallbackDeviceIoControl, - public IQueueCallbackCreate, - public IObjectCleanup -{ -public: - CQueue() - { - - } - - DECLARE_NOT_AGGREGATABLE(CQueue) - - BEGIN_COM_MAP(CQueue) - COM_INTERFACE_ENTRY(IQueueCallbackDeviceIoControl) - COM_INTERFACE_ENTRY(IQueueCallbackCreate) - END_COM_MAP() - -public: - static - HRESULT CreateInstance( - _COM_Outptr_ IUnknown** ppUkwn) - { - *ppUkwn = NULL; - CComObject< CQueue> *pMyQueue = NULL; - HRESULT hr = CComObject<CQueue>::CreateInstance( &pMyQueue ); - if( SUCCEEDED (hr) ) - { - pMyQueue->AddRef(); - hr = pMyQueue->QueryInterface( __uuidof(IUnknown), (void **) ppUkwn ); - pMyQueue->Release(); - pMyQueue = NULL; - } - return hr; - } - - // - // Wdf Callbacks - // - - // IQueueCallbackCreateClose - // - STDMETHOD_ (void, OnCreateFile)( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - _In_ IWDFFile* pFileObject - ); - - // - // IQueueCallbackDeviceIoControl - // - STDMETHOD_ (void, OnDeviceIoControl)( - _In_ IWDFIoQueue* pQueue, - _In_ IWDFIoRequest* pRequest, - ULONG ControlCode, - SIZE_T InputBufferSizeInBytes, - SIZE_T OutputBufferSizeInBytes - ); - - // - // IObjectCleanup - // - STDMETHOD_ (void, OnCleanup)( - _In_ IWDFObject* pWdfObject - ); - -private: - HRESULT ProcessWpdMessage( - ULONG ControlCode, - _In_ ContextMap* pClientContextMap, - _In_ IWDFDevice* pDevice, - _In_reads_bytes_(ulInputBufferLength) PVOID pInBuffer, - ULONG ulInputBufferLength, - _Out_writes_bytes_to_(ulOutputBufferLength, *pdwBytesWritten) PVOID pOutBuffer, - ULONG ulOutputBufferLength, - _Out_ DWORD* pdwBytesWritten); - - HRESULT GetWpdBaseDriver( - _In_ IWDFDevice* pDevice, - _Outptr_result_nullonfailure_ WpdBaseDriver** ppWpdBaseDriver); - - CComPtr<IWpdSerializer> m_pWpdSerializer; - CComAutoCriticalSection m_CriticalSection; -}; - diff --git a/wpd/WpdWudfSampleDriver/README.md b/wpd/WpdWudfSampleDriver/README.md deleted file mode 100644 index 63d7898f..00000000 --- a/wpd/WpdWudfSampleDriver/README.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -page_type: sample -description: "Demonstrates virtually all aspects of the WPD device driver interface (DDI)." -languages: -- cpp -products: -- windows -- windows-wdk ---- - -# WPD WUDF sample driver - -The comprehensive WPD sample driver (WpdWudfSampleDriver) demonstrates virtually all aspects of the Microsoft Windows Portable Devices (WPD) device driver interface (DDI). This driver is built as a normal User-Mode Driver Framework (UMDF) driver that also processes the WPD command set. Although this driver does not interact with actual hardware, it simulates communicating with a device that supports phone contacts, pictures, music, and video. - -This driver was written in the simplest way to demonstrate concepts. Therefore, the sample driver might perform operations or be structured in a way that are inefficient in a production driver. Additionally, this sample does not use real hardware. Instead, it simulates a device by using data structures in memory. Therefore, the driver might be implemented in a way that is unrealistic for production hardware. - -Some of the tasks that are accomplished by the `WpdWudfSampleDriver` sample are written for the advanced Windows Portable Devices (WPD) driver developer. - -For a complete description of this sample and its underlying code and functionality, refer to the [WPD WUDF Sample Driver](https://docs.microsoft.com/windows-hardware/drivers/portable/the-wpdwudfsampledriver-sample) description in the Windows Driver Kit documentation. - -## Related topics - -[WPD Design Guide](https://docs.microsoft.com/windows-hardware/drivers/portable/wpd-design-guide) - -[WPD Driver Development Tools](https://docs.microsoft.com/windows-hardware/drivers/portable/familiarizing-yourself-with-the-sample-driver) - -[WPD Programming Guide](https://docs.microsoft.com/windows-hardware/drivers/portable/wpd-programming-guide) diff --git a/wpd/WpdWudfSampleDriver/RenderingInformationFakeContent.h b/wpd/WpdWudfSampleDriver/RenderingInformationFakeContent.h deleted file mode 100644 index 75b2a0bd..00000000 --- a/wpd/WpdWudfSampleDriver/RenderingInformationFakeContent.h +++ /dev/null @@ -1,138 +0,0 @@ -#include "RenderingInformationFakeContent.h.tmh" - -class RenderingInformationFakeContent : public FakeContent -{ -public: - RenderingInformationFakeContent() - { - } - - RenderingInformationFakeContent(const RenderingInformationFakeContent& src) - { - *this = src; - } - - virtual ~RenderingInformationFakeContent() - { - } - - virtual HRESULT GetSupportedProperties(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - hr = AddSupportedProperties(WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, ppKeys); - CHECK_HR(hr, "Failed to add additional properties for RenderingInformationFakeContent"); - } - - return hr; - } - - virtual HRESULT GetAllValues( - _In_ IPortableDeviceValues* pStore) - { - HRESULT hr = S_OK; - HRESULT hrSetValue = S_OK; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Call the base class to fill in the standard properties - hr = FakeContent::GetAllValues(pStore); - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get basic property set"); - return hr; - } - - // Add WPD_FUNCTIONAL_OBJECT_CATEGORY - hrSetValue = pStore->SetGuidValue(WPD_FUNCTIONAL_OBJECT_CATEGORY, WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION); - if (hrSetValue != S_OK) - { - CHECK_HR(hr, "Failed to set WPD_FUNCTIONAL_OBJECT_CATEGORY"); - return hrSetValue; - } - - // Add WPD_RENDERING_INFORMATION_PROFILES - hrSetValue = SetRenderingProfiles(pStore); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, ("Failed to set WPD_RENDERING_INFORMATION_PROFILES")); - return hrSetValue; - } - - return hr; - } - - virtual HRESULT GetAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pAttributes; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (SUCCEEDED(hr)) - { - hr = AddFixedPropertyAttributes(WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, Key, pAttributes); - CHECK_HR(hr, "Failed to add fixed property attributes for %ws.%d on RenderingInformationFakeContent", CComBSTR(Key.fmtid), Key.pid); - } - - // Some of our properties have extra attributes on top of the ones that are common to all - if(IsEqualPropertyKey(Key, WPD_OBJECT_NAME)) - { - CAtlStringW strDefaultName; - - strDefaultName.Format(L"%ws%ws", L"Name", ObjectID.GetString()); - - hr = pAttributes->SetStringValue(WPD_PROPERTY_ATTRIBUTE_DEFAULT_VALUE, strDefaultName.GetString());; - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_DEFAULT_VALUE"); - } - - // Return the property attributes - if (SUCCEEDED(hr)) - { - hr = pAttributes->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppAttributes); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on Wpd IPortableDeviceValues"); - } - return hr; - } - - virtual GUID GetObjectFormat() - { - return WPD_OBJECT_FORMAT_UNSPECIFIED; - } -}; - diff --git a/wpd/WpdWudfSampleDriver/SampleAudioAnnotation.wav b/wpd/WpdWudfSampleDriver/SampleAudioAnnotation.wav Binary files differdeleted file mode 100644 index fa21dd53..00000000 --- a/wpd/WpdWudfSampleDriver/SampleAudioAnnotation.wav +++ /dev/null diff --git a/wpd/WpdWudfSampleDriver/SampleContactPhoto.png b/wpd/WpdWudfSampleDriver/SampleContactPhoto.png Binary files differdeleted file mode 100644 index 7979e772..00000000 --- a/wpd/WpdWudfSampleDriver/SampleContactPhoto.png +++ /dev/null diff --git a/wpd/WpdWudfSampleDriver/SampleDeviceIcon.ico b/wpd/WpdWudfSampleDriver/SampleDeviceIcon.ico Binary files differdeleted file mode 100644 index 33a1d1a5..00000000 --- a/wpd/WpdWudfSampleDriver/SampleDeviceIcon.ico +++ /dev/null diff --git a/wpd/WpdWudfSampleDriver/SampleExternalStorageIcon.ico b/wpd/WpdWudfSampleDriver/SampleExternalStorageIcon.ico Binary files differdeleted file mode 100644 index 5598b83b..00000000 --- a/wpd/WpdWudfSampleDriver/SampleExternalStorageIcon.ico +++ /dev/null diff --git a/wpd/WpdWudfSampleDriver/SampleImage.jpg b/wpd/WpdWudfSampleDriver/SampleImage.jpg Binary files differdeleted file mode 100644 index d018ec4e..00000000 --- a/wpd/WpdWudfSampleDriver/SampleImage.jpg +++ /dev/null diff --git a/wpd/WpdWudfSampleDriver/SampleImageThumbnail.jpg b/wpd/WpdWudfSampleDriver/SampleImageThumbnail.jpg Binary files differdeleted file mode 100644 index 39738839..00000000 --- a/wpd/WpdWudfSampleDriver/SampleImageThumbnail.jpg +++ /dev/null diff --git a/wpd/WpdWudfSampleDriver/SampleInternalStorageIcon.ico b/wpd/WpdWudfSampleDriver/SampleInternalStorageIcon.ico Binary files differdeleted file mode 100644 index e1496876..00000000 --- a/wpd/WpdWudfSampleDriver/SampleInternalStorageIcon.ico +++ /dev/null diff --git a/wpd/WpdWudfSampleDriver/SampleMemo.txt b/wpd/WpdWudfSampleDriver/SampleMemo.txt deleted file mode 100644 index c5436941..00000000 --- a/wpd/WpdWudfSampleDriver/SampleMemo.txt +++ /dev/null @@ -1 +0,0 @@ -This is a sample memo.
\ No newline at end of file diff --git a/wpd/WpdWudfSampleDriver/SampleMemoFolderIcon.ico b/wpd/WpdWudfSampleDriver/SampleMemoFolderIcon.ico Binary files differdeleted file mode 100644 index 9c07ff66..00000000 --- a/wpd/WpdWudfSampleDriver/SampleMemoFolderIcon.ico +++ /dev/null diff --git a/wpd/WpdWudfSampleDriver/SampleMemoIcon.ico b/wpd/WpdWudfSampleDriver/SampleMemoIcon.ico Binary files differdeleted file mode 100644 index 1bde7cc8..00000000 --- a/wpd/WpdWudfSampleDriver/SampleMemoIcon.ico +++ /dev/null diff --git a/wpd/WpdWudfSampleDriver/SampleMusic.wma b/wpd/WpdWudfSampleDriver/SampleMusic.wma Binary files differdeleted file mode 100644 index ae9b8f40..00000000 --- a/wpd/WpdWudfSampleDriver/SampleMusic.wma +++ /dev/null diff --git a/wpd/WpdWudfSampleDriver/SampleVideo.wmv b/wpd/WpdWudfSampleDriver/SampleVideo.wmv Binary files differdeleted file mode 100644 index 657d57ab..00000000 --- a/wpd/WpdWudfSampleDriver/SampleVideo.wmv +++ /dev/null diff --git a/wpd/WpdWudfSampleDriver/Stdafxsrc.cpp b/wpd/WpdWudfSampleDriver/Stdafxsrc.cpp deleted file mode 100644 index 5105a28d..00000000 --- a/wpd/WpdWudfSampleDriver/Stdafxsrc.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Stdafx.h"
\ No newline at end of file diff --git a/wpd/WpdWudfSampleDriver/StorageObjectFakeContent.h b/wpd/WpdWudfSampleDriver/StorageObjectFakeContent.h deleted file mode 100644 index d7ca2a7b..00000000 --- a/wpd/WpdWudfSampleDriver/StorageObjectFakeContent.h +++ /dev/null @@ -1,327 +0,0 @@ -#include "StorageObjectFakeContent.h.tmh" - -class StorageObjectFakeContent : public FakeContent -{ -public: - StorageObjectFakeContent() - { - Capacity = 0; - FreeSpaceInBytes = 0; - IsExternalStorage = FALSE; - } - - StorageObjectFakeContent(const FakeContent& src) - { - *this = src; - } - - virtual ~StorageObjectFakeContent() - { - } - - virtual StorageObjectFakeContent& operator= (const StorageObjectFakeContent& src) - { - ObjectID = src.ObjectID; - PersistentUniqueID = src.PersistentUniqueID; - ParentID = src.ParentID; - Name = src.Name; - ContentType = src.ContentType; - MarkedForDeletion = src.MarkedForDeletion; - CanDelete = src.CanDelete; - IsHidden = src.IsHidden; - IsSystem = src.IsSystem; - NonConsumable = src.NonConsumable; - Capacity = src.Capacity; - FreeSpaceInBytes = src.FreeSpaceInBytes; - IsExternalStorage = src.IsExternalStorage; - - return *this; - } - - virtual HRESULT GetSupportedProperties(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - hr = AddSupportedProperties(WPD_FUNCTIONAL_CATEGORY_STORAGE, ppKeys); - CHECK_HR(hr, "Failed to add additional properties for StorageObjectFakeContent"); - } - return hr; - } - - virtual HRESULT GetAllValues( - _In_ IPortableDeviceValues* pStore) - { - HRESULT hr = S_OK; - HRESULT hrSetValue = S_OK; - - if(pStore == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Call the base class to fill in the standard properties - hr = FakeContent::GetAllValues(pStore); - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get basic property set"); - return hr; - } - - // Add WPD_STORAGE_CAPACITY - hrSetValue = pStore->SetUnsignedLargeIntegerValue(WPD_STORAGE_CAPACITY, Capacity); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_STORAGE_CAPACITY"); - return hrSetValue; - } - - // Add WPD_STORAGE_FREE_SPACE_IN_BYTES - hrSetValue = pStore->SetUnsignedLargeIntegerValue(WPD_STORAGE_FREE_SPACE_IN_BYTES, FreeSpaceInBytes); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_STORAGE_FREE_SPACE_IN_BYTES"); - return hrSetValue; - } - - // Add WPD_FUNCTIONAL_OBJECT_CATEGORY - hrSetValue = pStore->SetGuidValue(WPD_FUNCTIONAL_OBJECT_CATEGORY, WPD_FUNCTIONAL_CATEGORY_STORAGE); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_FUNCTIONAL_OBJECT_CATEGORY"); - return hrSetValue; - } - - // Add WPD_STORAGE_TYPE - hrSetValue = pStore->SetUnsignedIntegerValue(WPD_STORAGE_TYPE, WPD_STORAGE_TYPE_FIXED_RAM); - if (hrSetValue != S_OK) - { - CHECK_HR(hrSetValue, "Failed to set WPD_STORAGE_TYPE"); - return hrSetValue; - } - - return hr; - } - - virtual HRESULT GetAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pAttributes; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (SUCCEEDED(hr)) - { - hr = AddFixedPropertyAttributes(FakeStorageContent_Format, Key, pAttributes); - CHECK_HR(hr, "Failed to add fixed property attributes for %ws.%d on StorageObjectFakeContent", CComBSTR(Key.fmtid), Key.pid); - } - - if (SUCCEEDED(hr)) - { - hr = pAttributes->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppAttributes); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on IPortableDeviceValues"); - } - return hr; - } - - virtual HRESULT GetSupportedResources(_COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) - { - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppKeys = NULL; - - if (SUCCEEDED(hr)) - { - // Call the base class to fill in the standard resources if any exist - hr = FakeContent::GetSupportedResources(&pKeys); - CHECK_HR(hr, "Failed to get basic supported resources"); - } - - if (SUCCEEDED(hr)) - { - // Add the icon resource - hr = pKeys->Add(WPD_RESOURCE_ICON); - CHECK_HR(hr, "Failed to add WPD_RESOURCE_ICON to supported resource list"); - } - - if (SUCCEEDED(hr)) - { - hr = pKeys->QueryInterface(IID_IPortableDeviceKeyCollection, (VOID**) ppKeys); - CHECK_HR(hr, "Failed to QI for IPortableDeviceKeyCollection on IPortableDeviceKeyCollection"); - } - - return hr; - } - - virtual HRESULT GetResourceAttributes( - _In_ REFPROPERTYKEY Key, - _COM_Outptr_ IPortableDeviceValues** ppAttributes) - { - UNREFERENCED_PARAMETER(Key); - - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pAttributes; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if (SUCCEEDED(hr)) - { - // Fill in the standard resource attributes - hr = GetCommonResourceAttributes(&pAttributes); - CHECK_HR(hr, "Failed to get common resource attributes set"); - } - - if (SUCCEEDED(hr)) - { - if (IsEqualPropertyKey(Key, WPD_RESOURCE_ICON)) - { - // Override the size attribute for this resource. - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE, GetResourceSize(GetResourceID())); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE"); - - // Override the format attribute for this resource. - hr = pAttributes->SetGuidValue(WPD_RESOURCE_ATTRIBUTE_FORMAT, WPD_OBJECT_FORMAT_ICON); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_FORMAT"); - } - } - - // Return the resource attributes - if (SUCCEEDED(hr)) - { - hr = pAttributes->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppAttributes); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on Wpd IPortableDeviceValues"); - } - return hr; - } - - // This sample driver uses a embedded image file resource as its data. - virtual HRESULT ReadData( - _In_ REFPROPERTYKEY ResourceKey, - DWORD dwStartByte, - _Out_writes_to_(dwNumBytesToRead, *pdwNumBytesRead) BYTE* pBuffer, - DWORD dwNumBytesToRead, - _Out_ DWORD* pdwNumBytesRead) - { - HRESULT hr = S_OK; - DWORD dwBytesToTransfer = 0; - DWORD dwObjectDataSize = 0; - PBYTE pResource = NULL; - - if((pBuffer == NULL) || - (pdwNumBytesRead == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - if (IsEqualPropertyKey(ResourceKey, WPD_RESOURCE_DEFAULT)) - { - return FakeContent::ReadData(ResourceKey, dwStartByte, pBuffer, dwNumBytesToRead, pdwNumBytesRead); - } - - *pdwNumBytesRead = 0; - - pResource = GetResourceData(GetResourceID()); - dwObjectDataSize = GetResourceSize(GetResourceID()); - - if (pResource == NULL) - { - hr = E_UNEXPECTED; - CHECK_HR(hr, "Failed to get resource representing the device icon data"); - } - - // Calculate how many bytes to transfer - if (hr == S_OK) - { - if (dwStartByte < dwObjectDataSize) - { - dwBytesToTransfer = (dwObjectDataSize - dwStartByte); - if (dwBytesToTransfer > dwNumBytesToRead) - { - dwBytesToTransfer = dwNumBytesToRead; - } - } - } - - // Copy the embedded image file data. - if ((hr == S_OK) && (dwBytesToTransfer > 0)) - { - memcpy(pBuffer, pResource + dwStartByte, dwBytesToTransfer); - } - - if (hr == S_OK) - { - *pdwNumBytesRead = dwBytesToTransfer; - } - - return hr; - } - - virtual GUID GetObjectFormat() - { - return FakeStorageContent_Format; - } - - UINT GetResourceID() - { - UINT uiResourceID = IDR_WPD_SAMPLEDRIVER_INTERNAL_STORAGE_ICON; - if(IsExternalStorage == TRUE) - { - uiResourceID = IDR_WPD_SAMPLEDRIVER_EXTERNAL_STORAGE_ICON; - } - - return uiResourceID; - } - - BOOL IsExternalStorage; - ULONGLONG Capacity; - ULONGLONG FreeSpaceInBytes; -}; - diff --git a/wpd/WpdWudfSampleDriver/WpdBaseDriver.cpp b/wpd/WpdWudfSampleDriver/WpdBaseDriver.cpp deleted file mode 100644 index b06591b6..00000000 --- a/wpd/WpdWudfSampleDriver/WpdBaseDriver.cpp +++ /dev/null @@ -1,456 +0,0 @@ -#include "stdafx.h" -#include "WpdBaseDriver.tmh" - -WpdBaseDriver::WpdBaseDriver() : - m_cRef(1) -{ -} - -WpdBaseDriver::~WpdBaseDriver() -{ - -} - -ULONG __stdcall WpdBaseDriver::AddRef() -{ - InterlockedIncrement((long*) &m_cRef); - return m_cRef; -} - -_At_(this, __drv_freesMem(Mem)) -ULONG __stdcall WpdBaseDriver::Release() -{ - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; -} - -HRESULT __stdcall WpdBaseDriver::QueryInterface( - REFIID riid, - void** ppv) -{ - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - return hr; -} - -HRESULT WpdBaseDriver::DispatchWpdMessage(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidCommandCategory = {0}; - DWORD dwCommandID = 0; - PROPERTYKEY CommandKey = WPD_PROPERTY_NULL; - - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, &guidCommandCategory); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_CATEGORY from input parameters"); - } - - if (hr == S_OK) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, &dwCommandID); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_ID from input parameters"); - } - - // If WPD_PROPERTY_COMMON_COMMAND_CATEGORY or WPD_PROPERTY_COMMON_COMMAND_ID could not be extracted - // properly then we should return E_INVALIDARG to the client. - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_COMMAND_CATEGORY or WPD_PROPERTY_COMMON_COMMAND_ID from input parameters"); - } - - if (hr == S_OK) - { - CommandKey.fmtid = guidCommandCategory; - CommandKey.pid = dwCommandID; - - if (CommandKey.fmtid == WPD_CATEGORY_OBJECT_ENUMERATION) - { - hr = m_ObjectEnum.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if(CommandKey.fmtid == WPD_CATEGORY_OBJECT_PROPERTIES) - { - hr = m_ObjectProperties.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if(CommandKey.fmtid == WPD_CATEGORY_OBJECT_PROPERTIES_BULK) - { - hr = m_ObjectPropertiesBulk.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if(CommandKey.fmtid == WPD_CATEGORY_OBJECT_RESOURCES) - { - hr = m_ObjectResources.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if(CommandKey.fmtid == WPD_CATEGORY_OBJECT_MANAGEMENT) - { - hr = m_ObjectManagement.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_CAPABILITIES) - { - hr = m_Capabilities.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_STORAGE) - { - hr = m_Storage.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if (CommandKey.fmtid == WPD_CATEGORY_NETWORK_CONFIGURATION) - { - hr = m_NetworkConfig.DispatchWpdMessage(CommandKey, pParams, pResults); - } - else if(IsEqualPropertyKey(CommandKey, WPD_COMMAND_COMMON_SAVE_CLIENT_INFORMATION)) - { - hr = OnSaveClientInfo(pParams, pResults); - } - else if(IsEqualPropertyKey(CommandKey, WPD_COMMAND_COMMON_GET_OBJECT_IDS_FROM_PERSISTENT_UNIQUE_IDS)) - { - hr = OnGetObjectIDsFromPersistentUniqueIDs(pParams, pResults); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "Unknown command %ws.%d received",CComBSTR(CommandKey.fmtid), CommandKey.pid); - } - } - - HRESULT hrTemp = pResults->SetErrorValue(WPD_PROPERTY_COMMON_HRESULT, hr); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_COMMON_HRESULT")); - - // Set to a success code, to indicate that the message was recieved. - // the return code for the actual command's results is stored in the - // WPD_PROPERTY_COMMON_HRESULT property. - hr = S_OK; - - return hr; -} - -/** - * This method is called to initialize the driver object. - * In a real driver, this is where the driver would set up it's I/O libraries - * and so on. - * - * For this sample driver, since we don't have a real device, we - * simply ignore the port name and initialize our internal FakeDevice. - * - */ -HRESULT WpdBaseDriver::Initialize( - _In_ LPCWSTR pszPortName, - _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension) -{ - UNREFERENCED_PARAMETER(pszPortName); - - HRESULT hr = S_OK; - - if(pPortableDeviceClassExtension == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - m_pPortableDeviceClassExtension = pPortableDeviceClassExtension; - - if (hr == S_OK) - { - hr = m_FakeDevice.InitializeContent(m_pPortableDeviceClassExtension); - CHECK_HR(hr, "Failed to initialize our fake device"); - } - - if (hr == S_OK) - { - hr = m_ObjectEnum.Initialize(&m_FakeDevice); - CHECK_HR(hr, "Failed to initialize our object enumerator"); - } - - if (hr == S_OK) - { - hr = m_ObjectProperties.Initialize(&m_FakeDevice); - CHECK_HR(hr, "Failed to initialize our properties object"); - } - - if (hr == S_OK) - { - hr = m_ObjectPropertiesBulk.Initialize(&m_FakeDevice); - CHECK_HR(hr, "Failed to initialize our properties bulk object"); - } - - if (hr == S_OK) - { - hr = m_ObjectResources.Initialize(&m_FakeDevice); - CHECK_HR(hr, "Failed to initialize our resources object"); - } - - if (hr == S_OK) - { - hr = m_ObjectManagement.Initialize(&m_FakeDevice); - CHECK_HR(hr, "Failed to initialize our object managment object"); - } - - if (hr == S_OK) - { - hr = m_Capabilities.Initialize(&m_FakeDevice); - CHECK_HR(hr, "Failed to initialize our capabilities object"); - } - - if (hr == S_OK) - { - hr = m_Storage.Initialize(&m_FakeDevice); - CHECK_HR(hr, "Failed to initialize our storage object"); - } - - if (hr == S_OK) - { - hr = m_NetworkConfig.Initialize(&m_FakeDevice); - CHECK_HR(hr, "Failed to initialize our network config object"); - } - - return hr; -} - -/** - * This method is called to uninitialize the driver object. - * In a real driver, this is where the driver would clean up - * any resources held by this driver. - */ -VOID WpdBaseDriver::Uninitialize() -{ -} - -/** - * Save the client information - */ -HRESULT WpdBaseDriver::OnSaveClientInfo( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidContext = GUID_NULL; - CComBSTR bstrContext; - ClientContext* pContext = NULL; - ContextMap* pContextMap = NULL; - - CComPtr<IPortableDeviceValues> pClientInfo; - - if((pParams == NULL) || - (pResults == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = CoCreateGuid(&guidContext); - if (hr == S_OK) - { - bstrContext = guidContext; - if(bstrContext.Length() == 0) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to create BSTR from GUID"); - } - } - - // Get the client info - if (hr == S_OK) - { - hr = pParams->GetIPortableDeviceValuesValue(WPD_PROPERTY_COMMON_CLIENT_INFORMATION, &pClientInfo); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_CLIENT_INFORMATION"); - } - - // Get the context map which the driver stored in pParams for convenience - if (hr == S_OK) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Create the new client info context we will save in the context map - if (hr == S_OK) - { - pContext = new ClientContext(); - if(pContext == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, ("Could not allocate memory for client info context")); - } - } - - // Save the client info. Since these are optional, none of this is fatal if - // they don't exist. - if (hr == S_OK) - { - LPWSTR pszClientName = NULL; - LPWSTR pszEventCookie = NULL; - - pClientInfo->GetStringValue(WPD_CLIENT_NAME, &pszClientName); - if(pszClientName != NULL) - { - pContext->ClientName = pszClientName; - } - pClientInfo->GetUnsignedIntegerValue(WPD_CLIENT_MAJOR_VERSION, &(pContext->MajorVersion)); - pClientInfo->GetUnsignedIntegerValue(WPD_CLIENT_MINOR_VERSION, &(pContext->MinorVersion)); - pClientInfo->GetUnsignedIntegerValue(WPD_CLIENT_REVISION, &(pContext->Revision)); - - pClientInfo->GetStringValue(WPD_CLIENT_EVENT_COOKIE, &pszEventCookie); - if (pszEventCookie != NULL) - { - pContext->EventCookie = pszEventCookie; - } - - CoTaskMemFree(pszClientName); - CoTaskMemFree(pszEventCookie); - } - - if ((hr == S_OK) && - (pContext->ClientName.GetLength() > 0) && - (pContextMap != NULL)) - { - CAtlStringW strKey = bstrContext; - hr = pContextMap->Add(strKey, pContext); - CHECK_HR(hr, "Failed to add client info context to context map"); - - if (hr == S_OK) - { - hr = pResults->SetStringValue(WPD_PROPERTY_COMMON_CLIENT_INFORMATION_CONTEXT, bstrContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_COMMON_CLIENT_INFORMATION_CONTEXT"); - } - } - - SAFE_RELEASE(pContext); // Always release the context, pContextMap::Add would have AddRef'ed it - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_COMMON_GET_OBJECT_IDS_FROM_PERSISTENT_UNIQUE_IDS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS: Contains an IPortableDevicePropVariantCollection of VT_LPWSTR, - * indicating the PersistentUniqueIDs. - * - * The driver should: - * - Iterate through the PersistentUniqueIDs, and convert to a currently valid object id. - * This object ID list should be returned as an IPortableDevicePropVariantCollection of VT_LPWSTR - * in WPD_PROPERTY_COMMON_OBJECT_IDS. - * Order is implicit, i.e. the first element in the Persistent Unique ID list corresponds to the - * to the first element of the ObjectID list and so on. - * - * For those elements where an existing ObjectID could not be found (e.g. the - * object is no longer present on the device), the element will contain the - * empty string (L""). - */ -HRESULT WpdBaseDriver::OnGetObjectIDsFromPersistentUniqueIDs( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - DWORD dwCount = 0; - CComPtr<IPortableDevicePropVariantCollection> pPersistentIDs; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - - if((pParams == NULL) || - (pResults == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - // Get the list of Persistent IDs - if (hr == S_OK) - { - hr = pParams->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS, &pPersistentIDs); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_COMMON_PERSISTENT_UNIQUE_IDS"); - } - - // Create the collection to hold the ObjectIDs - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pObjectIDs); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - // Iterate through the persistent ID list and add the equivalent object ID for each element. - if (hr == S_OK) - { - hr = pPersistentIDs->GetCount(&dwCount); - CHECK_HR(hr, "Failed to get count from persistent ID collection"); - - if (hr == S_OK) - { - DWORD dwIndex = 0; - PROPVARIANT pvPersistentID = {0}; - PROPVARIANT pvObjectID = {0}; - PropVariantInit(&pvPersistentID); - PropVariantInit(&pvObjectID); - - for(dwIndex = 0; dwIndex < dwCount; dwIndex++) - { - pvObjectID.vt = VT_LPWSTR; - hr = pPersistentIDs->GetAt(dwIndex, &pvPersistentID); - CHECK_HR(hr, "Failed to get persistent ID at index %d", dwIndex); - - if (hr == S_OK) - { - hr = m_FakeDevice.GetObjectIDFromPersistentID(pvPersistentID.pwszVal, &pvObjectID.pwszVal); - // Don't log this error, since it is expected if the object is not found - } - - if(FAILED(hr)) - { - hr = S_OK; - pvObjectID.pwszVal = AtlAllocTaskWideString(L""); - if(pvObjectID.pwszVal == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate memory for empty ObjectID"); - } - } - - if (hr == S_OK) - { - hr = pObjectIDs->Add(&pvObjectID); - CHECK_HR(hr, "Failed to add next Object ID"); - } - - PropVariantClear(&pvPersistentID); - PropVariantClear(&pvObjectID); - - if(FAILED(hr)) - { - break; - } - } - } - } - - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_COMMON_OBJECT_IDS, pObjectIDs); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_COMMON_OBJECT_IDS"); - } - - return hr; -} - diff --git a/wpd/WpdWudfSampleDriver/WpdBaseDriver.h b/wpd/WpdWudfSampleDriver/WpdBaseDriver.h deleted file mode 100644 index ee092fd6..00000000 --- a/wpd/WpdWudfSampleDriver/WpdBaseDriver.h +++ /dev/null @@ -1,113 +0,0 @@ -#pragma once - -// This class is used to store the connected client information. -// This is for demonstration purposes only - this driver does not -// make use of the information. -class ClientContext : public IUnknown -{ -public: - ClientContext() : - MajorVersion(0), - MinorVersion(0), - Revision(0), - m_cRef(1) - { - } - - ~ClientContext() - { - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -private: - DWORD m_cRef; - -public: - CAtlStringW ClientName; - CAtlStringW EventCookie; - DWORD MajorVersion; - DWORD MinorVersion; - DWORD Revision; -}; - -class WpdBaseDriver : - public IUnknown -{ -public: - WpdBaseDriver(); - virtual ~WpdBaseDriver(); - - HRESULT Initialize(_In_ LPCWSTR pszPortName, _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension); - VOID Uninitialize(); - - HRESULT DispatchWpdMessage(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - HRESULT OnSaveClientInfo(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetObjectIDsFromPersistentUniqueIDs(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -public: // IUnknown - ULONG __stdcall AddRef(); - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release(); - - HRESULT __stdcall QueryInterface(REFIID riid, void** ppv); - -private: - WpdObjectEnumerator m_ObjectEnum; - WpdObjectProperties m_ObjectProperties; - WpdObjectPropertiesBulk m_ObjectPropertiesBulk; - WpdObjectResources m_ObjectResources; - WpdObjectManagement m_ObjectManagement; - WpdCapabilities m_Capabilities; - WpdStorage m_Storage; - WpdNetworkConfig m_NetworkConfig; - FakeDevice m_FakeDevice; - CComPtr<IPortableDeviceClassExtension> m_pPortableDeviceClassExtension; - ULONG m_cRef; -}; - diff --git a/wpd/WpdWudfSampleDriver/WpdCapabilities.cpp b/wpd/WpdWudfSampleDriver/WpdCapabilities.cpp deleted file mode 100644 index 1656eaf4..00000000 --- a/wpd/WpdWudfSampleDriver/WpdCapabilities.cpp +++ /dev/null @@ -1,899 +0,0 @@ -#include "stdafx.h" -#include "WpdCapabilities.tmh" - -const PROPERTYKEY* g_SupportedCommands[] = -{ - // WPD_CATEGORY_OBJECT_ENUMERATION - &WPD_COMMAND_OBJECT_ENUMERATION_START_FIND, - &WPD_COMMAND_OBJECT_ENUMERATION_FIND_NEXT, - &WPD_COMMAND_OBJECT_ENUMERATION_END_FIND, - - // WPD_CATEGORY_OBJECT_MANAGEMENT - &WPD_COMMAND_OBJECT_MANAGEMENT_DELETE_OBJECTS, - &WPD_COMMAND_OBJECT_MANAGEMENT_CREATE_OBJECT_WITH_PROPERTIES_ONLY, - &WPD_COMMAND_OBJECT_MANAGEMENT_CREATE_OBJECT_WITH_PROPERTIES_AND_DATA, - &WPD_COMMAND_OBJECT_MANAGEMENT_WRITE_OBJECT_DATA, - &WPD_COMMAND_OBJECT_MANAGEMENT_COMMIT_OBJECT, - &WPD_COMMAND_OBJECT_MANAGEMENT_REVERT_OBJECT, - &WPD_COMMAND_OBJECT_MANAGEMENT_MOVE_OBJECTS, - &WPD_COMMAND_OBJECT_MANAGEMENT_COPY_OBJECTS, - &WPD_COMMAND_OBJECT_MANAGEMENT_UPDATE_OBJECT_WITH_PROPERTIES_AND_DATA, - - // WPD_CATEGORY_OBJECT_PROPERTIES - &WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED, - &WPD_COMMAND_OBJECT_PROPERTIES_GET, - &WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL, - &WPD_COMMAND_OBJECT_PROPERTIES_SET, - &WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES, - &WPD_COMMAND_OBJECT_PROPERTIES_DELETE, - - // WPD_CATEGORY_OBJECT_PROPERTIES_BULK - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_START, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_NEXT, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_END, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_START, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_NEXT, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_END, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_START, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_NEXT, - &WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_END, - - // WPD_CATEGORY_OBJECT_RESOURCES - &WPD_COMMAND_OBJECT_RESOURCES_GET_SUPPORTED, - &WPD_COMMAND_OBJECT_RESOURCES_GET_ATTRIBUTES, - &WPD_COMMAND_OBJECT_RESOURCES_OPEN, - &WPD_COMMAND_OBJECT_RESOURCES_READ, - &WPD_COMMAND_OBJECT_RESOURCES_WRITE, - &WPD_COMMAND_OBJECT_RESOURCES_CLOSE, - &WPD_COMMAND_OBJECT_RESOURCES_DELETE, - &WPD_COMMAND_OBJECT_RESOURCES_SEEK, - - // WPD_CATEGORY_CAPABILITIES - &WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS, - &WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS, - &WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES, - &WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS, - &WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES, - &WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS, - &WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES, - &WPD_COMMAND_CAPABILITIES_GET_FIXED_PROPERTY_ATTRIBUTES, - - // WPD_CATEGORY_STORAGE - &WPD_COMMAND_STORAGE_FORMAT, - - // WPD_CATEGORY_NETWORK_CONFIGURATION - &WPD_COMMAND_PROCESS_WIRELESS_PROFILE, -}; - -const GUID* g_SupportedFunctionalCategories[] = -{ - &WPD_FUNCTIONAL_CATEGORY_DEVICE, - &WPD_FUNCTIONAL_CATEGORY_STORAGE, - &WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, - &WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, -}; - -const GUID* g_SupportedEvents[] = -{ - &WPD_EVENT_OBJECT_ADDED, - &WPD_EVENT_OBJECT_REMOVED, - &WPD_EVENT_OBJECT_UPDATED, -}; - -typedef struct _FunctionalCategoryContentTypePair -{ - const GUID* FunctionalCategory; - const GUID* ContentType; -} FunctionalCategoryContentTypePair; - -const FunctionalCategoryContentTypePair g_CategoryContentTypePairs[] = -{ - {&WPD_FUNCTIONAL_CATEGORY_STORAGE, &WPD_CONTENT_TYPE_UNSPECIFIED}, - {&WPD_FUNCTIONAL_CATEGORY_STORAGE, &WPD_CONTENT_TYPE_FOLDER}, - {&WPD_FUNCTIONAL_CATEGORY_STORAGE, &WPD_CONTENT_TYPE_AUDIO}, - {&WPD_FUNCTIONAL_CATEGORY_STORAGE, &WPD_CONTENT_TYPE_VIDEO}, - {&WPD_FUNCTIONAL_CATEGORY_STORAGE, &WPD_CONTENT_TYPE_IMAGE}, - {&WPD_FUNCTIONAL_CATEGORY_STORAGE, &WPD_CONTENT_TYPE_CONTACT}, - {&WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, &WPD_CONTENT_TYPE_NETWORK_ASSOCIATION}, - {&WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, &WPD_CONTENT_TYPE_WIRELESS_PROFILE}, -}; - -typedef struct _ContentTypeFormatPair -{ - const GUID* ContentType; - const GUID* Format; -} ContentTypeFormatPair; - -const ContentTypeFormatPair g_ContentTypeFormatPairs[] = -{ - {&WPD_CONTENT_TYPE_UNSPECIFIED, &WPD_OBJECT_FORMAT_UNSPECIFIED}, - {&WPD_CONTENT_TYPE_UNSPECIFIED, &FakeContent_Format}, - {&WPD_CONTENT_TYPE_FOLDER, &FakeContent_Format}, - {&WPD_CONTENT_TYPE_AUDIO, &WPD_OBJECT_FORMAT_WMA}, - {&WPD_CONTENT_TYPE_VIDEO, &WPD_OBJECT_FORMAT_WMV}, - {&WPD_CONTENT_TYPE_IMAGE, &WPD_OBJECT_FORMAT_EXIF}, - {&WPD_CONTENT_TYPE_CONTACT, &WPD_OBJECT_FORMAT_VCARD2}, - {&WPD_CONTENT_TYPE_NETWORK_ASSOCIATION, &WPD_OBJECT_FORMAT_NETWORK_ASSOCIATION}, - {&WPD_CONTENT_TYPE_WIRELESS_PROFILE, &WPD_OBJECT_FORMAT_MICROSOFT_WFC}, -}; - -WpdCapabilities::WpdCapabilities() -{ - -} - -WpdCapabilities::~WpdCapabilities() -{ - -} - -HRESULT WpdCapabilities::Initialize(_In_ FakeDevice *pFakeDevice) -{ - - HRESULT hr = S_OK; - - if(pFakeDevice == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - m_pFakeDevice = pFakeDevice; - return hr; -} - - -HRESULT WpdCapabilities::DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (hr == S_OK) - { - if (Command.fmtid != WPD_CATEGORY_CAPABILITIES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS)) - { - hr = OnGetSupportedCommands(pParams, pResults); - CHECK_HR(hr, "Failed to get supported commands"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS)) - { - hr = OnGetCommandOptions(pParams, pResults); - CHECK_HR(hr, "Failed to get command options"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES)) - { - hr = OnGetFunctionalCategories(pParams, pResults); - CHECK_HR(hr, "Failed to get functional categories"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS)) - { - hr = OnGetFunctionalObjects(pParams, pResults); - CHECK_HR(hr, "Failed to get functional objects"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES)) - { - hr = OnGetSupportedContentTypes(pParams, pResults); - CHECK_HR(hr, "Failed to get supported content types"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS)) - { - hr = OnGetSupportedFormats(pParams, pResults); - CHECK_HR(hr, "Failed to get supported formats"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES)) - { - hr = OnGetSupportedFormatProperties(pParams, pResults); - CHECK_HR(hr, "Failed to get supported format properties"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_FIXED_PROPERTY_ATTRIBUTES)) - { - hr = OnGetFixedPropertyAttributes(pParams, pResults); - CHECK_HR(hr, "Failed to get fixed property attributes"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_EVENTS)) - { - hr = OnGetSupportedEvents(pParams, pResults); - CHECK_HR(hr, "Failed to get supported events"); - } - else if (IsEqualPropertyKey(Command, WPD_COMMAND_CAPABILITIES_GET_EVENT_OPTIONS)) - { - hr = OnGetEventOptions(pParams, pResults); - CHECK_HR(hr, "Failed to get event options"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return all commands supported by this driver should be returned as an - * IPortableDeviceKeyCollection in WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS. - * That includes custom commands, if any. - * Note that certain commands require a "command target" - * to function correctly (e.g. delete object), and it is understood that not all objects - * are necessarily valid targets (e.g. you cannot delete the device object). - */ -HRESULT WpdCapabilities::OnGetSupportedCommands( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - CComPtr<IPortableDeviceKeyCollection> pCommands; - UNREFERENCED_PARAMETER(pParams); - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pCommands); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - if (hr == S_OK) - { - // Add the supported commands - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedCommands); dwIndex++) - { - hr = pCommands->Add(*g_SupportedCommands[dwIndex]); - CHECK_HR(hr, "Failed to add supported command at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - } - - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS, pCommands); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_SUPPORTED_COMMANDS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_COMMAND_OPTIONS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_COMMAND: a collection of property keys containing a single value, - * which identifies the specific command options are requested to return. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS, containing - * the relevant options. If no options are available for this command, the driver should - * return an IPortableDeviceValues with no elements in it. - */ -HRESULT WpdCapabilities::OnGetCommandOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - PROPERTYKEY Command = WPD_PROPERTY_NULL; - - CComPtr<IPortableDeviceValues> pOptions; - - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_CAPABILITIES_COMMAND, &Command); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_COMMAND"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pOptions); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - // Check for command options - if (IsEqualPropertyKey(WPD_COMMAND_OBJECT_MANAGEMENT_DELETE_OBJECTS, Command)) - { - // This driver does not support recursive deletion - hr = pOptions->SetBoolValue(WPD_OPTION_OBJECT_MANAGEMENT_RECURSIVE_DELETE_SUPPORTED, FALSE); - CHECK_HR(hr, "Failed to set WPD_OPTION_OBJECT_MANAGEMENT_RECURSIVE_DELETE_SUPPORTED"); - } - else if (IsEqualPropertyKey(WPD_COMMAND_OBJECT_RESOURCES_SEEK, Command)) - { - // This driver supports Seek on resources opened for Read access - hr = pOptions->SetBoolValue(WPD_OPTION_OBJECT_RESOURCES_SEEK_ON_READ_SUPPORTED, TRUE); - CHECK_HR(hr, "Failed to set WPD_OPTION_OBJECT_RESOURCES_SEEK_ON_READ_SUPPORTED"); - - if (hr == S_OK) - { - // This driver does not support Seek on resources opened for WRITE access - hr = pOptions->SetBoolValue(WPD_OPTION_OBJECT_RESOURCES_SEEK_ON_WRITE_SUPPORTED, FALSE); - CHECK_HR(hr, "Failed to set WPD_OPTION_OBJECT_RESOURCES_SEEK_ON_WRITE_SUPPORTED"); - } - } - else if (IsEqualPropertyKey(WPD_COMMAND_OBJECT_RESOURCES_READ, Command)) - { - // For better read performance, tell the API not to provide the input buffer parameter - // when issuing a WPD_COMMAND_OBJECT_RESOURCES_READ command. - hr = pOptions->SetBoolValue(WPD_OPTION_OBJECT_RESOURCES_NO_INPUT_BUFFER_ON_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_OPTION_OBJECT_RESOURCES_NO_INPUT_BUFFER_ON_READ"); - } - } - - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS, pOptions); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_COMMAND_OPTIONS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FUNCTIONAL_CATEGORIES - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_CLSID) in - * WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES, containing - * the supported functional categories for this device. - */ -HRESULT WpdCapabilities::OnGetFunctionalCategories( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - CComPtr<IPortableDevicePropVariantCollection> pFunctionalCategories; - - UNREFERENCED_PARAMETER(pParams); - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFunctionalCategories); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - if (hr == S_OK) - { - // Add the supported functional categories - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedFunctionalCategories); dwIndex++) - { - PROPVARIANT pv = {0}; - - PropVariantInit(&pv); - - // Don't call PropVariantClear, since we did not allocate the memory for this GUID - pv.vt = VT_CLSID; - pv.puuid = (GUID*) g_SupportedFunctionalCategories[dwIndex]; - - hr = pFunctionalCategories->Add(&pv); - CHECK_HR(hr, "Failed to add supported functional category at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - } - - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES, pFunctionalCategories); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORIES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_FUNCTIONAL_OBJECTS - * command. It is sent when the caller is interesting in finding the object IDs for all - * functional objects belonging to the specified functional category. - * Note: the number of functional objects is expected to be very small (less than 8 for the - * whole device). - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY - a GUID value containing the category - * the caller is looking for. If the value is WPD_FUNCTIONAL_CATEGORY_ALL, then the driver - * must return all functional objects, no matter which category they belong to. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_LPWSTR) in - * WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS, containing - * the ids of the functional objects who belong to the specified functional category. - * If there are no objects in the specified category, the driver should return an - * empty collection. - */ -HRESULT WpdCapabilities::OnGetFunctionalObjects( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidFunctionalCategory = GUID_NULL; - - CComPtr<IPortableDevicePropVariantCollection> pFunctionalObjects; - - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY, &guidFunctionalCategory); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY"); - } - - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFunctionalObjects); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - if (hr == S_OK) - { - PROPVARIANT pv = {0}; - - PropVariantInit(&pv); - - - if ((guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_STORAGE) || - (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_ALL)) - { - pv.vt = VT_LPWSTR; - pv.pwszVal = STORAGE1_OBJECT_ID; - hr = pFunctionalObjects->Add(&pv); - CHECK_HR(hr, "Failed to add %ws object ID", STORAGE1_OBJECT_ID); - - if (hr == S_OK) - { - pv.pwszVal = STORAGE2_OBJECT_ID; - hr = pFunctionalObjects->Add(&pv); - CHECK_HR(hr, "Failed to add %ws object ID", STORAGE2_OBJECT_ID); - } - } - if ((guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION) || - (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_ALL)) - { - pv.vt = VT_LPWSTR; - pv.pwszVal = RENDERING_INFORMATION_OBJECT_ID; - hr = pFunctionalObjects->Add(&pv); - CHECK_HR(hr, "Failed to add %ws object ID", RENDERING_INFORMATION_OBJECT_ID); - } - if ((guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_DEVICE) || - (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_ALL)) - { - pv.vt = VT_LPWSTR; - pv.pwszVal = WPD_DEVICE_OBJECT_ID; - hr = pFunctionalObjects->Add(&pv); - CHECK_HR(hr, "Failed to add %ws object ID", WPD_DEVICE_OBJECT_ID); - } - if ((guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION) || - (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_ALL)) - { - pv.vt = VT_LPWSTR; - pv.pwszVal = NETWORK_CONFIG_OBJECT_ID; - hr = pFunctionalObjects->Add(&pv); - CHECK_HR(hr, "Failed to add %ws object ID", NETWORK_CONFIG_OBJECT_ID); - } - } - - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS, pFunctionalObjects); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_OBJECTS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_CONTENT_TYPES - * command. This message is sent when the client needs to know the possible content types supported - * by the specified functional category. - * If the driver has multiple functional objects that may support different content types, - * the driver should simply merge them together and report all possible types in one list here. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY - a GUID value containing the functional category - * whose content types the caller is interested in. If the value is WPD_FUNCTIONAL_CATEGORY_ALL, then the driver - * must return a list of all content types supported by the device. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_CLSID) in - * WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES, containing - * the content types supported by the specified functional category. - * If there are no objects in the specified category, the driver should return an - * empty collection. - */ -HRESULT WpdCapabilities::OnGetSupportedContentTypes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidFunctionalCategory = GUID_NULL; - - CComPtr<IPortableDevicePropVariantCollection> pContentTypes; - - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY, &guidFunctionalCategory); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FUNCTIONAL_CATEGORY"); - } - - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pContentTypes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - if (hr == S_OK) - { - PROPVARIANT pv = {0}; - - PropVariantInit(&pv); - - for(DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_CategoryContentTypePairs); dwIndex++) - { - pv.vt = VT_CLSID; - if ((*g_CategoryContentTypePairs[dwIndex].FunctionalCategory == guidFunctionalCategory) || - (guidFunctionalCategory == WPD_FUNCTIONAL_CATEGORY_ALL)) - { - pv.puuid = (CLSID*)g_CategoryContentTypePairs[dwIndex].ContentType; - hr = pContentTypes->Add(&pv); - CHECK_HR(hr, "Failed to add content type"); - } - // Don't clear the PropVariant since we don't own the memory for the GUIDs - } - } - - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES, pContentTypes); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_CONTENT_TYPES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMATS - * command. This message is sent when the client needs to know the possible formats supported - * by the specified content type (e.g. for image objects, the driver may choose to support JPEG and BMP files). - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_CONTENT_TYPE - a GUID value containing the content type - * whose formats the caller is interested in. If the value is WPD_CONTENT_TYPE_ALL, then the driver - * must return a list of all formats supported by the device. - * - * The driver should: - * - Return an IPortableDevicePropVariantCollection (of type VT_CLSID) in - * WPD_PROPERTY_CAPABILITIES_FORMATS, indicating the formats supported by the - * specified content type. - * If there are no formats supported by the specified content type, the driver should return an - * empty collection. - */ -HRESULT WpdCapabilities::OnGetSupportedFormats( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidContentType = GUID_NULL; - - CComPtr<IPortableDevicePropVariantCollection> pFormats; - - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_CONTENT_TYPE, &guidContentType); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_CONTENT_TYPE"); - } - - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFormats); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - if (hr == S_OK) - { - PROPVARIANT pv = {0}; - - PropVariantInit(&pv); - - for(DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_ContentTypeFormatPairs); dwIndex++) - { - pv.vt = VT_CLSID; - if ((*g_ContentTypeFormatPairs[dwIndex].ContentType == guidContentType) || - (guidContentType == WPD_CONTENT_TYPE_ALL)) - { - // Don't add duplicates. Some formats appear under more than one content type - if(!ExistsInCollection(*g_ContentTypeFormatPairs[dwIndex].Format, pFormats)) - { - pv.puuid = (CLSID*)g_ContentTypeFormatPairs[dwIndex].Format; - hr = pFormats->Add(&pv); - CHECK_HR(hr, "Failed to add Format"); - } - } - // Don't clear the PropVariant since we don't own the memory for the GUIDs - } - } - - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_FORMATS, pFormats); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_FORMATS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_FORMAT_PROPERTIES - * command. This message is sent when the client needs to know the typical properties for objects of - * a given format. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FORMAT - a GUID value specifying the format the caller is interested in. - * - * The driver should: - * - Return an IPortableDeviceKeyCollection in WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS, - * containing the property keys. - */ -HRESULT WpdCapabilities::OnGetSupportedFormatProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidObjectFormat = GUID_NULL; - - CComPtr<IPortableDeviceKeyCollection> pPropertyKeys; - - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FORMAT, &guidObjectFormat); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FORMAT"); - } - - if (hr == S_OK) - { - hr = AddSupportedProperties(guidObjectFormat, &pPropertyKeys); - CHECK_HR(hr, "Failed to add supported properties for %ws", (LPWSTR)CComBSTR(guidObjectFormat)); - } - - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS, pPropertyKeys); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_FIXED_PROPERTY_ATTRIBUTES - * command. This message is sent when the client needs to know the the property attributes that - * are the same for all objects of the given format. - * - * Typically, a driver treats objects of a given format the same. Many properties therefore will - * have attributes that are identical across all objects of that format. - * These can be returned here. There are some attributes which may be differ per object instance, - * which are not returned here. - * See WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_FORMAT - a GUID value specifying the format the caller is interested in. - * - WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS - a collection of property keys containing a single value, - * which is the key identifying the specific property attributes we are requested to return. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES - * containing the fixed property attributes. - */ -HRESULT WpdCapabilities::OnGetFixedPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID guidObjectFormat = GUID_NULL; - PROPERTYKEY key = WPD_PROPERTY_NULL; - - CComPtr<IPortableDeviceValues> pAttributes; - - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_FORMAT, &guidObjectFormat); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_FORMAT"); - } - - if(hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS, &key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_PROPERTY_KEYS"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = AddFixedPropertyAttributes(guidObjectFormat, key, pAttributes); - CHECK_HR(hr, "Failed to add fixed property attributes for format %ws and key %ws.%d", CComBSTR(guidObjectFormat), CComBSTR(key.fmtid), key.pid); - } - - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES, pAttributes); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_PROPERTY_ATTRIBUTES"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_EVENTS - * command. - * - * The parameters sent to us are: - * - none. - * - * The driver should: - * - Return all events supported by this driver should be returned as an - * IPortableDeviceKeyCollection in WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS. - * That includes custom commands, if any. - */ -HRESULT WpdCapabilities::OnGetSupportedEvents( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - CComPtr<IPortableDevicePropVariantCollection> pEvents; - UNREFERENCED_PARAMETER(pParams); - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pEvents); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - } - - if (hr == S_OK) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - - pv.vt = VT_CLSID; - // Add the supported events - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_SupportedEvents); dwIndex++) - { - pv.puuid = (CLSID*) g_SupportedEvents[dwIndex]; - hr = pEvents->Add(&pv); - CHECK_HR(hr, "Failed to add supported events at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - } - - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS, pEvents); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_SUPPORTED_EVENTS"); - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_CAPABILITIES_GET_EVENT_OPTIONS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_CAPABILITIES_EVENT: a GUID value indicating the Event whose options should be returned. - * - * The driver should: - * - Return an IPortableDeviceValues in WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS, containing - * the relevant options. - */ -HRESULT WpdCapabilities::OnGetEventOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - GUID Event = GUID_NULL; - - CComPtr<IPortableDeviceValues> pOptions; - - if (hr == S_OK) - { - hr = pParams->GetGuidValue(WPD_PROPERTY_CAPABILITIES_EVENT, &Event); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_CAPABILITIES_EVENT"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pOptions); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - // Check for the events we support - if ((Event == WPD_EVENT_OBJECT_ADDED) || - (Event == WPD_EVENT_OBJECT_REMOVED) || - (Event == WPD_EVENT_OBJECT_UPDATED)) - { - // These events are boradcast events - hr = pOptions->SetBoolValue(WPD_EVENT_OPTION_IS_BROADCAST_EVENT, TRUE); - CHECK_HR(hr, "Failed to set WPD_EVENT_OPTION_IS_BROADCAST_EVENT"); - } - - } - - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS, pOptions); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_CAPABILITIES_EVENT_OPTIONS"); - } - - return hr; -} - - diff --git a/wpd/WpdWudfSampleDriver/WpdCapabilities.h b/wpd/WpdWudfSampleDriver/WpdCapabilities.h deleted file mode 100644 index 15a96261..00000000 --- a/wpd/WpdWudfSampleDriver/WpdCapabilities.h +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once - -class WpdCapabilities -{ -public: - WpdCapabilities(); - ~WpdCapabilities(); - - HRESULT Initialize( - _In_ FakeDevice *pFakeDevice); - - HRESULT DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedCommands( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetCommandOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFunctionalCategories( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFunctionalObjects( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedContentTypes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedFormats( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedFormatProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetFixedPropertyAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedEvents( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetEventOptions( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - FakeDevice* m_pFakeDevice; -}; - diff --git a/wpd/WpdWudfSampleDriver/WpdNetworkConfig.cpp b/wpd/WpdWudfSampleDriver/WpdNetworkConfig.cpp deleted file mode 100644 index c09f7c25..00000000 --- a/wpd/WpdWudfSampleDriver/WpdNetworkConfig.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include "stdafx.h" -#include "WpdNetworkConfig.tmh" - -WpdNetworkConfig::WpdNetworkConfig() -{ - -} - -WpdNetworkConfig::~WpdNetworkConfig() -{ - -} - -HRESULT WpdNetworkConfig::Initialize(_In_ FakeDevice *pFakeDevice) -{ - HRESULT hr = S_OK; - - if(pFakeDevice == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - m_pFakeDevice = pFakeDevice; - return hr; -} - - -HRESULT WpdNetworkConfig::DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (hr == S_OK) - { - if (Command.fmtid != WPD_CATEGORY_NETWORK_CONFIGURATION) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - } - - if (hr == S_OK) - { - if(IsEqualPropertyKey(Command, WPD_COMMAND_PROCESS_WIRELESS_PROFILE)) - { - hr = OnProcessWFCObject(pParams, pResults); - CHECK_HR(hr, "Failed to commit WFC file"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - - - -/** - * This method is called when we receive a WPD_COMMAND_PROCESS_WIRELESS_PROFILE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_ID: identifies the object to process. - * - * The driver should: - * - - */ -HRESULT WpdNetworkConfig::OnProcessWFCObject( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszObjectID = NULL; - - UNREFERENCED_PARAMETER(pResults); - - // Get the Object ID - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &pszObjectID); - if (hr == S_OK) - { - FakeContent* pElement = NULL; - - // Check if the object exists - if(m_pFakeDevice->GetContent(pszObjectID, &pElement)) - { - // Check if the object is of the proper content type - if (IsEqualGUID(pElement->ContentType, WPD_CONTENT_TYPE_WIRELESS_PROFILE)) - { - BYTE Buffer[16]; - DWORD dwNumBytesRead = 0; - - // Perform minimal validation on the object contents (just read some bytes for this sample) - hr = pElement->ReadData(WPD_RESOURCE_DEFAULT, 0, Buffer, sizeof(Buffer), &dwNumBytesRead); - CHECK_HR(hr, "Failed to read resource data for %ws.%d", CComBSTR(WPD_RESOURCE_DEFAULT.fmtid), WPD_RESOURCE_DEFAULT.pid); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID for OnProcessWFCObject [%ws]", pszObjectID); - } - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Invalid ObjectID [%ws]", pszObjectID); - } - - CoTaskMemFree(pszObjectID); - } - else - { - CHECK_HR(hr, "Missing or invalid value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - return hr; -} - - diff --git a/wpd/WpdWudfSampleDriver/WpdNetworkConfig.h b/wpd/WpdWudfSampleDriver/WpdNetworkConfig.h deleted file mode 100644 index 9aa94ea9..00000000 --- a/wpd/WpdWudfSampleDriver/WpdNetworkConfig.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -class WpdNetworkConfig -{ -public: - WpdNetworkConfig(); - ~WpdNetworkConfig(); - - HRESULT Initialize(_In_ FakeDevice *pFakeDevice); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - - HRESULT OnProcessWFCObject(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); -private: - FakeDevice* m_pFakeDevice; -}; - diff --git a/wpd/WpdWudfSampleDriver/WpdObjectEnum.cpp b/wpd/WpdWudfSampleDriver/WpdObjectEnum.cpp deleted file mode 100644 index d67e6c5d..00000000 --- a/wpd/WpdWudfSampleDriver/WpdObjectEnum.cpp +++ /dev/null @@ -1,386 +0,0 @@ -#include "stdafx.h" -#include "WpdObjectEnum.tmh" - -WpdObjectEnumerator::WpdObjectEnumerator() -{ - -} - -WpdObjectEnumerator::~WpdObjectEnumerator() -{ - -} - -HRESULT WpdObjectEnumerator::Initialize(_In_ FakeDevice *pFakeDevice) -{ - HRESULT hr = S_OK; - - if(pFakeDevice == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - m_pFakeDevice = pFakeDevice; - - return hr; -} - -HRESULT WpdObjectEnumerator::DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (hr == S_OK) - { - if (Command.fmtid != WPD_CATEGORY_OBJECT_ENUMERATION) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - } - - if (hr == S_OK) - { - if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_START_FIND.pid) - { - hr = OnStartFind(pParams, pResults); - CHECK_HR(hr, "Failed to begin enumeration"); - } - else if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_FIND_NEXT.pid) - { - hr = OnFindNext(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to find next object"); - } - } - else if (Command.pid == WPD_COMMAND_OBJECT_ENUMERATION_END_FIND.pid) - { - hr = OnEndFind(pParams, pResults); - CHECK_HR(hr, "Failed to end enumeration"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_ENUMERATION_START_FIND - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID: the parent where we should start - * the enumeration. - * - WPD_PROPERTY_OBJECT_ENUMERATION_FILTER: the filter to use when doing - * enumeration. Since this parameter is optional, it may not exist. - * This driver currently ignores the filter parameter. - * - * The driver should: - * - Create a new context for this enumeration. - * - Return an identifier for the context in WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT. - * - */ -HRESULT WpdObjectEnumerator::OnStartFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszParentID = NULL; - LPWSTR pszEnumContext = NULL; - IUnknown* pContextMap = NULL; - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID, &pszParentID); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_PARENT_ID"); - } - - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, &pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - hr = CreateEnumContext((ContextMap*)pContextMap, pszParentID, &pszEnumContext); - CHECK_HR(hr, "Failed to create enumeration context"); - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, pszEnumContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszParentID); - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszEnumContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -HRESULT WpdObjectEnumerator::OnFindNext(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszEnumContext = NULL; - DWORD dwNumObjects = 0; - ContextMap* pContextMap = NULL; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDCollection; - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, &pszEnumContext); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - if (SUCCEEDED(hr)) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_ENUMERATION_NUM_OBJECTS_REQUESTED, &dwNumObjects); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_NUM_OBJECTS_REQUESTED"); - } - } - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - // Find the next objects in the enumeration - hr = GetObjectIDs(pContextMap, dwNumObjects, pszEnumContext, &pObjectIDCollection); - CHECK_HR(hr, "Failed to get the objectIDs"); - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_ENUMERATION_OBJECT_IDS, pObjectIDCollection); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_ENUMERATION_OBJECT_IDS"); - } - - if (SUCCEEDED(hr)) - { - if(pObjectIDCollection != NULL) - { - ULONG ulCount = 0; - - pObjectIDCollection->GetCount(&ulCount); - if(ulCount < dwNumObjects) - { - hr = S_FALSE; - } - } - } - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszEnumContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_ENUMERATION_END_FIND - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT: the context the driver returned to - * the client in OnStartFind. - * - * The driver should: - * - Destroy any resources associated with this context. - */ -HRESULT WpdObjectEnumerator::OnEndFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszEnumContext = NULL; - IUnknown* pContextMap = NULL; - - UNREFERENCED_PARAMETER(pResults); - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT, &pszEnumContext); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_ENUMERATION_CONTEXT"); - } - - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, &pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - hr = DestroyEnumContext((ContextMap*) pContextMap, pszEnumContext); - CHECK_HR(hr, "Failed to destroy enumeration context"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszEnumContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -HRESULT WpdObjectEnumerator::CreateEnumContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszParentID, - _Outptr_result_nullonfailure_ LPWSTR* ppszEnumContext) -{ - HRESULT hr = S_OK; - GUID guidContext = GUID_NULL; - CComBSTR bstrContext; - EnumContext* pContext = NULL; - - if((pContextMap == NULL) || - (pszParentID == NULL) || - (ppszEnumContext == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *ppszEnumContext = NULL; - - hr = CoCreateGuid(&guidContext); - if (SUCCEEDED(hr)) - { - bstrContext = guidContext; - if(bstrContext.Length() == 0) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to create BSTR from GUID"); - } - } - - if (SUCCEEDED(hr)) - { - pContext = new EnumContext(); - if(pContext != NULL) - { - CAtlStringW strKey = bstrContext; - pContext->ParentID = pszParentID; - - hr = pContextMap->Add(strKey, pContext); - CHECK_HR(hr, "Failed to add enumeration context to client context map"); - - pContext->Release(); - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate enumeration context"); - } - } - - if (SUCCEEDED(hr)) - { - *ppszEnumContext = AtlAllocTaskWideString(bstrContext); - } - - return hr; -} - -HRESULT WpdObjectEnumerator::DestroyEnumContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszEnumContext) -{ - HRESULT hr = S_OK; - - CAtlStringW strKey = pszEnumContext; - pContextMap->Remove(strKey); - - return hr; -} - -#pragma warning(suppress: 6388) // PREFast bug means here there is a false positive for the call to CComPtr<>::QueryInterface(). -HRESULT WpdObjectEnumerator::GetObjectIDs( - _In_ ContextMap* pContextMap, - _In_ const DWORD dwNumObjects, - _In_ LPCWSTR pszEnumContext, - _COM_Outptr_ IPortableDevicePropVariantCollection** ppCollection) -{ - HRESULT hr = S_OK; - EnumContext* pContext = NULL; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - - if(ppCollection == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL collection parameter"); - return hr; - } - - *ppCollection = NULL; - - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_PPV_ARGS(&pObjectIDs)); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDevicePropVariantCollection"); - - if (SUCCEEDED(hr)) - { - CAtlStringW strKey = pszEnumContext; - pContext = (EnumContext*) pContextMap->GetContext(strKey); - if(pContext != NULL) - { - for(DWORD dwCount = 0; dwCount < dwNumObjects; dwCount++) - { - CAtlStringW strObjectID; - - DWORD dwNextStartIndex = 0; - if(m_pFakeDevice->FindNext(pContext->SearchIndex, - pContext->ParentID, - strObjectID, - &dwNextStartIndex)) - { - PropVariantWrapper pvObjectID(strObjectID); - - hr = pObjectIDs->Add(&pvObjectID); - CHECK_HR(hr, "Failed to add object [%ws]", pvObjectID.pwszVal); - pContext->SearchIndex = dwNextStartIndex; - } - } - - pContext->Release(); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Cannot find enum context [%ws]", pszEnumContext); - } - } - - if (SUCCEEDED(hr)) - { - hr = pObjectIDs->QueryInterface(IID_PPV_ARGS(ppCollection)); - CHECK_HR(hr, "Failed to QI for IID_IPortableDevicePropVariantCollection on IPortableDevicePropVariantCollection"); - } - return hr; -} - diff --git a/wpd/WpdWudfSampleDriver/WpdObjectEnum.h b/wpd/WpdWudfSampleDriver/WpdObjectEnum.h deleted file mode 100644 index a7cc4c02..00000000 --- a/wpd/WpdWudfSampleDriver/WpdObjectEnum.h +++ /dev/null @@ -1,105 +0,0 @@ -#pragma once - -// This class is used to store the context for a specific enumeration. -// Currrently, this is done by storing the object index. -class EnumContext : public IUnknown -{ -public: - EnumContext() : - m_cRef(1), - SearchIndex(0) - { - - } - - ~EnumContext() - { - - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -public: - DWORD SearchIndex; - CAtlStringW ParentID; -private: - DWORD m_cRef; -}; - -class WpdObjectEnumerator -{ -public: - WpdObjectEnumerator(); - ~WpdObjectEnumerator(); - - HRESULT Initialize(_In_ FakeDevice *pFakeDevice); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnStartFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnFindNext(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnEndFind(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - HRESULT CreateEnumContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszParentID, - _Outptr_result_nullonfailure_ LPWSTR* ppszEnumContext); - - HRESULT DestroyEnumContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszEnumContext); - - HRESULT GetObjectIDs( - _In_ ContextMap* pContextMap, - _In_ const DWORD dwNumObjects, - _In_ LPCWSTR pszEnumContext, - _COM_Outptr_ IPortableDevicePropVariantCollection** ppCollection); - - FakeDevice* m_pFakeDevice; -}; diff --git a/wpd/WpdWudfSampleDriver/WpdObjectManagement.cpp b/wpd/WpdWudfSampleDriver/WpdObjectManagement.cpp deleted file mode 100644 index 9c3d22b2..00000000 --- a/wpd/WpdWudfSampleDriver/WpdObjectManagement.cpp +++ /dev/null @@ -1,1160 +0,0 @@ -#include "stdafx.h" -#include "WpdObjectManagement.tmh" - -WpdObjectManagement::WpdObjectManagement() -{ - -} - -WpdObjectManagement::~WpdObjectManagement() -{ - -} - -HRESULT WpdObjectManagement::Initialize(_In_ FakeDevice *pFakeDevice) -{ - HRESULT hr = S_OK; - - if(pFakeDevice == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - m_pFakeDevice = pFakeDevice; - - return hr; -} - -HRESULT WpdObjectManagement::DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (hr == S_OK) - { - if (Command.fmtid != WPD_CATEGORY_OBJECT_MANAGEMENT) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - } - - if (hr == S_OK) - { - if (Command.pid == WPD_COMMAND_OBJECT_MANAGEMENT_DELETE_OBJECTS.pid) - { - hr = OnDelete(pParams, pResults); - CHECK_HR(hr, "Failed to delete object"); - } - else if (Command.pid == WPD_COMMAND_OBJECT_MANAGEMENT_CREATE_OBJECT_WITH_PROPERTIES_ONLY.pid) - { - hr = OnCreateObjectWithPropertiesOnly(pParams, pResults); - CHECK_HR(hr, "Failed to create object"); - } - else if (Command.pid == WPD_COMMAND_OBJECT_MANAGEMENT_CREATE_OBJECT_WITH_PROPERTIES_AND_DATA.pid) - { - hr = OnCreateObjectWithPropertiesAndData(pParams, pResults); - CHECK_HR(hr, "Failed to create object"); - } - else if (Command.pid == WPD_COMMAND_OBJECT_MANAGEMENT_WRITE_OBJECT_DATA.pid) - { - hr = OnWriteObjectData(pParams, pResults); - CHECK_HR(hr, "Failed to write object data"); - } - else if (Command.pid == WPD_COMMAND_OBJECT_MANAGEMENT_COMMIT_OBJECT.pid) - { - hr = OnCommit(pParams, pResults); - CHECK_HR(hr, "Failed to commit object"); - } - else if (Command.pid == WPD_COMMAND_OBJECT_MANAGEMENT_REVERT_OBJECT.pid) - { - hr = OnRevert(pParams, pResults); - CHECK_HR(hr, "Failed to revert object"); - } - else if (Command.pid == WPD_COMMAND_OBJECT_MANAGEMENT_MOVE_OBJECTS.pid) - { - hr = OnMove(pParams, pResults); - CHECK_HR(hr, "Failed to Move objects"); - } - else if (Command.pid == WPD_COMMAND_OBJECT_MANAGEMENT_COPY_OBJECTS.pid) - { - hr = OnCopy(pParams, pResults); - CHECK_HR(hr, "Failed to Copy objects"); - } - else if (Command.pid == WPD_COMMAND_OBJECT_MANAGEMENT_UPDATE_OBJECT_WITH_PROPERTIES_AND_DATA.pid) - { - hr = OnUpdateObjectWithPropertiesAndData(pParams, pResults); - CHECK_HR(hr, "Failed to update object"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_MANAGEMENT_DELETE_OBJECTS - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS: the ObjectIDs, indicating which objects to delete. These may - * contain children. - * - WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_OPTIONS: Flag parameter indicating delete options. Must be one - * of the following: - * - PORTABLE_DEVICE_DELETE_NO_RECURSION - Deletes the - * object only. This should fail if children exist. - * - PORTABLE_DEVICE_DELETE_WITH_RECURSION - Deletes this - * object and all children. - * - * The driver should: - * - If the flag is PORTABLE_DEVICE_DELETE_NO_RECURSION the driver should delete the - * specified object only. If the object still has children the driver should not delete - * the object and instead return HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION). - * - If the flag is PORTABLE_DEVICE_DELETE_WITH_RECURSION the driver should delete the - * specified object and all of its children. - * - Fill out the operation results in WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_RESULTS. It contains an IPortableDevicePropVariantCollection of - * VT_ERROR values indicating the success or failure of the operation for that element. - * Order is implicit, i.e. the first element of WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_RESULTS corresponds to the first element of WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS and so on. - * - The driver should return: - * - S_OK if all objects were deleted successfully. - * - S_FALSE if any object delete failed. - * - An error return indicates that the driver did not delete any objects, and - * WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_RESULTS is ignored. - */ -HRESULT WpdObjectManagement::OnDelete( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - DWORD dwOptions = PORTABLE_DEVICE_DELETE_NO_RECURSION; - BOOL bDeleteFailed = FALSE; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - CComPtr<IPortableDevicePropVariantCollection> pDeleteResults; - CComPtr<IPortableDeviceValues> pEventParams; - VARTYPE vt = VT_EMPTY; - - if (hr == S_OK) - { - hr = pParams->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS, &pObjectIDs); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS"); - } - - // Ensure that this is a collection of VT_LPWSTR - if (hr == S_OK) - { - hr = pObjectIDs->GetType(&vt); - CHECK_HR(hr, "Failed to get the VARTYP of WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS"); - if (hr == S_OK) - { - if (vt != VT_LPWSTR) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS is not a collection of VT_LPWSTR"); - } - } - } - - if (hr == S_OK) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_OPTIONS, &dwOptions); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_OPTIONS"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pDeleteResults); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDevicePropVariantCollection"); - } - - - if (hr == S_OK) - { - DWORD cObjects = 0; - // Loop through the object list and attempt to delete - hr = pObjectIDs->GetCount(&cObjects); - CHECK_HR(hr, "Failed to get number of objects to delete"); - - if (hr == S_OK) - { - for(DWORD dwIndex = 0; dwIndex < cObjects; dwIndex++) - { - HRESULT hrTemp = S_OK; - PROPVARIANT pv = {0}; - - PropVariantInit(&pv); - // Get the next Object to delete - hr = pObjectIDs->GetAt(dwIndex, &pv); - CHECK_HR(hr, "Failed to get next object id at index %d", dwIndex); - if (hr == S_OK) - { - pEventParams = NULL; - // Get the object properties used for sending the event. Ignore errors (these are expected in some cases - // e.g. app is sending object ID that doesn't exist), since this relates to the event, not the delete operation, - // and we return results for the delete (an error posting the event is non-fatal). - hrTemp = m_pFakeDevice->GetObjectPropertiesForEvent(pv.pwszVal, &pEventParams); - CHECK_HR(hrTemp, "Failed to get properties for event on object %ws", pv.pwszVal); - - HRESULT hrDelete = S_OK; - PROPVARIANT pvResult = {0}; - - PropVariantInit(&pvResult); - - hrDelete = m_pFakeDevice->DeleteObject(dwOptions, pv.pwszVal); - CHECK_HR(hrDelete, "Failed to delete object [%ws]", pv.pwszVal); - - if(FAILED(hrDelete)) - { - bDeleteFailed = TRUE; - } - - // Save this result - pvResult.vt = VT_ERROR; - pvResult.scode = hrDelete; - hrTemp = pDeleteResults->Add(&pvResult); - PropVariantClear(&pvResult); - CHECK_HR(hrTemp, "Failed to add result for [%ws] to list of results", pv.pwszVal); - - if ((hrDelete == S_OK) && (hrTemp == S_OK)) - { - HRESULT hrEvent = S_OK; - // Set the event-specific parameters - hrEvent = pEventParams->SetGuidValue(WPD_EVENT_PARAMETER_EVENT_ID, WPD_EVENT_OBJECT_REMOVED); - CHECK_HR(hrEvent, "Failed to add WPD_EVENT_PARAMETER_EVENT_ID"); - - // Send the Event - if (hrEvent == S_OK) - { - PostWpdEvent(pParams, pEventParams); - } - } - PropVariantClear(&pv); - } - else - { - break; - } - } - } - } - - // Set the results - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_RESULTS, pDeleteResults); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_MANAGEMENT_DELETE_RESULTS"); - } - - // If an object failed to delete, make sure we return S_FALSE - if ((hr == S_OK) && (bDeleteFailed)) - { - hr = S_FALSE; - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_MANAGEMENT_MOVE_OBJECTS - * command. - * - * This command will move the specified objects to the destination folder. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS : the ObjectIDs, indicating which objects to move. These may - * be folder objects. - * - WPD_PROPERTY_OBJECT_MANAGEMENT_DESTINATION_FOLDER_OBJECT_ID: Indicates the destination folder for the move operation. - * - * The driver should: - * - Attempt to Move the object specified in WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS to the folder specified in - * WPD_PROPERTY_OBJECT_MANAGEMENT_DESTINATION_FOLDER_OBJECT_ID. - * - Fill out the operation results in WPD_PROPERTY_OBJECT_MANAGEMENT_MOVE_RESULTS. It contains an IportableDevicePropVariantCollection of - * VT_ERROR values indicating the success or failure of the operation for that element. - * Order is implicit, i.e. the first element of WPD_PROPERTY_OBJECT_MANAGEMENT_MOVE_RESULTS corresponds to the first element of WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS and so on. - * - The driver should return: - * - S_OK if all objects were moved successfully. - * - S_FALSE if any object move failed. - * - An error return indicates that the driver did not move any objects, and - * WPD_PROPERTY_OBJECT_MANAGEMENT_MOVE_RESULTS is ignored. - */ -HRESULT WpdObjectManagement::OnMove( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszDestFolderObjectID = NULL; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - CComPtr<IPortableDevicePropVariantCollection> pMoveResults; - BOOL bMoveFailed = FALSE; - VARTYPE vt = VT_EMPTY; - - if (hr == S_OK) - { - hr = pParams->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS, &pObjectIDs); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS"); - } - - // Ensure that this is a collection of VT_LPWSTR - if (hr == S_OK) - { - hr = pObjectIDs->GetType(&vt); - CHECK_HR(hr, "Failed to get the VARTYP of WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS"); - if (hr == S_OK) - { - if (vt != VT_LPWSTR) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS is not a collection of VT_LPWSTR"); - } - } - } - - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_MANAGEMENT_DESTINATION_FOLDER_OBJECT_ID, &pszDestFolderObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_DESTINATION_FOLDER_OBJECT_ID"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pMoveResults); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDevicePropVariantCollection"); - } - - - if (hr == S_OK) - { - DWORD cObjects = 0; - // Loop through the object list and attempt to move - hr = pObjectIDs->GetCount(&cObjects); - CHECK_HR(hr, "Failed to get number of objects to move"); - - if (hr == S_OK) - { - for(DWORD dwIndex = 0; dwIndex < cObjects; dwIndex++) - { - HRESULT hrTemp = S_OK; - PROPVARIANT pv = {0}; - - PropVariantInit(&pv); - // Get the next Object to move - hrTemp = pObjectIDs->GetAt(dwIndex, &pv); - CHECK_HR(hr, "Failed to get next object id at index %d", dwIndex); - if (hrTemp == S_OK) - { - // Move this object - hrTemp = m_pFakeDevice->MoveObject(pv.pwszVal, pszDestFolderObjectID); - CHECK_HR(hrTemp, "Failed to move object [%ws] to folder [%ws]", pv.pwszVal, pszDestFolderObjectID); - - if(FAILED(hrTemp)) - { - bMoveFailed = TRUE; - } - - PROPVARIANT pvResult = {0}; - - PropVariantInit(&pvResult); - - // Save this result - pvResult.vt = VT_ERROR; - pvResult.scode = hrTemp; - hrTemp = pMoveResults->Add(&pvResult); - CHECK_HR(hrTemp, "Failed to add result for [%ws] to list of results", pv.pwszVal); - - PropVariantClear(&pvResult); - } - PropVariantClear(&pv); - } - } - } - - // Set the results - if (hr == S_OK) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_MANAGEMENT_MOVE_RESULTS, pMoveResults); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_MANAGEMENT_MOVE_RESULTS"); - } - - CoTaskMemFree(pszDestFolderObjectID); - - // If an object failed to move, make sure we return S_FALSE - if ((hr == S_OK) && (bMoveFailed)) - { - hr = S_FALSE; - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_MANAGEMENT_COPY_OBJECTS - * command. - * - * This command will copy the specified objects to the destination folder. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS : the ObjectIDs, indicating which objects to copy. These may - * be folder objects. - * - WPD_PROPERTY_OBJECT_MANAGEMENT_DESTINATION_FOLDER_OBJECT_ID: Indicates the destination folder for the copy operation. - * - * The driver should: - * - Attempt to copy the object specified in WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS to the folder specified in - * WPD_PROPERTY_OBJECT_MANAGEMENT_DESTINATION_FOLDER_OBJECT_ID. - * - Fill out the operation results in WPD_PROPERTY_OBJECT_MANAGEMENT_COPY_RESULTS. It contains an IPortableDevicePropVariantCollection of - * VT_ERROR values indicating the success or failure of the operation for that element. - * Order is implicit, i.e. the first element of WPD_PROPERTY_OBJECT_MANAGEMENT_COPY_RESULTS corresponds to the first element of WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS and so on. - * - The driver should return: - * - S_OK if all objects were copied successfully. - * - S_FALSE if any object copy failed. - * - An error return indicates that the driver did not copy any objects, and - * WPD_PROPERTY_OBJECT_MANAGEMENT_COPY_RESULTS is ignored. - */ -HRESULT WpdObjectManagement::OnCopy( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszDestFolderObjectID = NULL; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - CComPtr<IPortableDevicePropVariantCollection> pCopyResults; - BOOL bCopyFailed = FALSE; - VARTYPE vt = VT_EMPTY; - - hr = pParams->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS, &pObjectIDs); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS"); - - // Ensure that this is a collection of VT_LPWSTR - if (SUCCEEDED(hr)) - { - hr = pObjectIDs->GetType(&vt); - CHECK_HR(hr, "Failed to get the VARTYP of WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS"); - if (hr == S_OK) - { - if (vt != VT_LPWSTR) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_IDS is not a collection of VT_LPWSTR"); - } - } - } - - if (SUCCEEDED(hr)) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_MANAGEMENT_DESTINATION_FOLDER_OBJECT_ID, &pszDestFolderObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_DESTINATION_FOLDER_OBJECT_ID"); - } - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pCopyResults); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDevicePropVariantCollection"); - } - - - if (SUCCEEDED(hr)) - { - DWORD cObjects = 0; - // Loop through the object list and attempt to copy - hr = pObjectIDs->GetCount(&cObjects); - CHECK_HR(hr, "Failed to get number of objects to copy"); - - if (SUCCEEDED(hr)) - { - for(DWORD dwIndex = 0; dwIndex < cObjects; dwIndex++) - { - CComPtr<IPortableDeviceValues> pEventParams; - LPWSTR pszNewObjectID = NULL; - HRESULT hrTemp = S_OK; - PROPVARIANT pv = {0}; - - PropVariantInit(&pv); - // Get the next Object to copy - hrTemp = pObjectIDs->GetAt(dwIndex, &pv); - CHECK_HR(hr, "Failed to get next object id at index %d", dwIndex); - if (SUCCEEDED(hrTemp)) - { - // Copy this object - hrTemp = m_pFakeDevice->CopyObject(pv.pwszVal, pszDestFolderObjectID, &pszNewObjectID); - CHECK_HR(hrTemp, "Failed to copy object [%ws] to folder [%ws]", pv.pwszVal, pszDestFolderObjectID); - - if(FAILED(hrTemp)) - { - bCopyFailed = TRUE; - } - - PROPVARIANT pvResult = {0}; - - PropVariantInit(&pvResult); - - // Save this result - pvResult.vt = VT_ERROR; - pvResult.scode = hrTemp; - hrTemp = pCopyResults->Add(&pvResult); - CHECK_HR(hrTemp, "Failed to add result for [%ws] to list of results", pv.pwszVal); - - PropVariantClear(&pvResult); - - if (SUCCEEDED(hrTemp)) - { - // Send the event - // Get the object properties used for sending the event - hrTemp = m_pFakeDevice->GetObjectPropertiesForEvent(pszNewObjectID, &pEventParams); - CHECK_HR(hrTemp, "Failed to get properties for event on object %ws", pszNewObjectID); - if (SUCCEEDED(hrTemp)) - { - // Set the event-specific parameters - hrTemp = pEventParams->SetGuidValue(WPD_EVENT_PARAMETER_EVENT_ID, WPD_EVENT_OBJECT_ADDED); - CHECK_HR(hrTemp, "Failed to add WPD_EVENT_PARAMETER_EVENT_ID"); - - // Send the Event - if (SUCCEEDED(hrTemp)) - { - PostWpdEvent(pParams, pEventParams); - } - } - } - } - - if (pszNewObjectID != NULL) - { - CoTaskMemFree(pszNewObjectID); - pszNewObjectID = NULL; - } - - PropVariantClear(&pv); - } - } - } - - // Set the results - if (SUCCEEDED(hr)) - { - hr = pResults->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_MANAGEMENT_COPY_RESULTS, pCopyResults); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_MANAGEMENT_COPY_RESULTS"); - } - - CoTaskMemFree(pszDestFolderObjectID); - - // If an object failed to copy, make sure we return S_FALSE - if (SUCCEEDED(hr) && bCopyFailed) - { - hr = S_FALSE; - } - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_MANAGEMENT_CREATE_OBJECT_WITH_PROPERTIES_ONLY - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_MANAGEMENT_CREATION_PROPERTIES: Contains an IPortableDeviceValues, describing - * properties of the new object. At the very least, it will contain: - * - WPD_OBJECT_NAME: The object name. - * - WPD_PARENT_ID: Identifies the parent object. The object should be inserted as a child of - * this parent (e.g. this would be the target directory in a file system based device). - * - * The driver should: - * - Create the object, and return its ID in WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID. - */ -HRESULT WpdObjectManagement::OnCreateObjectWithPropertiesOnly( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszContext = NULL; - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceValues> pEventParams; - - // Get the Object Properties - hr = pParams->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_MANAGEMENT_CREATION_PROPERTIES, &pValues); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_CREATION_PROPERTIES"); - - // Save the object to the device here. - if (SUCCEEDED(hr)) - { - hr = m_pFakeDevice->SaveNewObject(pValues, &pszContext); - CHECK_HR(hr, "Failed to save new (properties only) object to device"); - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID, pszContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID"); - } - - if (SUCCEEDED(hr)) - { - // Send the event - HRESULT hrTemp = S_OK; - // Get the object properties used for sending the event - hrTemp = m_pFakeDevice->GetObjectPropertiesForEvent(pszContext, &pEventParams); - CHECK_HR(hrTemp, "Failed to get properties for event on object %ws", pszContext); - if (SUCCEEDED(hrTemp)) - { - // Set the event-specific parameters - hrTemp = pEventParams->SetGuidValue(WPD_EVENT_PARAMETER_EVENT_ID, WPD_EVENT_OBJECT_ADDED); - CHECK_HR(hrTemp, "Failed to add WPD_EVENT_PARAMETER_EVENT_ID"); - - // Send the Event - if (SUCCEEDED(hrTemp)) - { - PostWpdEvent(pParams, pEventParams); - } - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszContext); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_MANAGEMENT_CREATE_OBJECT_WITH_PROPERTIES_AND_DATA - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_MANAGEMENT_CREATION_PROPERTIES: Contains an IPortableDeviceValues, describing - * properties of the new object. At the very least, it will contain: - * - WPD_OBJECT_NAME: The object name. - * - WPD_PARENT_ID: Identifies the parent object. The object should be inserted as a child of - * this parent (e.g. this would be the target directory in a file system based device). - * - WPD_OBJECT_SIZE: The total size of the object data stream. - * - WPD_OBJECT_FORMAT: The format the object data stream. - * - * The driver should: - * - Create a context for this operation and return it in WPD_PROPERTY_OBJECT_MANAGEMENT_CONTEXT. - * - Return the optimal transfer buffer size in WPD_PROPERTY_OBJECT_MANAGEMENT_OPTIMAL_TRANSFER_BUFFER_SIZE. - */ -HRESULT WpdObjectManagement::OnCreateObjectWithPropertiesAndData( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszContext = NULL; - LPWSTR pszObjectName = NULL; - IUnknown* pContextMap = NULL; - CComPtr<IPortableDeviceValues> pValues; - - // Get the Object Properties - hr = pParams->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_MANAGEMENT_CREATION_PROPERTIES, &pValues); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_CREATION_PROPERTIES"); - - // Get Object Name from pValues - if (SUCCEEDED(hr)) - { - hr = pValues->GetStringValue(WPD_OBJECT_NAME, &pszObjectName); - CHECK_HR(hr, "Failed to get WPD_OBJECT_NAME"); - } - - // Get the context map - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, &pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - // Object data will be provided by the caller. So Create a context identifying this - // creation request, since the actual data will come later, and the object can only be saved - // when we receive a WPD_COMMAND_OBJECT_MANAGEMENT_COMMIT_OBJECT call. - hr = CreateObjectManagementContext((ContextMap*) pContextMap, pszObjectName, pValues, false /*bUpdateRequest*/, &pszContext); - CHECK_HR(hr, "Failed to create object management context"); - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_MANAGEMENT_CONTEXT, pszContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_MANAGEMENT_CONTEXT"); - } - - // Set the optimal buffer size - if (SUCCEEDED(hr)) - { - hr = pResults->SetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_MANAGEMENT_OPTIMAL_TRANSFER_BUFFER_SIZE, OPTIMAL_BUFFER_SIZE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_MANAGEMENT_OPTIMAL_TRANSFER_BUFFER_SIZE value"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszContext); - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszObjectName); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_MANAGEMENT_REVERT_OBJECT - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_MANAGEMENT_CONTEXT: identifies the object creation request (driver returned this in - * WPD_COMMAND_OBJECT_MANAGEMENT_CREATE_OBJECT). - * - * The driver should: - * - Free any resources associated with this context/operation. The object should not be saved to the - * device. If a placeholder was created on the device for this operation, it should be removed. - */ -HRESULT WpdObjectManagement::OnRevert( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszContext = NULL; - ContextMap* pContextMap = NULL; - - // There are no return parameters for this operation. - UNREFERENCED_PARAMETER(pResults); - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_MANAGEMENT_CONTEXT, &pszContext); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID"); - - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - hr = DestroyObjectManagementContext(pContextMap, pszContext); - CHECK_HR(hr, "Failed to revert object identified by context [%ws]", pszContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_MANAGEMENT_COMMIT_OBJECT - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_MANAGEMENT_CONTEXT: identifies the object creation request (driver returned this in - * WPD_COMMAND_OBJECT_MANAGEMENT_CREATE_OBJECT). - * - * The driver should: - * - Commit the object to the device. - * - Return the new/updated ObjectID in WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID. - */ -HRESULT WpdObjectManagement::OnCommit( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszContext = NULL; - ObjectManagementContext* pContext = NULL; - ContextMap* pContextMap = NULL; - CComPtr<IPortableDeviceValues> pEventParams; - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_MANAGEMENT_CONTEXT, &pszContext); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID"); - - // Get the object management context for this request - if (SUCCEEDED(hr)) - { - hr = GetClientContext(pParams, pszContext, (IUnknown**)&pContext); - CHECK_HR(hr, "Failed to get Object Management Context"); - } - - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - if (pContext->UpdateRequest) - { - // Update the object - hr = UpdateObject(pContext, pParams, pResults); - } - else - { - // Save the new object - hr = CommitNewObject(pContext, pszContext, pParams, pResults); - } - } - - // We're done with the context - SAFE_RELEASE(pContext); - - // Destroy the context associated with this request, since it is no longer needed - if (SUCCEEDED(hr)) - { - hr = DestroyObjectManagementContext(pContextMap, pszContext); - CHECK_HR(hr, "Failed to destroy object identified by context [%ws]", pszContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_MANAGEMENT_WRITE_OBJECT_DATA - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_MANAGEMENT_CONTEXT: identifies the object creation request previsouly started with - * WPD_PROPERTY_OBJECT_MANAGEMENT_CREATE_OBJECT. - * - WPD_PROPERTY_OBJECT_MANAGEMENT_NUM_BYTES_TO_WRITE: specifies the next number of bytes to write. - * - WPD_PROPERTY_OBJECT_MANAGEMENT_DATA: specifies byte array where the data should be copied from. - * - * The driver should: - * - Write the next WPD_PROPERTY_OBJECT_MANAGEMENT_NUM_BYTES_TO_WRITE to the resource. - * - Return the number of bytes actually written in WPD_PROPERTY_OBJECT_MANAGEMENT_NUM_BYTES_WRITTEN. - * It is normally considered an error if this value does not match WPD_PROPERTY_OBJECT_MANAGEMENT_NUM_BYTES_TO_WRITE. - */ -HRESULT WpdObjectManagement::OnWriteObjectData( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszContext = NULL; - DWORD dwNumBytesToWrite = 0; - DWORD dwNumBytesWritten = 0; - BYTE* pBuffer = NULL; - DWORD cbBuffer = 0; - ObjectManagementContext* pContext = NULL; - - // Get the Context string - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_MANAGEMENT_CONTEXT, &pszContext); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_CONTEXT"); - - // Get the number of bytes to write - if (SUCCEEDED(hr)) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_MANAGEMENT_NUM_BYTES_TO_WRITE, &dwNumBytesToWrite); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_NUM_BYTES_TO_WRITE"); - } - - // Get the source buffer - if (SUCCEEDED(hr)) - { - hr = pParams->GetBufferValue(WPD_PROPERTY_OBJECT_MANAGEMENT_DATA, &pBuffer, &cbBuffer); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_DATA"); - } - - // Get the resource context for this object creation request - if (SUCCEEDED(hr)) - { - hr = GetClientContext(pParams, pszContext, (IUnknown**)&pContext); - CHECK_HR(hr, "Failed to get Object Management Context"); - } - - // Write the next band of data for this new object request - if (SUCCEEDED(hr)) - { - // TBD: Write bytes to object. This sample driver ignores the data content. - dwNumBytesWritten = dwNumBytesToWrite; - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_MANAGEMENT_NUM_BYTES_WRITTEN, dwNumBytesWritten); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_MANAGEMENT_NUM_BYTES_WRITTEN"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszContext); - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pBuffer); - - SAFE_RELEASE(pContext); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_MANAGEMENT_UPDATE_OBJECT_WITH_PROPERTIES_AND_DATA - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID: Identifies the object to update. - * - WPD_PROPERTY_OBJECT_MANAGEMENT_UPDATE_PROPERTIES: Contains an IPortableDeviceValues, describing - * the updated properties of the object. At the very least, it will contain: - * - WPD_OBJECT_SIZE: The total size of the object data stream. - * - * The driver should: - * - Create a context for this operation and return it in WPD_PROPERTY_OBJECT_MANAGEMENT_CONTEXT. - * - Return the optimal transfer buffer size in WPD_PROPERTY_OBJECT_MANAGEMENT_OPTIMAL_TRANSFER_BUFFER_SIZE. - */ -HRESULT WpdObjectManagement::OnUpdateObjectWithPropertiesAndData( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszContext = NULL; - LPWSTR pszObjectId = NULL; - IUnknown* pContextMap = NULL; - BOOL bUpdatable = NULL; - CComPtr<IPortableDeviceValues> pValues; - - // Get the Object Identifier. - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID, &pszObjectId); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID"); - - // Get the Object Properties - if (SUCCEEDED(hr)) - { - hr = pParams->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_MANAGEMENT_UPDATE_PROPERTIES, &pValues); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_MANAGEMENT_CREATION_PROPERTIES"); - } - - // Get the context map - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, &pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Validate whether this object supports the default resource - if (SUCCEEDED(hr)) - { - hr = m_pFakeDevice->SupportsResource(pszObjectId, WPD_RESOURCE_DEFAULT, &bUpdatable); - CHECK_HR(hr, "Failed to check whether object supports WPD_RESOURCE_DEFAULT"); - - if (SUCCEEDED(hr) && !bUpdatable) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Object does not support WPD_RESOURCE_DEFAULT"); - } - } - - if (SUCCEEDED(hr)) - { - // Object data will be provided by the caller. So Create a context identifying this - // creation request, since the actual data will come later, and the object can only be saved - // when we receive a WPD_COMMAND_OBJECT_MANAGEMENT_COMMIT_OBJECT call. - hr = CreateObjectManagementContext((ContextMap*) pContextMap, pszObjectId, pValues, true /*bUpdateRequest*/, &pszContext); - CHECK_HR(hr, "Failed to create object management context"); - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_MANAGEMENT_CONTEXT, pszContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_MANAGEMENT_CONTEXT"); - } - - // Set the optimal buffer size - if (SUCCEEDED(hr)) - { - hr = pResults->SetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_MANAGEMENT_OPTIMAL_TRANSFER_BUFFER_SIZE, OPTIMAL_BUFFER_SIZE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_MANAGEMENT_OPTIMAL_TRANSFER_BUFFER_SIZE value"); - } - - CoTaskMemFree(pszContext); - CoTaskMemFree(pszObjectId); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -HRESULT WpdObjectManagement::CreateObjectManagementContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszObjectName, - _In_ IPortableDeviceValues* pObjectProperties, - _In_ BOOL bUpdateRequest, - _Outptr_result_nullonfailure_ LPWSTR* ppszObjectManagementContext) -{ - HRESULT hr = S_OK; - GUID guidContext = GUID_NULL; - ObjectManagementContext* pContext = NULL; - CComBSTR bstrContext; - - if((pContextMap == NULL) || - (pObjectProperties == NULL) || - (pszObjectName == NULL) || - (ppszObjectManagementContext == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *ppszObjectManagementContext = NULL; - - hr = CoCreateGuid(&guidContext); - if (SUCCEEDED(hr)) - { - bstrContext = guidContext; - if(bstrContext.Length() == 0) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to create BSTR from GUID"); - } - } - - if (SUCCEEDED(hr)) - { - pContext = new ObjectManagementContext(); - if(pContext != NULL) - { - CAtlStringW strKey = bstrContext; - pContext->Name = pszObjectName; - pContext->ObjectProperties = pObjectProperties; - pContext->UpdateRequest = bUpdateRequest; - - hr = pContextMap->Add(strKey, pContext); - CHECK_HR(hr, "Failed to add object creation context to client context map"); - - pContext->Release(); - } - else - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate object creation context"); - } - } - - if (SUCCEEDED(hr)) - { - *ppszObjectManagementContext = AtlAllocTaskWideString(bstrContext); - } - - return hr; -} - -HRESULT WpdObjectManagement::DestroyObjectManagementContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszObjectManagementContext) -{ - HRESULT hr = S_OK; - - CAtlStringW strKey = pszObjectManagementContext; - pContextMap->Remove(strKey); - - return hr; -} - -HRESULT WpdObjectManagement::CommitNewObject( - _In_ ObjectManagementContext* pContext, - _In_ LPCWSTR pszContext, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - LPWSTR pszObjectID = NULL; - - // Save the new object - HRESULT hr = m_pFakeDevice->SaveNewObject(pContext->ObjectProperties, &pszObjectID); - CHECK_HR(hr, "Failed to save new object [%ws] to device", pContext->Name); - - // Let the caller know the new object's ID. - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID, pszObjectID); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID"); - } - - if (SUCCEEDED(hr)) - { - // Send the event - HRESULT hrTemp = S_OK; - CComPtr<IPortableDeviceValues> pEventParams; - - // Get the object properties used for sending the event - hrTemp = m_pFakeDevice->GetObjectPropertiesForEvent(pszObjectID, &pEventParams); - CHECK_HR(hrTemp, "Failed to get properties for event on object %ws", pszObjectID); - - if (SUCCEEDED(hrTemp)) - { - // Set the event-specific parameters - hrTemp = pEventParams->SetGuidValue(WPD_EVENT_PARAMETER_EVENT_ID, WPD_EVENT_OBJECT_ADDED); - CHECK_HR(hrTemp, "Failed to add WPD_EVENT_PARAMETER_EVENT_ID"); - - hrTemp = pEventParams->SetStringValue(WPD_EVENT_PARAMETER_OBJECT_CREATION_COOKIE, pszContext); - CHECK_HR(hrTemp, "Failed to add WPD_EVENT_PARAMETER_OBJECT_CREATION_COOKIE"); - - // Send the Event - if (SUCCEEDED(hr)) - { - PostWpdEvent(pParams, pEventParams); - } - } - } - - CoTaskMemFree(pszObjectID); - - return hr; -} - -HRESULT WpdObjectManagement::UpdateObject( - _In_ ObjectManagementContext* pContext, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - // For convenience, the ObjectID was stored in Name for object updates - LPCWSTR pszObjectId = pContext->Name; - - // Update the object - HRESULT hr = m_pFakeDevice->UpdateContentObject(pszObjectId, pContext->ObjectProperties); - CHECK_HR(hr, "Failed to update object [%ws] to device", pszObjectId); - - // Set the object ID. - if (hr == S_OK) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID, pszObjectId); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_MANAGEMENT_OBJECT_ID"); - } - - if (hr == S_OK) - { - // Send the event - HRESULT hrTemp = S_OK; - CComPtr<IPortableDeviceValues> pEventParams; - - // Get the object properties used for sending the event - hrTemp = m_pFakeDevice->GetObjectPropertiesForEvent(pContext->Name, &pEventParams); - CHECK_HR(hrTemp, "Failed to get properties for event on object %ws", pszObjectId); - - if (hrTemp == S_OK) - { - // Set the event-specific parameters - hrTemp = pEventParams->SetGuidValue(WPD_EVENT_PARAMETER_EVENT_ID, WPD_EVENT_OBJECT_UPDATED); - CHECK_HR(hrTemp, "Failed to add WPD_EVENT_PARAMETER_EVENT_ID"); - - // Send the Event - if (hrTemp == S_OK) - { - PostWpdEvent(pParams, pEventParams); - } - } - } - - return hr; -} diff --git a/wpd/WpdWudfSampleDriver/WpdObjectManagement.h b/wpd/WpdWudfSampleDriver/WpdObjectManagement.h deleted file mode 100644 index 7fe3a097..00000000 --- a/wpd/WpdWudfSampleDriver/WpdObjectManagement.h +++ /dev/null @@ -1,131 +0,0 @@ -#pragma once - -// This class is used to store the context for a specific enumeration. -// Currently, this is done by storing the object index. -class ObjectManagementContext : public IUnknown -{ -public: - ObjectManagementContext() : - m_cRef(1), - UpdateRequest(FALSE) - { - - } - - ~ObjectManagementContext() - { - - } - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -public: - CAtlStringW Name; - CComPtr<IPortableDeviceValues> ObjectProperties; - BOOL UpdateRequest; -private: - DWORD m_cRef; -}; - -class WpdObjectManagement -{ -public: - WpdObjectManagement(); - ~WpdObjectManagement(); - - HRESULT Initialize(_In_ FakeDevice *pFakeDevice); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnDelete(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnCreateObjectWithPropertiesOnly(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnCreateObjectWithPropertiesAndData(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnWriteObjectData(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnRevert(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnCommit(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnMove(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnCopy(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnUpdateObjectWithPropertiesAndData(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - HRESULT CreateObjectManagementContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszObjectName, - _In_ IPortableDeviceValues* pObjectProperties, - _In_ BOOL bUpdateRequest, - _Outptr_result_nullonfailure_ LPWSTR* ppszObjectManagementContext); - - HRESULT DestroyObjectManagementContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszObjectManagementContext); - - HRESULT CommitNewObject( - _In_ ObjectManagementContext* pContext, - _In_ LPCWSTR pszContext, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT UpdateObject( - _In_ ObjectManagementContext* pContext, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - FakeDevice* m_pFakeDevice; -}; diff --git a/wpd/WpdWudfSampleDriver/WpdObjectProperties.cpp b/wpd/WpdWudfSampleDriver/WpdObjectProperties.cpp deleted file mode 100644 index d6e0d5dd..00000000 --- a/wpd/WpdWudfSampleDriver/WpdObjectProperties.cpp +++ /dev/null @@ -1,445 +0,0 @@ -#include "stdafx.h" -#include "WpdObjectProperties.tmh" - -WpdObjectProperties::WpdObjectProperties() -{ - -} - -WpdObjectProperties::~WpdObjectProperties() -{ - -} - -HRESULT WpdObjectProperties::Initialize(_In_ FakeDevice *pFakeDevice) -{ - HRESULT hr = S_OK; - - if(pFakeDevice == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - m_pFakeDevice = pFakeDevice; - return hr; -} - - -HRESULT WpdObjectProperties::DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (hr == S_OK) - { - if (Command.fmtid != WPD_CATEGORY_OBJECT_PROPERTIES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED)) - { - hr = OnGetSupportedProperties(pParams, pResults); - CHECK_HR(hr, "Failed to get supported properties"); - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET)) - { - hr = OnGetValues(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to read properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL)) - { - hr = OnGetAllValues(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to read all properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_SET)) - { - hr = OnWriteProperties(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to write properties"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES)) - { - hr = OnGetAttributes(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to get property attributes"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_DELETE)) - { - hr = OnDelete(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to delete properties"); - } - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_SUPPORTED - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose properties we want to return. - * - WPD_PROPERTY_OBJECT_PROPERTIES_FILTER: the filter to use when returning supported properties. - * Since this parameter is optional, it may not exist. - * ! This driver currently ignores the filter parameter. ! - * - * The driver should: - * - Return all properties that match the filter. - */ -HRESULT WpdObjectProperties::OnGetSupportedProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszObjectID = NULL; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // Get the Object ID - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &pszObjectID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing string value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - // Get the properties to read - if (hr == S_OK) - { - hr = m_pFakeDevice->GetSupportedProperties(pszObjectID, &pKeys); - CHECK_HR(hr, "Failed to get property keys collection"); - } - - if (hr == S_OK) - { - hr = pResults->SetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, pKeys); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszObjectID); - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values we want to return. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys, identifying which - * specific property values we are requested to return. - * - * The driver should: - * - Return all requested property values in WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES. If any property read failed, the corresponding value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were read successfully. - * - S_FALSE should be returned if any property read failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - - CComPtr<IPortableDeviceValues> pValueStore; - CComPtr<IPortableDeviceKeyCollection> pKeys; - - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - if (hr == S_OK) - { - hr = pParams->GetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, &pKeys); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - if (hr == S_OK) - { - hr = m_pFakeDevice->GetValues(wszObjectID, pKeys, &pValueStore); - CHECK_HR(hr, "Failed to read properties on [%ws]", wszObjectID); - } - - if (SUCCEEDED(hr)) - { - HRESULT hrTemp = S_OK; - - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, pValueStore); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - CoTaskMemFree(wszObjectID); - wszObjectID = NULL; - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_ALL - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values we want to return. - * - * The driver should: - * - Return all property values in WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES. If any property read failed, the corresponding value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were read successfully. - * - S_FALSE should be returned if any property read failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetAllValues( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR wszObjectID = NULL; - - CComPtr<IPortableDeviceValues> pValueStore; - - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &wszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - if (hr == S_OK) - { - hr = m_pFakeDevice->GetAllValues(wszObjectID, &pValueStore); - CHECK_HR(hr, "Failed to read all properties on [%ws]", wszObjectID); - } - - if (SUCCEEDED(hr)) - { - HRESULT hrTemp = S_OK; - - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, pValueStore); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - CoTaskMemFree(wszObjectID); - wszObjectID = NULL; - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_SET - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property values we want to return. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES: an IPortableDeviceValues of values, identifying which - * specific property values we are requested to write. - * - * The driver should: - * - Write all requested property values. For each property, a write result should be returned in the - * write result property store. - * - If any property write failed, the corresponding write result value should be - * set to type VT_ERROR with the 'scode' member holding the HRESULT reason for the failure. - * - S_OK should be returned if all properties were written successfully. - * - S_FALSE should be returned if any property write failed. - * - Any error return indicates that the driver did not write any results, and the caller will - * not attempt to unpack any property write results. - */ -HRESULT WpdObjectProperties::OnWriteProperties( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszObjectID = NULL; - CComPtr<IPortableDeviceValues> pValues; - CComPtr<IPortableDeviceValues> pWriteResults; - CComPtr<IPortableDeviceValues> pEventParams; - - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &pszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - if (hr == S_OK) - { - hr = pParams->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES, &pValues); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_VALUES"); - } - - if (hr == S_OK) - { - hr = m_pFakeDevice->WritePropertiesOnObject(pszObjectID, pValues, &pWriteResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to write properties on [%ws]", pszObjectID); - } - } - - // Be sure to preserve possible S_FALSE returns - if (SUCCEEDED(hr)) - { - HRESULT hrTemp = S_OK; - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_WRITE_RESULTS, pWriteResults); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_WRITE_RESULTS")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - - pEventParams = NULL; - hrTemp = m_pFakeDevice->GetObjectPropertiesForEvent(pszObjectID, &pEventParams); - CHECK_HR(hrTemp, "Failed to get properties for event on object %ws", pszObjectID); - - if (hrTemp == S_OK) - { - HRESULT hrEvent = S_OK; - // Set the event-specific parameters - hrEvent = pEventParams->SetGuidValue(WPD_EVENT_PARAMETER_EVENT_ID, WPD_EVENT_OBJECT_UPDATED); - CHECK_HR(hrEvent, "Failed to add WPD_EVENT_PARAMETER_EVENT_ID"); - - // Send the Event - if (hrEvent == S_OK) - { - PostWpdEvent(pParams, pEventParams); - } - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_GET_ATTRIBUTES - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose property attributes we want to return. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys containing a single value, - * which is the key identifying the specific property attributes we are requested to return. - * - * The driver should: - * - Return the requested property attributes. If any property attributes failed to be retrieved, - * the corresponding value should be set to type VT_ERROR with the 'scode' member holding the - * HRESULT reason for the failure. - * - S_OK should be returned if all property attributes were read successfully. - * - S_FALSE should be returned if any property attribute failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectProperties::OnGetAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszObjectID = NULL; - - PROPERTYKEY Key = WPD_PROPERTY_NULL; - CComPtr<IPortableDeviceValues> pAttributeStore; - - if (hr == S_OK) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID, &pszObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID"); - } - - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS, &Key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS"); - } - - if (hr == S_OK) - { - hr = m_pFakeDevice->GetAttributes(pszObjectID, Key, &pAttributeStore); - CHECK_HR(hr, "Failed to get attributes on [%ws]", pszObjectID); - } - - if (SUCCEEDED(hr)) - { - HRESULT hrTemp = S_OK; - - hrTemp = pResults->SetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_ATTRIBUTES, pAttributeStore); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_ATTRIBUTES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_DELETE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_OBJECT_ID: identifies the object whose properties should be deleted. - * - WPD_PROPERTY_OBJECT_PROPERTIES_PROPERTY_KEYS: a collection of property keys indicating which - * properties to delete. - * - * The driver should: - * - Delete the specified properties from the object. - * - S_OK should be returned if all specified properties were successfully deleted. - * - E_ACCESSDENIED should be returned if the client attempts to delete a property which is not deletable (i.e. - * WPD_PROPERTY_ATTRIBUTE_CAN_DELETE is FALSE for that property.) - */ -HRESULT WpdObjectProperties::OnDelete( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = E_ACCESSDENIED; - - UNREFERENCED_PARAMETER(pParams); - UNREFERENCED_PARAMETER(pResults); - - // This driver has no properties which can be deleted. - return hr; -} - diff --git a/wpd/WpdWudfSampleDriver/WpdObjectProperties.h b/wpd/WpdWudfSampleDriver/WpdObjectProperties.h deleted file mode 100644 index a63b2021..00000000 --- a/wpd/WpdWudfSampleDriver/WpdObjectProperties.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -class WpdObjectProperties -{ -public: - WpdObjectProperties(); - ~WpdObjectProperties(); - - HRESULT Initialize(_In_ FakeDevice *pFakeDevice); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedProperties(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetValues(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetAllValues(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnWriteProperties(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetAttributes(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnDelete(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - - FakeDevice* m_pFakeDevice; -}; diff --git a/wpd/WpdWudfSampleDriver/WpdObjectPropertiesBulk.cpp b/wpd/WpdWudfSampleDriver/WpdObjectPropertiesBulk.cpp deleted file mode 100644 index 6eafc6fb..00000000 --- a/wpd/WpdWudfSampleDriver/WpdObjectPropertiesBulk.cpp +++ /dev/null @@ -1,1027 +0,0 @@ -#include "stdafx.h" -#include "WpdObjectPropertiesBulk.tmh" - -#define MAX_OBJECTS_TO_RETURN 20 - -WpdObjectPropertiesBulk::WpdObjectPropertiesBulk() -{ - -} - -WpdObjectPropertiesBulk::~WpdObjectPropertiesBulk() -{ - -} - -HRESULT WpdObjectPropertiesBulk::Initialize(_In_ FakeDevice *pFakeDevice) -{ - HRESULT hr = S_OK; - - if(pFakeDevice == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - m_pFakeDevice = pFakeDevice; - return hr; -} - -HRESULT WpdObjectPropertiesBulk::DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (hr == S_OK) - { - if (Command.fmtid != WPD_CATEGORY_OBJECT_PROPERTIES_BULK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - } - - if (hr == S_OK) - { - if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_START)) - { - hr = OnGetValuesByObjectListStart(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to start bulk property operation"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_NEXT)) - { - hr = OnGetValuesByObjectListNext(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to do next bulk property operation"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_END)) - { - hr = OnGetValuesByObjectListEnd(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to end bulk property operation"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_START)) - { - hr = OnGetValuesByObjectFormatStart(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to start bulk property operation"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_NEXT)) - { - hr = OnGetValuesByObjectFormatNext(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to do next bulk property operation"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_END)) - { - hr = OnGetValuesByObjectFormatEnd(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to end bulk property operation "); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_START)) - { - hr = OnSetValuesByObjectListStart(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to set bulk property operation"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_NEXT)) - { - hr = OnSetValuesByObjectListNext(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to set bulk property operation"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_END)) - { - hr = OnSetValuesByObjectListEnd(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to set bulk property operation"); - } - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_START - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_OBJECT_IDS: identifies the objects whose property - * values we want to return. - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_PROPERTY_KEYS: a collection of property keys, identifying which - * specific property values we are requested to return. If this property doesn't exist, - * then the client is asking for all values. - * - * The driver should: - * - Create a new context for this bulk property operation. - * - Return an identifier for the context in WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT. - */ -HRESULT WpdObjectPropertiesBulk::OnGetValuesByObjectListStart( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - CComPtr<IPortableDeviceKeyCollection> pKeys; - ContextMap* pContextMap = NULL; - - // Get the IPortableDevicePropVariantCollection which contains the collection - // of object identifiers the bulk operation is being performed on. - hr = pParams->GetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_OBJECT_IDS, &pObjectIDs); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_BULK_OBJECT_IDS"); - - // Get the IPortableDeviceKeyCollection which contains the collection - // keys of properties being read on the multiple objects. - if (SUCCEEDED(hr)) - { - hr = pParams->GetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_PROPERTY_KEYS, &pKeys); - if (FAILED(hr)) - { - // Client is asking for all properties. - pKeys = NULL; - hr = S_OK; - } - } - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - LPWSTR pwszContext = NULL; - hr = CreateBulkPropertiesContext(pContextMap, pObjectIDs, pKeys, &pwszContext); - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, pwszContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - } - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_NEXT - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT: the context the driver returned to - * the client in OnGetValuesByObjectListStart. - * - * The driver should: - * - Return the next set of property values in WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES. - * If there are no more properties to be read an - * empty collection should be returned. - * - It is up to the driver to return as many object property values as it wants. If zero values are returned - * it is assumed the bulk operation is complete and the WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_END - * will be called next. - * - * - S_OK should be returned if the collection can be returned successfully. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectPropertiesBulk::OnGetValuesByObjectListNext( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pwszContext = NULL; - BulkPropertiesContext* pContext = NULL; - DWORD cObjects = 0; - CComPtr<IPortableDeviceValuesCollection> pCollection; - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, &pwszContext); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT from IPortableDeviceValues"); - - // Get the bulk property operation context - if (SUCCEEDED(hr)) - { - hr = GetClientContext(pParams, pwszContext, (IUnknown**) &pContext); - CHECK_HR(hr, "Failed to get bulk property context"); - } - - if (SUCCEEDED(hr)) - { - hr = pContext->ObjectIDs->GetCount(&cObjects); - CHECK_HR(hr, "Failed to get number of objectIDs from bulk properties context"); - } - - if (SUCCEEDED(hr)) - { - cObjects = cObjects - pContext->NextObject; - if(cObjects > MAX_OBJECTS_TO_RETURN) - { - cObjects = MAX_OBJECTS_TO_RETURN; - } - } - - // Make sure the the collection holds VT_LPWSTR values. - if (SUCCEEDED(hr)) - { - hr = pContext->ObjectIDs->ChangeType(VT_LPWSTR); - CHECK_HR(hr, "Failed to change objectIDs collection to VT_LPWSTR"); - } - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValuesCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValuesCollection, - (VOID**) &pCollection); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValuesCollection"); - } - - if (SUCCEEDED(hr)) - { - for (DWORD dwIndex = pContext->NextObject, dwCount = 0; dwCount < cObjects; dwCount++, dwIndex++) - { - CComPtr<IPortableDeviceValues> pValues; - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - hr = pContext->ObjectIDs->GetAt(dwIndex, &pv); - CHECK_HR(hr, "Failed to get next object ID from bulk properties context"); - - if (SUCCEEDED(hr)) - { - // If a key list was supplied, get the specified object properties, other get all - // properties. - if(pContext->Properties != NULL) - { - hr = m_pFakeDevice->GetValues(pv.pwszVal, pContext->Properties, &pValues); - CHECK_HR(hr, "Failed to get property values for [%ws]", pv.pwszVal); - } - else - { - hr = m_pFakeDevice->GetAllValues(pv.pwszVal, &pValues); - CHECK_HR(hr, "Failed to get property values for [%ws]", pv.pwszVal); - } - } - - // Add the ObjectID to the returned results - if (SUCCEEDED(hr)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ID, pv.pwszVal); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID for %ws", pv.pwszVal); - } - - if (SUCCEEDED(hr)) - { - hr = pCollection->Add(pValues); - CHECK_HR(hr, "Failed to add IPortableDeviceValues to IPortableDeviceValuesCollection"); - } - - PropVariantClear(&pv); - - pContext->NextObject += 1; - } - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES, pCollection); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - - SAFE_RELEASE(pContext); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_LIST_END - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT: the context the driver returned to - * the client in OnGetValuesByObjectListStart. - * - * The driver should: - * - Destroy any resources associated with this context. - */ -HRESULT WpdObjectPropertiesBulk::OnGetValuesByObjectListEnd( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pwszContext = NULL; - ContextMap* pContextMap = NULL; - UNREFERENCED_PARAMETER(pResults); - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, &pwszContext); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT from IPortableDeviceValues"); - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - hr = DestroyBulkPropertiesContext(pContextMap, pwszContext); - CHECK_HR(hr, "Failed to destroy bulk property context %ws", pwszContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_START - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_OBJECT_FORMAT: Identifies the format of the objects the - * client is interested in. - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_PARENT_OBJECT_ID: Identifies the parent object from which the - * operation should start. - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_DEPTH: Indicates the hierarchical depth of the operation - * from the parent object. - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_PROPERTY_KEYS: a collection of property keys, identifying which - * specific property values we are requested to return. If this doesn't exist, then - * ALL object proeprties should be returned for the specified objects. - * - * The driver should: - * - Create a new context for this bulk property operation. - * - Return an identifier for the context in WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT. - */ -HRESULT WpdObjectPropertiesBulk::OnGetValuesByObjectFormatStart( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceKeyCollection> pKeys; - GUID guidOjbectFormat = GUID_NULL; - LPWSTR pszParentObjectID = NULL; - DWORD dwDepth = 0; - ContextMap* pContextMap = NULL; - - // Get the object format. - hr = pParams->GetGuidValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_OBJECT_FORMAT, &guidOjbectFormat); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_BULK_OBJECT_FORMAT"); - - // Get the parent object id. - if (SUCCEEDED(hr)) - { - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_PARENT_OBJECT_ID, &pszParentObjectID); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_BULK_PARENT_OBJECT_ID"); - } - - // Get the depth. - if (SUCCEEDED(hr)) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_DEPTH, &dwDepth); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_BULK_DEPTH"); - } - - // Get the IPortableDeviceKeyCollection which contains the collection - // keys of properties being read on the multiple objects. - if (SUCCEEDED(hr)) - { - hr = pParams->GetIPortableDeviceKeyCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_PROPERTY_KEYS, &pKeys); - if (FAILED(hr)) - { - // Client is asking for all properties. - pKeys = NULL; - hr = S_OK; - } - } - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - LPWSTR pwszContext = NULL; - hr = CreateBulkPropertiesContext(pContextMap, guidOjbectFormat, pszParentObjectID, dwDepth, pKeys, &pwszContext); - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, pwszContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszParentObjectID); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_NEXT - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT: the context the driver returned to - * the client in OnGetValuesByObjectFormatStart. - * - * The driver should: - * - Return the next set of property values in WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES. - * If there are no more properties to be read an - * empty collection should be returned. - * - It is up to the driver to return as many object property values as it wants. If zero values are returned - * it is assumed the bulk operation is complete and the WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_END - * will be called next. - * - * - S_OK should be returned if the collection can be returned successfully. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectPropertiesBulk::OnGetValuesByObjectFormatNext( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pwszContext = NULL; - BulkPropertiesContext* pContext = NULL; - DWORD cObjects = 0; - CComPtr<IPortableDeviceValuesCollection> pCollection; - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, &pwszContext); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT from IPortableDeviceValues"); - - // Get the bulk property operation context - if (SUCCEEDED(hr)) - { - hr = GetClientContext(pParams, pwszContext, (IUnknown**) &pContext); - CHECK_HR(hr, "Failed to get bulk property context"); - } - - // Make sure the the collection holds VT_LPWSTR values. - if (SUCCEEDED(hr)) - { - hr = pContext->ObjectIDs->ChangeType(VT_LPWSTR); - CHECK_HR(hr, "Failed to change objectIDs collection to VT_LPWSTR"); - } - - if (SUCCEEDED(hr)) - { - hr = pContext->ObjectIDs->GetCount(&cObjects); - CHECK_HR(hr, "Failed to get number of objectIDs from bulk properties context"); - } - - if (SUCCEEDED(hr)) - { - cObjects = cObjects - pContext->NextObject; - if(cObjects > MAX_OBJECTS_TO_RETURN) - { - cObjects = MAX_OBJECTS_TO_RETURN; - } - } - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValuesCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValuesCollection, - (VOID**) &pCollection); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValuesCollection"); - } - - if (SUCCEEDED(hr)) - { - for (DWORD dwIndex = pContext->NextObject, dwCount = 0; dwCount < cObjects; dwCount++, dwIndex++) - { - CComPtr<IPortableDeviceValues> pValues; - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - hr = pContext->ObjectIDs->GetAt(dwIndex, &pv); - CHECK_HR(hr, "Failed to get next object ID from bulk properties context"); - - if (SUCCEEDED(hr)) - { - // If a key list was supplied, get the specified object properties, other get all - // properties. - if(pContext->Properties != NULL) - { - hr = m_pFakeDevice->GetValues(pv.pwszVal, pContext->Properties, &pValues); - CHECK_HR(hr, "Failed to get property values for [%ws]", pv.pwszVal); - } - else - { - hr = m_pFakeDevice->GetAllValues(pv.pwszVal, &pValues); - CHECK_HR(hr, "Failed to get property values for [%ws]", pv.pwszVal); - } - } - - // Add the ObjectID to the returned results - if (SUCCEEDED(hr)) - { - hr = pValues->SetStringValue(WPD_OBJECT_ID, pv.pwszVal); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID for %ws", pv.pwszVal); - } - - if (SUCCEEDED(hr)) - { - hr = pCollection->Add(pValues); - CHECK_HR(hr, "Failed to add IPortableDeviceValues to IPortableDeviceValuesCollection"); - } - - PropVariantClear(&pv); - pContext->NextObject++; - } - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES, pCollection); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - SAFE_RELEASE(pContext); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_GET_VALUES_BY_OBJECT_FORMAT_END - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT: the context the driver returned to - * the client in OnGetValuesByObjectFormatStart. - * - * The driver should: - * - Destroy any resources associated with this context. - */ -HRESULT WpdObjectPropertiesBulk::OnGetValuesByObjectFormatEnd( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pwszContext = NULL; - ContextMap* pContextMap = NULL; - UNREFERENCED_PARAMETER(pResults); - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, &pwszContext); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT from IPortableDeviceValues"); - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - hr = DestroyBulkPropertiesContext(pContextMap, pwszContext); - CHECK_HR(hr, "Failed to destroy bulk property context %ws", pwszContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_START - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES: holds a collection of IPortableDeviceValues which - * indicate which object properties to set. - * - * The driver should: - * - Create a new context for this bulk property operation. - * - Return an identifier for the context in WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT. - */ -HRESULT WpdObjectPropertiesBulk::OnSetValuesByObjectListStart( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValuesCollection> pValuesCollection; - ContextMap* pContextMap = NULL; - - // Get the IPortableDevicePropVariantCollection which contains the collection - // of object identifiers the bulk operation is being performed on. - hr = pParams->GetIPortableDeviceValuesCollectionValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES, &pValuesCollection); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_PROPERTIES_BULK_VALUES"); - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - LPWSTR pwszContext = NULL; - hr = CreateBulkPropertiesContext(pContextMap, pValuesCollection, &pwszContext); - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, pwszContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - } - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_NEXT - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT: the context the driver returned to - * the client in OnGetValuesByObjectListStart. - * - * The driver should: - * - Write the next set of property values, and return the write results in WPD_PROPERTY_OBJECT_PROPERTIES_BULK_WRITE_RESULTS. - * If there are no more properties to be written, an empty collection should be returned. - * - It is up to the driver to write as many object property values as it wants. If zero write results are returned - * it is assumed the bulk operation is complete and the WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_END - * will be called next. - * - * - S_OK should be returned if the collection can be returned successfully. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any property values. - */ -HRESULT WpdObjectPropertiesBulk::OnSetValuesByObjectListNext( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pwszContext = NULL; - BulkPropertiesContext* pContext = NULL; - DWORD cObjects = 0; - CComPtr<IPortableDeviceValuesCollection> pWriteResults; - CComPtr<IPortableDeviceValuesCollection> pValuesCollection; - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, &pwszContext); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT from IPortableDeviceValues"); - - // Get the bulk property operation context - if (SUCCEEDED(hr)) - { - hr = GetClientContext(pParams, pwszContext, (IUnknown**) &pContext); - CHECK_HR(hr, "Failed to get bulk property context"); - } - - // Make sure the the collection holds a ValuesCollection, then get the number of elements. - if (SUCCEEDED(hr)) - { - if(pContext->ValuesCollection != NULL) - { - hr = pContext->ValuesCollection->GetCount(&cObjects); - CHECK_HR(hr, "Failed to get number of objectIDs from bulk properties context"); - } - else - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Incorrect context specified - this context does not contain a values collection"); - } - } - - // Create the collection to hold the write results - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValuesCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValuesCollection, - (VOID**) &pWriteResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValuesCollection"); - } - - if (SUCCEEDED(hr)) - { - for (DWORD dwIndex = pContext->NextObject; dwIndex < cObjects; dwIndex++) - { - CComPtr<IPortableDeviceValues> pSetValues; - CComPtr<IPortableDeviceValues> pSetResults; - hr = pContext->ValuesCollection->GetAt(dwIndex, &pSetValues); - CHECK_HR(hr, "Failed to get next values from bulk properties context"); - - if (SUCCEEDED(hr)) - { - LPWSTR pszObjectID = NULL; - - // Get which object this is for - hr = pSetValues->GetStringValue(WPD_OBJECT_ID, &pszObjectID); - if (SUCCEEDED(hr)) - { - // Set the values - hr = m_pFakeDevice->WritePropertiesOnObject(pszObjectID, pSetValues, &pSetResults); - CHECK_HR(hr, "Failed to set proeprties on [%ws]", pszObjectID); - - // Ensure the write results contain which ObjectID this was for - if (SUCCEEDED(hr)) - { - hr = pSetResults->SetStringValue(WPD_OBJECT_ID, pszObjectID); - CHECK_HR(hr, "Failed to set WPD_OBJECT_ID in write resutls"); - } - } - CoTaskMemFree(pszObjectID); - } - - if (SUCCEEDED(hr)) - { - hr = pWriteResults->Add(pSetResults); - CHECK_HR(hr, "Failed to add IPortableDeviceValues to IPortableDeviceValuesCollection"); - } - - pContext->NextObject++; - } - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_WRITE_RESULTS, pWriteResults); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_PROPERTIES_BULK_WRITE_RESULTS"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - - SAFE_RELEASE(pContext); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_PROPERTIES_BULK_SET_VALUES_BY_OBJECT_LIST_END - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT: the context the driver returned to - * the client in OnSetValuesByObjectListStart. - * - * The driver should: - * - Destroy any resources associated with this context. - */ -HRESULT WpdObjectPropertiesBulk::OnSetValuesByObjectListEnd( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pwszContext = NULL; - ContextMap* pContextMap = NULL; - UNREFERENCED_PARAMETER(pResults); - - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT, &pwszContext); - CHECK_HR(hr, "Failed to get WPD_PROPERTY_OBJECT_PROPERTIES_BULK_CONTEXT from IPortableDeviceValues"); - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr)) - { - hr = DestroyBulkPropertiesContext(pContextMap, pwszContext); - CHECK_HR(hr, "Failed to destroy bulk property context %ws", pwszContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pwszContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -HRESULT WpdObjectPropertiesBulk::CreateBulkPropertiesContext( - _In_ ContextMap* pContextMap, - _In_ IPortableDevicePropVariantCollection* pObjectIDs, - _In_ IPortableDeviceKeyCollection* pProperties, - _Outptr_result_nullonfailure_ LPWSTR* ppszBulkPropertiesContext) -{ - HRESULT hr = S_OK; - GUID guidContext = GUID_NULL; - CComBSTR bstrContext; - BulkPropertiesContext* pContext = NULL; - - if((pContextMap == NULL) || - (pObjectIDs == NULL) || - (ppszBulkPropertiesContext == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *ppszBulkPropertiesContext = NULL; - - hr = CoCreateGuid(&guidContext); - if (SUCCEEDED(hr)) - { - bstrContext = guidContext; - if(bstrContext.Length() == 0) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to create BSTR from GUID"); - } - } - - if (SUCCEEDED(hr)) - { - pContext = new BulkPropertiesContext(); - if(pContext == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new bulk properties context"); - } - } - - if (SUCCEEDED(hr)) - { - pContext->ObjectIDs = pObjectIDs; - pContext->Properties = pProperties; - - CAtlStringW strKey = bstrContext; - hr = pContextMap->Add(strKey, pContext); // calls AddRef on pContext - CHECK_HR(hr, "Failed to insert bulk property operation context into our context Map"); - } - - if (SUCCEEDED(hr)) - { - *ppszBulkPropertiesContext = AtlAllocTaskWideString(bstrContext); - if (*ppszBulkPropertiesContext == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate bulk properties context"); - } - } - - SAFE_RELEASE(pContext); - - return hr; -} - -HRESULT WpdObjectPropertiesBulk::CreateBulkPropertiesContext( - _In_ ContextMap* pContextMap, - _In_ REFGUID guidObjectFormat, - _In_ LPCWSTR pszParentObjectID, - _In_ DWORD dwDepth, - _In_ IPortableDeviceKeyCollection* pProperties, - _Outptr_result_nullonfailure_ LPWSTR* ppszBulkPropertiesContext) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDevicePropVariantCollection> pObjectIDs; - - if((pContextMap == NULL) || - (pszParentObjectID == NULL) || - (ppszBulkPropertiesContext == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *ppszBulkPropertiesContext = NULL; - - hr = m_pFakeDevice->GetObjectIDsByFormat(guidObjectFormat, pszParentObjectID, dwDepth, &pObjectIDs); - CHECK_HR(hr, "Faield to get list of object ids by format"); - - if (SUCCEEDED(hr)) - { - hr = CreateBulkPropertiesContext(pContextMap, pObjectIDs, pProperties, ppszBulkPropertiesContext); - } - - return hr; -} - -HRESULT WpdObjectPropertiesBulk::CreateBulkPropertiesContext( - _In_ ContextMap* pContextMap, - _In_ IPortableDeviceValuesCollection* pValuesCollection, - _Outptr_result_nullonfailure_ LPWSTR* ppszBulkPropertiesContext) -{ - HRESULT hr = S_OK; - GUID guidContext = GUID_NULL; - CComBSTR bstrContext; - BulkPropertiesContext* pContext = NULL; - - if((pContextMap == NULL) || - (pValuesCollection == NULL) || - (ppszBulkPropertiesContext == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *ppszBulkPropertiesContext = NULL; - - hr = CoCreateGuid(&guidContext); - if (SUCCEEDED(hr)) - { - bstrContext = guidContext; - if(bstrContext.Length() == 0) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to create BSTR from GUID"); - } - } - - if (SUCCEEDED(hr)) - { - pContext = new BulkPropertiesContext(); - if(pContext == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new bulk properties context"); - } - } - - if (SUCCEEDED(hr)) - { - pContext->ValuesCollection = pValuesCollection; - - CAtlStringW strKey = bstrContext; - hr = pContextMap->Add(strKey, pContext); - CHECK_HR(hr, "Failed to insert bulk property operation context into our context Map"); - } - - if (SUCCEEDED(hr)) - { - *ppszBulkPropertiesContext = AtlAllocTaskWideString(bstrContext); - if (*ppszBulkPropertiesContext == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate bulk properties context"); - } - } - - SAFE_RELEASE(pContext); - - return hr; -} - -HRESULT WpdObjectPropertiesBulk::DestroyBulkPropertiesContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszBulkPropertiesContext) -{ - HRESULT hr = S_OK; - - CAtlStringW strKey = pszBulkPropertiesContext; - pContextMap->Remove(strKey); - - return hr; -} diff --git a/wpd/WpdWudfSampleDriver/WpdObjectPropertiesBulk.h b/wpd/WpdWudfSampleDriver/WpdObjectPropertiesBulk.h deleted file mode 100644 index dc5cafc6..00000000 --- a/wpd/WpdWudfSampleDriver/WpdObjectPropertiesBulk.h +++ /dev/null @@ -1,134 +0,0 @@ -#pragma once - -// This class is used to store the context for a specific enumeration. -// Currently, this is done by storing the object index. -class BulkPropertiesContext : public IUnknown -{ -public: - BulkPropertiesContext() : - NextObject(0), - m_cRef(1) - { - - } - - ~BulkPropertiesContext() - { - - } - - CComPtr<IPortableDevicePropVariantCollection> ObjectIDs; - DWORD NextObject; - CComPtr<IPortableDeviceKeyCollection> Properties; - CComPtr<IPortableDeviceValuesCollection> ValuesCollection; - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -private: - DWORD m_cRef; -}; - -class WpdObjectPropertiesBulk -{ -public: - WpdObjectPropertiesBulk(); - ~WpdObjectPropertiesBulk(); - - HRESULT Initialize(_In_ FakeDevice *pFakeDevice); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetValuesByObjectListStart(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetValuesByObjectListNext(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetValuesByObjectListEnd(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetValuesByObjectFormatStart(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetValuesByObjectFormatNext(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetValuesByObjectFormatEnd(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnSetValuesByObjectListStart(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnSetValuesByObjectListNext(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnSetValuesByObjectListEnd(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - - HRESULT CreateBulkPropertiesContext( - _In_ ContextMap* pContextMap, - _In_ IPortableDevicePropVariantCollection* pObjectIDs, - _In_ IPortableDeviceKeyCollection* pProperties, - _Outptr_result_nullonfailure_ LPWSTR* ppszBulkPropertiesContext); - - HRESULT CreateBulkPropertiesContext( - _In_ ContextMap* pContextMap, - _In_ REFGUID guidObjectFormat, - _In_ LPCWSTR pszParentObjectID, - _In_ DWORD dwDepth, - _In_ IPortableDeviceKeyCollection* pProperties, - _Outptr_result_nullonfailure_ LPWSTR* ppszBulkPropertiesContext); - - HRESULT CreateBulkPropertiesContext( - _In_ ContextMap* pContextMap, - _In_ IPortableDeviceValuesCollection* pValuesCollection, - _Outptr_result_nullonfailure_ LPWSTR* ppszBulkPropertiesContext); - - HRESULT DestroyBulkPropertiesContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszBulkPropertiesContext); - - FakeDevice* m_pFakeDevice; -}; diff --git a/wpd/WpdWudfSampleDriver/WpdObjectResources.cpp b/wpd/WpdWudfSampleDriver/WpdObjectResources.cpp deleted file mode 100644 index 6f7955d5..00000000 --- a/wpd/WpdWudfSampleDriver/WpdObjectResources.cpp +++ /dev/null @@ -1,944 +0,0 @@ -#include "stdafx.h" -#include "WpdObjectResources.tmh" - -WpdObjectResources::WpdObjectResources() -{ - -} - -WpdObjectResources::~WpdObjectResources() -{ - -} - -HRESULT WpdObjectResources::Initialize( - _In_ FakeDevice *pFakeDevice) -{ - HRESULT hr = S_OK; - - if(pFakeDevice == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - m_pFakeDevice = pFakeDevice; - return hr; -} - -HRESULT WpdObjectResources::DispatchWpdMessage( - _In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - - if (hr == S_OK) - { - if (Command.fmtid != WPD_CATEGORY_OBJECT_RESOURCES) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_GET_SUPPORTED)) - { - hr = OnGetSupportedResources(pParams, pResults); - CHECK_HR(hr, "Failed to get supported resources"); - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_GET_ATTRIBUTES)) - { - hr = OnGetAttributes(pParams, pResults); - if(FAILED(hr)) - { - CHECK_HR(hr, "Failed to get resource attributes"); - } - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_OPEN)) - { - hr = OnOpen(pParams, pResults); - CHECK_HR(hr, "Failed to open resource"); - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_READ)) - { - hr = OnRead(pParams, pResults); - CHECK_HR(hr, "Failed to read resource data"); - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_WRITE)) - { - hr = OnWrite(pParams, pResults); - CHECK_HR(hr, "Failed to write resource data"); - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_CLOSE)) - { - hr = OnClose(pParams, pResults); - CHECK_HR(hr, "Failed to close resource"); - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_DELETE)) - { - hr = OnDelete(pParams, pResults); - CHECK_HR(hr, "Failed to delete resources"); - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_CREATE_RESOURCE)) - { - hr = OnCreate(pParams, pResults); - CHECK_HR(hr, "Failed to create resource"); - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_REVERT)) - { - hr = OnRevert(pParams, pResults); - CHECK_HR(hr, "Failed to revert resource operation"); - } - else if(IsEqualPropertyKey(Command, WPD_COMMAND_OBJECT_RESOURCES_SEEK)) - { - hr = OnSeek(pParams, pResults); - CHECK_HR(hr, "Failed resource seek operation"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_GET_SUPPORTED - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID: identifies the object whose resources we want to return. - * - * The driver should: - * - Return all resources for this object in WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS. - */ -HRESULT WpdObjectResources::OnGetSupportedResources( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszObjectID = NULL; - - CComPtr<IPortableDeviceKeyCollection> pKeys; - - // Get the Object ID - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID, &pszObjectID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID"); - } - - // Get the collection of resource keys - if (hr == S_OK) - { - hr = m_pFakeDevice->GetSupportedResources(pszObjectID, &pKeys); - CHECK_HR(hr, "Failed to get resource keys collection on [%ws]", pszObjectID); - } - - if (hr == S_OK) - { - hr = pResults->SetIUnknownValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS, pKeys); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_GET_ATTRIBUTES - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID: identifies the object whose resource attributes we want to return. - * - WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS: a collection of resource keys containing a single value, - * which is the key identifying the specific resource whose attributes we are requested to return. - * - * The driver should: - * - Return the requested resource attributes. If any resource attributes failed to be retrieved, - * the corresponding value should be set to type VT_ERROR with the 'scode' member holding the - * HRESULT reason for the failure. - * - S_OK should be returned if all resource attributes were read successfully. - * - S_FALSE should be returned if any resource attribute failed. - * - Any error return indicates that the driver did not fill in any results, and the caller will - * not attempt to unpack any resource attributes. - */ -HRESULT WpdObjectResources::OnGetAttributes( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszObjectID = NULL; - PROPERTYKEY Key = {0}; - - CComPtr<IPortableDeviceValues> pAttributeStore; - - // Get the Object ID - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID, &pszObjectID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID"); - } - - if (hr == S_OK) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS, &Key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS"); - } - - if (hr == S_OK) - { - hr = m_pFakeDevice->GetResourceAttributes(pszObjectID, Key, &pAttributeStore); - CHECK_HR(hr, "Failed to get attributes on [%ws]", pszObjectID); - } - - if (SUCCEEDED(hr)) - { - HRESULT hrTemp = S_OK; - - hrTemp = pResults->SetIUnknownValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_ATTRIBUTES, pAttributeStore); - CHECK_HR(hrTemp, ("Failed to set WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_ATTRIBUTES")); - - if(FAILED(hrTemp)) - { - hr = hrTemp; - } - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszObjectID); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_OPEN - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID: identifies the object whose resource we are interested in. - * - WPD_PROPERTY_OBJECT_RESOURCES_ACCESS_MODE: specifies the access requested by the caller. It will - * be either STGM_READ or STGM_WRITE. - * - WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS: a collection of resource keys containing a single value, - * which is the key identifying the specific resource the caller is interested in. - * - * The driver should: - * - Create a context associated with this resource. This context will be used by clients when reading/writing - * resource data. Generally, most drivers will also lock the resource here if necessary. - * The context identifier should be a string value returned in WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT. - * - Return the optimal transfer buffer size in WPD_PROPERTY_OBJECT_RESOURCES_OPTIMAL_TRANSFER_BUFFER_SIZE. - */ -HRESULT WpdObjectResources::OnOpen( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszObjectID = NULL; - PROPERTYKEY Key = {0}; - DWORD dwMode = STGM_READ; - LPWSTR pszContext = NULL; - ContextMap* pContextMap = NULL; - BOOL bSupportsResource = FALSE; - - // Get the Object ID - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID, &pszObjectID); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID"); - } - - // Get the resource key - if (SUCCEEDED(hr)) - { - hr = pParams->GetKeyValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS, &Key); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS"); - } - - // Get the access mode - if (SUCCEEDED(hr)) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_ACCESS_MODE, &dwMode); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_ACCESS_MODE"); - } - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Validate whether this object supports the requested resource - if (SUCCEEDED(hr)) - { - hr = m_pFakeDevice->SupportsResource(pszObjectID, Key, &bSupportsResource); - CHECK_HR(hr, "Failed to check whether object supports resources"); - } - - if (SUCCEEDED(hr) && !bSupportsResource) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Object does not support this resource"); - } - - // Create the context - if (SUCCEEDED(hr)) - { - hr = CreateResourceContext(pContextMap, pszObjectID, Key, FALSE, &pszContext); - CHECK_HR(hr, "Failed to create resource context for %ws.%d on %ws", CComBSTR(Key.fmtid), Key.pid, pszObjectID); - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, pszContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Set the optimal buffer size - if (SUCCEEDED(hr)) - { - hr = pResults->SetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_OPTIMAL_TRANSFER_BUFFER_SIZE, OPTIMAL_BUFFER_SIZE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_OPTIMAL_TRANSFER_BUFFER_SIZE value"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszObjectID); - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_READ - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT: identifies the previsouly opened resource we are going to read from. - * - WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ: specifies the next number of bytes to read. - * - * The driver should: - * - Read up to the next WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ from the resource. - * - Return the number of bytes actually read in WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_READ. - */ -HRESULT WpdObjectResources::OnRead( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszContext = NULL; - DWORD dwNumBytesToRead = 0; - DWORD dwNumBytesRead = 0; - BYTE* pBuffer = NULL; - ResourceContext* pContext = NULL; - - // Get the Context - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, &pszContext); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Get the number of bytes to read - if (SUCCEEDED(hr)) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ, &dwNumBytesToRead); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_READ"); - } - - // Allocate the destination buffer - if (SUCCEEDED(hr)) - { - pBuffer = reinterpret_cast<BYTE *>(CoTaskMemAlloc(dwNumBytesToRead)); - if (pBuffer == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate the destination buffer"); - } - } - - // Get the context for this transfer - if (SUCCEEDED(hr)) - { - hr = GetClientContext(pParams, pszContext, (IUnknown**) &pContext); - CHECK_HR(hr, "Failed to get resource context"); - } - - // Read the next band of data for this transfer request - if (SUCCEEDED(hr) && pBuffer != NULL) - { - hr = m_pFakeDevice->ReadData(pContext->ObjectID, - pContext->Key, - pContext->NumBytesTransfered, - pBuffer, - dwNumBytesToRead, - &dwNumBytesRead); - CHECK_HR(hr, "Failed to read %d bytes from [%ws] on resource {%ws}.%d", dwNumBytesToRead, pContext->ObjectID, CComBSTR(pContext->Key.fmtid), pContext->Key.pid); - if (SUCCEEDED(hr)) - { - pContext->NumBytesTransfered += dwNumBytesRead; - } - } - - if (SUCCEEDED(hr) && pBuffer != NULL) - { - hr = pResults->SetBufferValue(WPD_PROPERTY_OBJECT_RESOURCES_DATA, pBuffer, dwNumBytesRead); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_DATA"); - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_READ, dwNumBytesRead); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_READ"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszContext); - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pBuffer); - - SAFE_RELEASE(pContext); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_WRITE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT: identifies the previsouly opened resource we are going to write to. - * - WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_WRITE: specifies the next number of bytes to write. - * - WPD_PROPERTY_OBJECT_RESOURCES_DATA: specifies byte array where the data should be copied from. - * - * The driver should: - * - Write the next WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_WRITE to the resource. - * - Return the number of bytes actually written in WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_WRITTEN. - * It is normally considered an error if this value does not match WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_WRITE. - */ -HRESULT WpdObjectResources::OnWrite( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszContext = NULL; - DWORD dwNumBytesToWrite = 0; - DWORD dwNumBytesWritten = 0; - BYTE* pBuffer = NULL; - DWORD cbBuffer = 0; - ResourceContext* pContext = NULL; - - // Get the Context string - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, &pszContext); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Get the number of bytes to write - if (SUCCEEDED(hr)) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_WRITE, &dwNumBytesToWrite); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_TO_WRITE"); - } - - // Get the source buffer - if (SUCCEEDED(hr)) - { - hr = pParams->GetBufferValue(WPD_PROPERTY_OBJECT_RESOURCES_DATA, &pBuffer, &cbBuffer); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_DATA"); - } - - // Get the resource context for this transfer - if (SUCCEEDED(hr)) - { - hr = GetClientContext(pParams, pszContext, (IUnknown**) &pContext); - CHECK_HR(hr, "Faield to get resource context"); - } - - // Write the next band of data for this transfer request - if (SUCCEEDED(hr) && pBuffer != NULL) - { - hr = m_pFakeDevice->WriteData(pContext->ObjectID, - pContext->Key, - pContext->NumBytesTransfered, - pBuffer, - dwNumBytesToWrite, - &dwNumBytesWritten); - CHECK_HR(hr, "Failed to write %d bytes to [%ws] on resource {%ws}.%d", dwNumBytesToWrite, pContext->ObjectID, CComBSTR(pContext->Key.fmtid), pContext->Key.pid); - if (SUCCEEDED(hr)) - { - pContext->NumBytesTransfered += dwNumBytesWritten; - } - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_WRITTEN, dwNumBytesWritten); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_NUM_BYTES_WRITTEN"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszContext); - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pBuffer); - - SAFE_RELEASE(pContext); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_CLOSE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT: identifies the resource context associated with a - * previously opened resource. - * - * The driver should: - * - Unlock the resource if necessary, and release any system and device resources associated with this WPD object resource. - */ -HRESULT WpdObjectResources::OnClose( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - // No results are expected to be returned - UNREFERENCED_PARAMETER(pResults); - - HRESULT hr = S_OK; - LPWSTR pszContext = NULL; - ContextMap* pContextMap = NULL; - ResourceContext* pContext = NULL; - - // Get the Object ID - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, &pszContext); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // If this was a creation request, enable the resource for the content - if (SUCCEEDED(hr)) - { - // Get the context for this transfer - hr = GetClientContext(pParams, pszContext, (IUnknown**) &pContext); - CHECK_HR(hr, "Failed to get resource context"); - } - - if (SUCCEEDED(hr)) - { - if (pContext->CreateRequest == TRUE) - { - hr = m_pFakeDevice->EnableResource(pContext->ObjectID, pContext->Key); - CHECK_HR(hr, "Failed to enable resource on object [%ws]", pContext->ObjectID); - } - } - - //Free the context - SAFE_RELEASE(pContext); - - if (SUCCEEDED(hr)) - { - hr = DestroyResourceContext(pContextMap, pszContext); - CHECK_HR(hr, "Failed to remove resource context [%ws]", pszContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_DELETE - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_OBJECT_ID: identifies the object whose resources should be deleted. - * - WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_KEYS: a collection of keys indicating which - * resources to delete. - * - * The driver should: - * - Delete the specified resources from the object. - * - S_OK should be returned if all specified properties were successfully deleted. - * - E_ACCESSDENIED should be returned if the client attempts to delete a resource which is not deletable (i.e. - * WPD_RESOURCE_ATTRIBUTE_CAN_DELETE is FALSE for that resource.) - */ -HRESULT WpdObjectResources::OnDelete( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = E_ACCESSDENIED; - - UNREFERENCED_PARAMETER(pParams); - UNREFERENCED_PARAMETER(pResults); - - // This driver has no resources which can be deleted. - return hr; -} - -HRESULT WpdObjectResources::OnCreate( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszObjectID = NULL; - LPWSTR pszContext = NULL; - ContextMap* pContextMap = NULL; - PROPERTYKEY ResourceKey = WPD_PROPERTY_NULL; - GUID guidObjectFormat = GUID_NULL; - CComPtr<IPortableDeviceValues> pResourceAttributes; - - // Getthe Resource Attributes - hr = pParams->GetIPortableDeviceValuesValue(WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_ATTRIBUTES, &pResourceAttributes); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_RESOURCE_ATTRIBUTES"); - } - - // Get the Resource Key - if (SUCCEEDED(hr)) - { - hr = pResourceAttributes->GetKeyValue(WPD_RESOURCE_ATTRIBUTE_RESOURCE_KEY, &ResourceKey); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_RESOURCE_ATTRIBUTE_RESOURCE_KEY"); - } - } - - if (SUCCEEDED(hr) && !IsEqualPropertyKey(ResourceKey, WPD_RESOURCE_CONTACT_PHOTO)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "CreateResource is only supported on WPD_RESOURCE_CONTACT_PHOTO"); - } - - if (SUCCEEDED(hr)) - { - // Get the Object ID - hr = pResourceAttributes->GetStringValue(WPD_OBJECT_ID, &pszObjectID); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_OBJECT_ID"); - } - } - - if (SUCCEEDED(hr)) - { - hr = m_pFakeDevice->GetContentFormat(pszObjectID, guidObjectFormat); - CHECK_HR(hr, "Failed to get content object format"); - - if (SUCCEEDED(hr) && !IsEqualGUID(guidObjectFormat, WPD_OBJECT_FORMAT_VCARD2)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "CreateResource is only supported on contact objects"); - } - } - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - // Create the context - if (SUCCEEDED(hr)) - { - hr = CreateResourceContext(pContextMap, pszObjectID, ResourceKey, TRUE, &pszContext); - CHECK_HR(hr, "Failed to create resource context for %ws.%d on %ws", CComBSTR(ResourceKey.fmtid), ResourceKey.pid, pszObjectID); - } - - if (SUCCEEDED(hr)) - { - hr = pResults->SetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, pszContext); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Set the optimal buffer size - if (SUCCEEDED(hr)) - { - hr = pResults->SetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_OPTIMAL_TRANSFER_BUFFER_SIZE, OPTIMAL_BUFFER_SIZE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_OPTIMAL_TRANSFER_BUFFER_SIZE value"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszObjectID); - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_REVERT - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT: identifies the resource context associated with a - * previously opened resource. - * - * The driver should: - * - Unlock and remove the resource if necessary, and release any system and device resources associated with this WPD object resource. - */ -HRESULT WpdObjectResources::OnRevert( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - // No results are expected to be returned - UNREFERENCED_PARAMETER(pResults); - - HRESULT hr = S_OK; - LPWSTR pszContext = NULL; - ContextMap* pContextMap = NULL; - - // Get the Object ID - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, &pszContext); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Get the context map which the driver stored in pParams for convenience - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**)&pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - //Free the context - if (SUCCEEDED(hr)) - { - hr = DestroyResourceContext(pContextMap, pszContext); - CHECK_HR(hr, "Failed to remove resource context [%ws]", pszContext); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszContext); - - SAFE_RELEASE(pContextMap); - - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_OBJECT_RESOURCES_SEEK - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT: identifies the resource context associated with a - * previously opened resource. - * - WPD_PROPERTY_OBJECT_RESOURCES_SEEK_OFFSET: Displacement to be added to the location indicated by the WPD_PROPERTY_OBJECT_RESOURCES_SEEK_ORIGIN_FLAG parameter. - * - WPD_PROPERTY_OBJECT_RESOURCES_SEEK_ORIGIN_FLAG: Specifies the origin of the displacement for the seek operation. Can be one of the following values: - * STREAM_SEEK_SET - Offset is from the beginning of the stream - * STREAM_SEEK_CUR - Offset is from the current position in the stream - * STREAM_SEEK_END - Offset is from the end of the stream - * - * The driver should: - * - Move the seek pointer for the resource to point to the specified position, so that - * subsequent read / write operations occur from the new position. - * - Return the new position as an offset relative to the start of the data stream in WPD_PROPERTY_OBJECT_RESOURCES_POSITION_FROM_START. - */ -HRESULT WpdObjectResources::OnSeek( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - // No results are expected to be returned - UNREFERENCED_PARAMETER(pResults); - - HRESULT hr = S_OK; - LPWSTR pszContext = NULL; - DWORD dwOrigin = 0; - LONGLONG lOffset = 0; - - ResourceContext* pContext = NULL; - - // Get the Object ID - hr = pParams->GetStringValue(WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT, &pszContext); - if (FAILED(hr)) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_CONTEXT"); - } - - // Get the offset - if (SUCCEEDED(hr)) - { - hr = pParams->GetSignedLargeIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_SEEK_OFFSET, &lOffset); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_SEEK_OFFSET"); - } - - // Get the origin flags - if (SUCCEEDED(hr)) - { - hr = pParams->GetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_SEEK_ORIGIN_FLAG, &dwOrigin); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_OBJECT_RESOURCES_SEEK_ORIGIN_FLAG"); - } - - // Get the context for this transfer - if (SUCCEEDED(hr)) - { - hr = GetClientContext(pParams, pszContext, (IUnknown**) &pContext); - CHECK_HR(hr, "Failed to get resource context"); - } - - // Update the current seek pointer. For this driver, we update the NumBytesTransfered in the context so that subsequent reads/writes start - // at the appropriate place. - if (SUCCEEDED(hr)) - { - ULONG ulSize = 0; - ULONG ulOriginalNumBytesTransfered = pContext->NumBytesTransfered; - CComPtr<IPortableDeviceValues> pResourceAttributes; - - // Get the total size of the resource - hr = m_pFakeDevice->GetResourceAttributes(pContext->ObjectID, pContext->Key, &pResourceAttributes); - CHECK_HR(hr, "Failed to get attributes on [%ws]", pContext->ObjectID); - if (SUCCEEDED(hr)) - { - hr = pResourceAttributes->GetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE, &ulSize); - CHECK_HR(hr, "Failed to get WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE"); - } - - if(dwOrigin == STREAM_SEEK_CUR) - { - pContext->NumBytesTransfered += (LONG) lOffset; - } - else if(dwOrigin == STREAM_SEEK_SET) - { - pContext->NumBytesTransfered = (LONG) lOffset; - } - else - { - pContext->NumBytesTransfered = ulSize + (LONG) lOffset; - } - - // Validate that this is in the correct range - if (SUCCEEDED(hr) && pContext->NumBytesTransfered > ulSize) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Attempting to seek beyond existing data"); - // Restore the seek pointer to its original value - pContext->NumBytesTransfered = ulOriginalNumBytesTransfered; - } - } - - // Set the return value - if (SUCCEEDED(hr)) - { - hr = pResults->SetUnsignedIntegerValue(WPD_PROPERTY_OBJECT_RESOURCES_POSITION_FROM_START, pContext->NumBytesTransfered); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_OBJECT_RESOURCES_POSITION_FROM_START"); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszContext); - - SAFE_RELEASE(pContext); - - return hr; -} - -HRESULT WpdObjectResources::CreateResourceContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszObjectID, - _In_ REFPROPERTYKEY ResourceKey, - _In_ BOOL bCreateRequest, - _Outptr_ LPWSTR* ppszResourceContext) -{ - HRESULT hr = S_OK; - GUID guidContext = GUID_NULL; - ResourceContext* pContext = NULL; - - if((pContextMap == NULL) || - (pszObjectID == NULL) || - (ppszResourceContext == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *ppszResourceContext = NULL; - - hr = CoCreateGuid(&guidContext); - CHECK_HR(hr, "Failed to CoCreateGuid used for identifying the resource context"); - - if (SUCCEEDED(hr)) - { - pContext = new ResourceContext(); - if(pContext == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate new resource context"); - } - } - - if (SUCCEEDED(hr)) - { - pContext->ObjectID = pszObjectID; - pContext->Key = ResourceKey; - pContext->CreateRequest = bCreateRequest; - - CAtlStringW strKey = CComBSTR(guidContext); - hr = pContextMap->Add(strKey, pContext); - CHECK_HR(hr, "Failed to insert bulk property operation context into our context Map"); - } - - if (SUCCEEDED(hr)) - { - hr = StringFromCLSID(guidContext, ppszResourceContext); - CHECK_HR(hr, "Failed to allocate string from GUID for resource context"); - } - - SAFE_RELEASE(pContext); - - return hr; -} - -HRESULT WpdObjectResources::DestroyResourceContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszResourceContext) -{ - HRESULT hr = S_OK; - - if(pszResourceContext == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - CAtlStringW strKey = pszResourceContext; - pContextMap->Remove(strKey); - - return hr; -} - diff --git a/wpd/WpdWudfSampleDriver/WpdObjectResources.h b/wpd/WpdWudfSampleDriver/WpdObjectResources.h deleted file mode 100644 index 81894662..00000000 --- a/wpd/WpdWudfSampleDriver/WpdObjectResources.h +++ /dev/null @@ -1,129 +0,0 @@ -#pragma once - -// This context is used for managing reads/writes for data transfer. -// It keeps track of the number of bytes read/written for the current transfer. -class ResourceContext : public IUnknown -{ -public: - ResourceContext() : - NumBytesTransfered(0), - m_cRef(1), - CreateRequest(FALSE) - { - - - Key = WPD_PROPERTY_NULL; - } - - ~ResourceContext() - { - - } - - CAtlStringW ObjectID; - PROPERTYKEY Key; - DWORD NumBytesTransfered; - BOOL CreateRequest; - -public: // IUnknown - ULONG __stdcall AddRef() - { - InterlockedIncrement((long*) &m_cRef); - return m_cRef; - } - - _At_(this, __drv_freesMem(Mem)) - ULONG __stdcall Release() - { - ULONG ulRefCount = m_cRef - 1; - - if (InterlockedDecrement((long*) &m_cRef) == 0) - { - delete this; - return 0; - } - return ulRefCount; - } - - HRESULT __stdcall QueryInterface( - REFIID riid, - void** ppv) - { - HRESULT hr = S_OK; - - if(riid == IID_IUnknown) - { - *ppv = static_cast<IUnknown*>(this); - AddRef(); - } - else - { - *ppv = NULL; - hr = E_NOINTERFACE; - } - - return hr; - } - -private: - DWORD m_cRef; -}; - -class WpdObjectResources -{ -public: - WpdObjectResources(); - ~WpdObjectResources(); - - HRESULT Initialize(_In_ FakeDevice *pFakeDevice); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetSupportedResources(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnGetAttributes(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnOpen(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnRead(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnWrite(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnClose(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnDelete(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnCreate(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnRevert(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnSeek(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - HRESULT CreateResourceContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszObjectID, - _In_ REFPROPERTYKEY ResourceKey, - _In_ BOOL bCreateRequest, - _Outptr_ LPWSTR* ppszResourceContext); - - HRESULT DestroyResourceContext( - _In_ ContextMap* pContextMap, - _In_ LPCWSTR pszResourceContext); - -private: - - FakeDevice* m_pFakeDevice; -}; diff --git a/wpd/WpdWudfSampleDriver/WpdStorage.cpp b/wpd/WpdWudfSampleDriver/WpdStorage.cpp deleted file mode 100644 index cb4e85c3..00000000 --- a/wpd/WpdWudfSampleDriver/WpdStorage.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include "stdafx.h" -#include "WpdStorage.tmh" - -WpdStorage::WpdStorage() -{ - -} - -WpdStorage::~WpdStorage() -{ - -} - -HRESULT WpdStorage::Initialize(_In_ FakeDevice *pFakeDevice) -{ - - HRESULT hr = S_OK; - - if(pFakeDevice == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - m_pFakeDevice = pFakeDevice; - return hr; -} - - -HRESULT WpdStorage::DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - - HRESULT hr = S_OK; - - if (hr == S_OK) - { - if (Command.fmtid != WPD_CATEGORY_STORAGE) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "This object does not support this command category %ws",CComBSTR(Command.fmtid)); - } - } - - if (hr == S_OK) - { - if (IsEqualPropertyKey(Command, WPD_COMMAND_STORAGE_FORMAT)) - { - hr = OnFormat(pParams, pResults); - CHECK_HR(hr, "Failed to format storage"); - } - else - { - hr = E_NOTIMPL; - CHECK_HR(hr, "This object does not support this command id %d", Command.pid); - } - } - return hr; -} - -/** - * This method is called when we receive a WPD_COMMAND_STORAGE_FORMAT - * command. - * - * The parameters sent to us are: - * - WPD_PROPERTY_STORAGE_OBJECT_ID: identifies the storage object to format. - * - * The driver should: - * - Format the storage identified by WPD_PROPERTY_STORAGE_OBJECT_ID. - */ -HRESULT WpdStorage::OnFormat( - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults) -{ - HRESULT hr = S_OK; - LPWSTR pszObjectID = NULL; - - UNREFERENCED_PARAMETER(pResults); - - // Get the Object ID - hr = pParams->GetStringValue(WPD_PROPERTY_STORAGE_OBJECT_ID, &pszObjectID); - if (hr != S_OK) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Missing string value for WPD_PROPERTY_STORAGE_OBJECT_ID"); - } - - // Format this storage - if (hr == S_OK) - { - hr = m_pFakeDevice->FormatStorage(pszObjectID, pParams); - CHECK_HR(hr, "Failed to process format command on [%ws]", pszObjectID); - } - - // Free the memory. CoTaskMemFree ignores NULLs so no need to check. - CoTaskMemFree(pszObjectID); - - return hr; -} - - diff --git a/wpd/WpdWudfSampleDriver/WpdStorage.h b/wpd/WpdWudfSampleDriver/WpdStorage.h deleted file mode 100644 index a20c8e06..00000000 --- a/wpd/WpdWudfSampleDriver/WpdStorage.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -class WpdStorage -{ -public: - WpdStorage(); - ~WpdStorage(); - - HRESULT Initialize(_In_ FakeDevice *pFakeDevice); - - HRESULT DispatchWpdMessage(_In_ REFPROPERTYKEY Command, - _In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnFormat(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - - HRESULT OnMoveObject(_In_ IPortableDeviceValues* pParams, - _In_ IPortableDeviceValues* pResults); - -private: - - FakeDevice* m_pFakeDevice; -}; diff --git a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.cpp b/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.cpp deleted file mode 100644 index 2728b2e7..00000000 --- a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// Implementation of DLL Exports. - -#include "stdafx.h" -#include "resource.h" -#include "WpdWudfSampleDriver.h" - -#include "WpdWudfSampleDriver.tmh" - -HINSTANCE g_hInstance = NULL; - -class CWpdWudfSampleDriverModule : public CAtlDllModuleT< CWpdWudfSampleDriverModule > -{ -public : - DECLARE_LIBID(LIBID_WpdWudfSampleDriverLib) - DECLARE_REGISTRY_APPID_RESOURCEID(IDR_WpdWudfSampleDriver, "{9FF28171-F2BA-4720-AAE1-92DA54E8BB0E}") -}; - -CWpdWudfSampleDriverModule _AtlModule; - - -// DLL Entry Point -extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) -{ - if(dwReason == DLL_PROCESS_ATTACH) - { - g_hInstance = hInstance; - // Initialize tracing. - WPP_INIT_TRACING(MYDRIVER_TRACING_ID); - } - else if (dwReason == DLL_PROCESS_DETACH) - { - // Cleanup tracing. - WPP_CLEANUP(); - } - - return _AtlModule.DllMain(dwReason, lpReserved); -} - - -// Used to determine whether the DLL can be unloaded by OLE -STDAPI DllCanUnloadNow(void) -{ - return _AtlModule.DllCanUnloadNow(); -} - - -// Returns a class factory to create an object of the requested type -STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID* ppv) -{ - return _AtlModule.DllGetClassObject(rclsid, riid, ppv); -} - - -// DllRegisterServer - Adds entries to the system registry -STDAPI DllRegisterServer(void) -{ - // registers object, typelib and all interfaces in typelib - HRESULT hr = _AtlModule.DllRegisterServer(); - return hr; -} - - -// DllUnregisterServer - Removes entries from the system registry -STDAPI DllUnregisterServer(void) -{ - HRESULT hr = _AtlModule.DllUnregisterServer(); - return hr; -} diff --git a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.def b/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.def deleted file mode 100644 index 661dd814..00000000 --- a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.def +++ /dev/null @@ -1,9 +0,0 @@ -; WpdWudfSampleDriver.def : Declares the module parameters. - -LIBRARY "WpdWudfSampleDriver.DLL" - -EXPORTS - DllCanUnloadNow PRIVATE - DllGetClassObject PRIVATE - DllRegisterServer PRIVATE - DllUnregisterServer PRIVATE diff --git a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.idl b/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.idl deleted file mode 100644 index 4e3f3dd0..00000000 --- a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.idl +++ /dev/null @@ -1,24 +0,0 @@ - -import "oaidl.idl"; -import "ocidl.idl"; - -import "wudfddi.idl"; - -[ - uuid(780B0652-9672-42FF-9AEA-8AE2AE1AABE0), - version(1.0), - helpstring("WPD Sample Driver for new WUDF 1.0 Type Library") -] -library WpdWudfSampleDriverLib -{ - importlib("stdole2.tlb"); - [ - uuid(4F2FDA86-31DD-4840-A391-7A0F29220208), - helpstring("WpdWudfSampleDriver Class") - ] - coclass WpdWudfSampleDriver - { - [default] interface IDriverEntry; - }; -}; - diff --git a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.inx b/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.inx Binary files differdeleted file mode 100644 index a2e11b1b..00000000 --- a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.inx +++ /dev/null diff --git a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.rc b/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.rc deleted file mode 100644 index 7b337741..00000000 --- a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.rc +++ /dev/null @@ -1,31 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" -#include <windows.h> -#include <ntverp.h> - -#define VER_FILETYPE VFT_DLL -#define VER_FILESUBTYPE VFT2_UNKNOWN -#define VER_FILEDESCRIPTION_STR "Windows Portable Device Sample Driver using WUDF" -#define VER_INTERNALNAME_STR "WpdWudfSampleDriver.dll" - -#include <common.ver> - -IDR_WPD_SAMPLEDRIVER_IMAGE DATA_FILE "SampleImage.jpg" -IDR_WPD_SAMPLEDRIVER_IMAGE_THUMBNAIL DATA_FILE "SampleImageThumbnail.jpg" -IDR_WPD_SAMPLEDRIVER_MUSIC DATA_FILE "SampleMusic.wma" -IDR_WPD_SAMPLEDRIVER_DEVICE_ICON DATA_FILE "SampleDeviceIcon.ico" -IDR_WPD_SAMPLEDRIVER_AUDIO_ANNOTATION DATA_FILE "SampleAudioAnnotation.wav" -IDR_WPD_SAMPLEDRIVER_VIDEO DATA_FILE "SampleVideo.wmv" -IDR_WPD_SAMPLEDRIVER_CONTACT_PHOTO DATA_FILE "SampleContactPhoto.png" -IDR_WPD_SAMPLEDRIVER_INTERNAL_STORAGE_ICON DATA_FILE "SampleInternalStorageIcon.ico" -IDR_WPD_SAMPLEDRIVER_EXTERNAL_STORAGE_ICON DATA_FILE "SampleExternalStorageIcon.ico" -IDR_WPD_SAMPLEDRIVER_MEMO DATA_FILE "SampleMemo.txt" -IDR_WPD_SAMPLEDRIVER_MEMO_ICON DATA_FILE "SampleMemoIcon.ico" -IDR_WPD_SAMPLEDRIVER_MEMO_FOLDER_ICON DATA_FILE "SampleMemoFolderIcon.ico" - -1 TYPELIB "WpdWudfSampleDriver.tlb" - -IDR_WpdWudfSampleDriver REGISTRY "WpdWudfSampleDriver.rgs" - - diff --git a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.rgs b/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.rgs deleted file mode 100644 index 42a55b28..00000000 --- a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.rgs +++ /dev/null @@ -1,26 +0,0 @@ -HKCR -{ - WpdWudfSampleDriver.WpdWudfSampleDriver.1 = s 'WpdWudfSampleDriver Class' - { - CLSID = s '{4F2FDA86-31DD-4840-A391-7A0F29220208}' - } - WpdWudfSampleDriver.WpdWudfSampleDriver = s 'WpdWudfSampleDriver Class' - { - CLSID = s '{4F2FDA86-31DD-4840-A391-7A0F29220208}' - CurVer = s 'WpdWudfSampleDriver.WpdWudfSampleDriver.1' - } - NoRemove CLSID - { - ForceRemove {4F2FDA86-31DD-4840-A391-7A0F29220208} = s 'WpdWudfSampleDriver Class' - { - ProgID = s 'WpdWudfSampleDriver.WpdWudfSampleDriver.1' - VersionIndependentProgID = s 'WpdWudfSampleDriver.WpdWudfSampleDriver.1' - InprocServer32 = s '%MODULE%' - { - val ThreadingModel = s 'Free' - } - 'TypeLib' = s '{780B0652-9672-42FF-9AEA-8AE2AE1AABE0}' - } - } -} - diff --git a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.sln b/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.sln deleted file mode 100644 index 4a75ae9f..00000000 --- a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.sln +++ /dev/null @@ -1,28 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0 -MinimumVisualStudioVersion = 12.0 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WpdWudfSampleDriver", "WpdWudfSampleDriver.vcxproj", "{0BC526FD-758C-42AD-A9E5-6BF873E280AA}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - Debug|x64 = Debug|x64 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0BC526FD-758C-42AD-A9E5-6BF873E280AA}.Debug|Win32.ActiveCfg = Debug|Win32 - {0BC526FD-758C-42AD-A9E5-6BF873E280AA}.Debug|Win32.Build.0 = Debug|Win32 - {0BC526FD-758C-42AD-A9E5-6BF873E280AA}.Release|Win32.ActiveCfg = Release|Win32 - {0BC526FD-758C-42AD-A9E5-6BF873E280AA}.Release|Win32.Build.0 = Release|Win32 - {0BC526FD-758C-42AD-A9E5-6BF873E280AA}.Debug|x64.ActiveCfg = Debug|x64 - {0BC526FD-758C-42AD-A9E5-6BF873E280AA}.Debug|x64.Build.0 = Debug|x64 - {0BC526FD-758C-42AD-A9E5-6BF873E280AA}.Release|x64.ActiveCfg = Release|x64 - {0BC526FD-758C-42AD-A9E5-6BF873E280AA}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.vcxproj b/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.vcxproj deleted file mode 100644 index 3e575c04..00000000 --- a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.vcxproj +++ /dev/null @@ -1,418 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup Label="ProjectConfigurations"> - <ProjectConfiguration Include="Debug|Win32"> - <Configuration>Debug</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|Win32"> - <Configuration>Release</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Debug|x64"> - <Configuration>Debug</Configuration> - <Platform>x64</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|x64"> - <Configuration>Release</Configuration> - <Platform>x64</Platform> - </ProjectConfiguration> - </ItemGroup> - <PropertyGroup Label="Globals"> - <ProjectGuid>{0BC526FD-758C-42AD-A9E5-6BF873E280AA}</ProjectGuid> - <RootNamespace>$(MSBuildProjectName)</RootNamespace> - <UMDF_VERSION_MAJOR>1</UMDF_VERSION_MAJOR> - <KMDF_VERSION_MAJOR>1</KMDF_VERSION_MAJOR> - <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration> - <Platform Condition="'$(Platform)' == ''">Win32</Platform> - <SampleGuid>{3A602CE0-07F1-41D2-BC96-23A8C5D3D0E4}</SampleGuid> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>False</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>True</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>False</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <TargetVersion>Windows10</TargetVersion> - <UseDebugLibraries>True</UseDebugLibraries> - <DriverTargetPlatform>Desktop</DriverTargetPlatform> - <DriverType>UMDF</DriverType> - <PlatformToolset>WindowsUserModeDriver10.0</PlatformToolset> - <ConfigurationType>DynamicLibrary</ConfigurationType> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> - <PropertyGroup> - <OutDir>$(IntDir)</OutDir> - </PropertyGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" /> - </ImportGroup> - <ItemGroup Label="WrappedTaskItems"> - <ClCompile Include="WpdWudfSampleDriver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Driver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Device.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Queue.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdBaseDriver.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectEnum.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectManagement.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectProperties.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectResources.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdCapabilities.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdObjectPropertiesBulk.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdStorage.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="WpdNetworkConfig.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <ClCompile Include="Helpers.cpp"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Use</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <Inf Include="WpdWudfSampleDriver.inx"> - <Architecture>$(InfArch)</Architecture> - <SpecifyArchitecture>true</SpecifyArchitecture> - <CopyOutput>.\$(IntDir)\WpdWudfSampleDriver.inf</CopyOutput> - </Inf> - <OtherWpp Include="WpdWudfSampleDriver.rc; WpdWudfSampleDriver.idl; DeviceObjectFakeContent.h; FakeContactContent.h; FakeContent.h; FakeDevice.h; FakeFolderContent.h; FakeImageContent.h; FakeMemoContent.h; FakeMusicContent.h; FakeVideoContent.h; NetworkConfigFakeContent.h; RenderingInformationFakeContent.h; StorageObjectFakeContent.h"> - <WppEnabled>true</WppEnabled> - <WppDllMacro>true</WppDllMacro> - <WppFileExtensions>.cpp.h.H</WppFileExtensions> - <WppPreserveExtensions>.h.H</WppPreserveExtensions> - <WppScanConfigurationData>stdafx.h</WppScanConfigurationData> - </OtherWpp> - </ItemGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <TargetName>WpdWudfSampleDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <TargetName>WpdWudfSampleDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <TargetName>WpdWudfSampleDriver</TargetName> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <TargetName>WpdWudfSampleDriver</TargetName> - </PropertyGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Link> - <EntryPointSymbol Condition="'$(Platform)'=='win32'">_DllMainCRTStartup@12</EntryPointSymbol> - <EntryPointSymbol Condition="'$(Platform)'!='win32'">_DllMainCRTStartup</EntryPointSymbol> - </Link> - </ItemDefinitionGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <UseOfAtl>Dynamic</UseOfAtl> - </PropertyGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <ExceptionHandling>Sync</ExceptionHandling> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <ExceptionHandling>Sync</ExceptionHandling> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <ExceptionHandling>Sync</ExceptionHandling> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <ClCompile> - <TreatWarningAsError>true</TreatWarningAsError> - <WarningLevel>Level4</WarningLevel> - <ExceptionHandling>Sync</ExceptionHandling> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SDK_INC_PATH)</AdditionalIncludeDirectories> - </ClCompile> - <ResourceCompile> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SDK_INC_PATH)</AdditionalIncludeDirectories> - </ResourceCompile> - <Midl> - <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(DDK_INC_PATH);$(SDK_INC_PATH)</AdditionalIncludeDirectories> - </Midl> - <Link> - <AdditionalDependencies>%(AdditionalDependencies);$(SDK_LIB_PATH)\strsafe.lib;$(SDK_LIB_PATH)\kernel32.lib;$(SDK_LIB_PATH)\ole32.lib;$(SDK_LIB_PATH)\oleaut32.lib;$(SDK_LIB_PATH)\uuid.lib;$(SDK_LIB_PATH)\user32.lib;$(SDK_LIB_PATH)\advapi32.lib;$(SDK_LIB_PATH)\shlwapi.lib;$(SDK_LIB_PATH)\PortableDeviceGuids.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Link> - <ModuleDefinitionFile>WpdWudfSampleDriver.def</ModuleDefinitionFile> - </Link> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Link> - <ModuleDefinitionFile>WpdWudfSampleDriver.def</ModuleDefinitionFile> - </Link> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Link> - <ModuleDefinitionFile>WpdWudfSampleDriver.def</ModuleDefinitionFile> - </Link> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Link> - <ModuleDefinitionFile>WpdWudfSampleDriver.def</ModuleDefinitionFile> - </Link> - <DriverSign> - <FileDigestAlgorithm>sha256</FileDigestAlgorithm> - </DriverSign> - </ItemDefinitionGroup> - <ItemGroup> - <ClCompile Include="Stdafxsrc.cpp"> - <AdditionalIncludeDirectories>;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreCompiledHeaderFile>Stdafx.h</PreCompiledHeaderFile> - <PreCompiledHeader>Create</PreCompiledHeader> - <PreCompiledHeaderOutputFile>$(IntDir)\Stdafx.h.pch</PreCompiledHeaderOutputFile> - </ClCompile> - <Midl Include="WpdWudfSampleDriver.idl" /> - <ResourceCompile Include="WpdWudfSampleDriver.rc" /> - </ItemGroup> - <ItemGroup> - <Inf Exclude="@(Inf)" Include="*.inf" /> - <FilesToPackage Include="$(TargetPath)" Condition="'$(ConfigurationType)'=='Driver' or '$(ConfigurationType)'=='DynamicLibrary'" /> - </ItemGroup> - <ItemGroup> - <None Exclude="@(None)" Include="*.txt;*.htm;*.html" /> - <None Exclude="@(None)" Include="*.ico;*.cur;*.bmp;*.dlg;*.rct;*.gif;*.jpg;*.jpeg;*.wav;*.jpe;*.tiff;*.tif;*.png;*.rc2" /> - <None Exclude="@(None)" Include="*.def;*.bat;*.hpj;*.asmx" /> - </ItemGroup> - <ItemGroup> - <ClInclude Exclude="@(ClInclude)" Include="*.h;*.hpp;*.hxx;*.hm;*.inl;*.xsd" /> - </ItemGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> -</Project>
\ No newline at end of file diff --git a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.vcxproj.Filters b/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.vcxproj.Filters deleted file mode 100644 index 25312bfa..00000000 --- a/wpd/WpdWudfSampleDriver/WpdWudfSampleDriver.vcxproj.Filters +++ /dev/null @@ -1,89 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup> - <Filter Include="Source Files"> - <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx;*</Extensions> - <UniqueIdentifier>{67CA94EC-D68D-4F71-99F5-60936D63553C}</UniqueIdentifier> - </Filter> - <Filter Include="Header Files"> - <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> - <UniqueIdentifier>{E3EAB4FD-41BF-487F-BF82-2FD11D9E6DBC}</UniqueIdentifier> - </Filter> - <Filter Include="Resource Files"> - <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms;man;xml</Extensions> - <UniqueIdentifier>{27BEF1DA-9389-4F74-9E59-5974CA70CF32}</UniqueIdentifier> - </Filter> - <Filter Include="Driver Files"> - <Extensions>inf;inv;inx;mof;mc;</Extensions> - <UniqueIdentifier>{27F470F7-CE41-4D4A-A7B2-8061E93B20D4}</UniqueIdentifier> - </Filter> - </ItemGroup> - <ItemGroup> - <ClCompile Include="Device.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Driver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Helpers.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Queue.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="Stdafxsrc.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdBaseDriver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdCapabilities.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdNetworkConfig.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectEnum.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectManagement.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectProperties.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectPropertiesBulk.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdObjectResources.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdStorage.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <ClCompile Include="WpdWudfSampleDriver.cpp"> - <Filter>Source Files</Filter> - </ClCompile> - <Midl Include="WpdWudfSampleDriver.idl"> - <Filter>Source Files</Filter> - </Midl> - <None Include="WpdWudfSampleDriver.def"> - <Filter>Source Files</Filter> - </None> - </ItemGroup> - <ItemGroup> - <Inf Include="WpdWudfSampleDriver.inx"> - <Filter>Driver Files</Filter> - </Inf> - </ItemGroup> - <ItemGroup> - <ResourceCompile Include="WpdWudfSampleDriver.rc"> - <Filter>Resource Files</Filter> - </ResourceCompile> - </ItemGroup> - <ItemGroup> - <ClInclude Include="WpdObjectResources.h"> - <Filter>Header Files</Filter> - </ClInclude> - </ItemGroup> -</Project>
\ No newline at end of file diff --git a/wpd/WpdWudfSampleDriver/helpers.cpp b/wpd/WpdWudfSampleDriver/helpers.cpp deleted file mode 100644 index 497ae61c..00000000 --- a/wpd/WpdWudfSampleDriver/helpers.cpp +++ /dev/null @@ -1,1600 +0,0 @@ -#include "stdafx.h" -#include "helpers.tmh" - -// Define the value for the registered WAVE format this driver uses -#ifndef WAVE_FORMAT_MSAUDIO3 - #define WAVE_FORMAT_MSAUDIO3 0x0162 -#endif - -#define VCARD_FORMAT "BEGIN:VCARD\r\nVERSION:2.1\r\nN:%ws;%ws\r\nFN:%ws\r\nORG:%ws\r\nTITLE:%ws\r\nTEL;HOME;VOICE:%ws\r\nTEL;WORK;VOICE:%ws\r\nTEL;CELL;VOICE:%ws\r\nTEL;WORK;FAX:%ws\r\nADR;HOME;ENCODING=QUOTED-PRINTABLE:;;%ws=0D=0A%ws;%ws;,;%ws;;REV:20051206T185151Z\r\nEND:VCARD\r\n" - -const PROPERTYKEY* g_SupportedPropertiesForFormatAll[] = -{ - &WPD_OBJECT_ID, - &WPD_OBJECT_PERSISTENT_UNIQUE_ID, - &WPD_OBJECT_PARENT_ID, - &WPD_OBJECT_NAME, - &WPD_OBJECT_CONTENT_TYPE, - &WPD_OBJECT_FORMAT, - &WPD_OBJECT_CAN_DELETE, - &WPD_OBJECT_ISHIDDEN, - &WPD_OBJECT_ISSYSTEM, - &WPD_OBJECT_NON_CONSUMABLE, -}; - -const PROPERTYKEY* g_SupportedPropertiesForFakeContentFormat[] = -{ - &WPD_OBJECT_ID, - &WPD_OBJECT_PERSISTENT_UNIQUE_ID, - &WPD_OBJECT_PARENT_ID, - &WPD_OBJECT_NAME, - &WPD_OBJECT_CONTENT_TYPE, - &WPD_OBJECT_FORMAT, - &WPD_OBJECT_CAN_DELETE, - &WPD_OBJECT_ISHIDDEN, - &WPD_OBJECT_ISSYSTEM, - &WPD_FOLDER_CONTENT_TYPES_ALLOWED, - &WPD_OBJECT_ORIGINAL_FILE_NAME, - &WPD_OBJECT_NON_CONSUMABLE, -}; - -const PROPERTYKEY* g_SupportedPropertiesForFakeDeviceContentFormat[] = -{ - &WPD_OBJECT_ID, - &WPD_OBJECT_PERSISTENT_UNIQUE_ID, - &WPD_OBJECT_PARENT_ID, - &WPD_OBJECT_NAME, - &WPD_OBJECT_CONTENT_TYPE, - &WPD_OBJECT_FORMAT, - &WPD_OBJECT_CAN_DELETE, - &WPD_OBJECT_ISHIDDEN, - &WPD_OBJECT_ISSYSTEM, - &WPD_DEVICE_SUPPORTS_NON_CONSUMABLE, - &WPD_OBJECT_NON_CONSUMABLE, - &WPD_FUNCTIONAL_OBJECT_CATEGORY, - &WPD_DEVICE_FIRMWARE_VERSION, - &WPD_DEVICE_POWER_LEVEL, - &WPD_DEVICE_POWER_SOURCE, - &WPD_DEVICE_PROTOCOL, - &WPD_DEVICE_MODEL, - &WPD_DEVICE_SERIAL_NUMBER, - &WPD_DEVICE_MANUFACTURER, - &WPD_DEVICE_TYPE, - &WPD_DEVICE_FRIENDLY_NAME, -}; - -const PROPERTYKEY* g_SupportedPropertiesForFakeStorageContentFormat[] = -{ - &WPD_OBJECT_ID, - &WPD_OBJECT_PERSISTENT_UNIQUE_ID, - &WPD_OBJECT_PARENT_ID, - &WPD_OBJECT_NAME, - &WPD_OBJECT_CONTENT_TYPE, - &WPD_OBJECT_FORMAT, - &WPD_OBJECT_CAN_DELETE, - &WPD_OBJECT_ISHIDDEN, - &WPD_OBJECT_ISSYSTEM, - &WPD_FOLDER_CONTENT_TYPES_ALLOWED, - &WPD_OBJECT_NON_CONSUMABLE, - &WPD_STORAGE_CAPACITY, - &WPD_STORAGE_FREE_SPACE_IN_BYTES, - &WPD_FUNCTIONAL_OBJECT_CATEGORY, - &WPD_STORAGE_TYPE, -}; - -const PROPERTYKEY* g_SupportedPropertiesForFakeImageContentFormat[] = -{ - &WPD_OBJECT_ID, - &WPD_OBJECT_PERSISTENT_UNIQUE_ID, - &WPD_OBJECT_PARENT_ID, - &WPD_OBJECT_NAME, - &WPD_OBJECT_CONTENT_TYPE, - &WPD_OBJECT_FORMAT, - &WPD_OBJECT_CAN_DELETE, - &WPD_OBJECT_ISHIDDEN, - &WPD_OBJECT_ISSYSTEM, - &WPD_OBJECT_NON_CONSUMABLE, - &WPD_MEDIA_HEIGHT, - &WPD_MEDIA_WIDTH, - &WPD_OBJECT_DATE_CREATED, - &WPD_OBJECT_ORIGINAL_FILE_NAME, - &WPD_OBJECT_SIZE, -}; - -const PROPERTYKEY* g_SupportedPropertiesForFakeMusicContentFormat[] = -{ - &WPD_OBJECT_ID, - &WPD_OBJECT_PERSISTENT_UNIQUE_ID, - &WPD_OBJECT_PARENT_ID, - &WPD_OBJECT_NAME, - &WPD_OBJECT_CONTENT_TYPE, - &WPD_OBJECT_FORMAT, - &WPD_OBJECT_CAN_DELETE, - &WPD_OBJECT_ISHIDDEN, - &WPD_OBJECT_ISSYSTEM, - &WPD_OBJECT_NON_CONSUMABLE, - &WPD_MEDIA_TITLE, - &WPD_MEDIA_ARTIST, - &WPD_MEDIA_DURATION, - &WPD_OBJECT_SIZE, - &WPD_OBJECT_DATE_AUTHORED, - &WPD_OBJECT_DATE_MODIFIED, - &WPD_MUSIC_ALBUM, - &WPD_MEDIA_GENRE, - &WPD_MUSIC_TRACK, - &WPD_OBJECT_ORIGINAL_FILE_NAME, -}; - -const PROPERTYKEY* g_SupportedPropertiesForFakeVideoContentFormat[] = -{ - &WPD_OBJECT_ID, - &WPD_OBJECT_PERSISTENT_UNIQUE_ID, - &WPD_OBJECT_PARENT_ID, - &WPD_OBJECT_NAME, - &WPD_OBJECT_CONTENT_TYPE, - &WPD_OBJECT_FORMAT, - &WPD_OBJECT_CAN_DELETE, - &WPD_OBJECT_ISHIDDEN, - &WPD_OBJECT_ISSYSTEM, - &WPD_OBJECT_NON_CONSUMABLE, - &WPD_MEDIA_TITLE, - &WPD_MEDIA_DURATION, - &WPD_OBJECT_SIZE, - &WPD_MEDIA_HEIGHT, - &WPD_MEDIA_WIDTH, - &WPD_OBJECT_DATE_AUTHORED, - &WPD_OBJECT_DATE_MODIFIED, - &WPD_OBJECT_ORIGINAL_FILE_NAME, - &WPD_VIDEO_SCAN_TYPE, - &WPD_VIDEO_BITRATE, - &WPD_VIDEO_FOURCC_CODE, - &WPD_OBJECT_GENERATE_THUMBNAIL_FROM_RESOURCE, -}; - -const PROPERTYKEY* g_SupportedPropertiesForFakeContactContentFormat[] = -{ - &WPD_OBJECT_ID, - &WPD_OBJECT_PERSISTENT_UNIQUE_ID, - &WPD_OBJECT_PARENT_ID, - &WPD_OBJECT_NAME, - &WPD_OBJECT_CONTENT_TYPE, - &WPD_OBJECT_FORMAT, - &WPD_OBJECT_CAN_DELETE, - &WPD_OBJECT_ISHIDDEN, - &WPD_OBJECT_ISSYSTEM, - &WPD_OBJECT_NON_CONSUMABLE, - &WPD_CONTACT_DISPLAY_NAME, - &WPD_CONTACT_PRIMARY_PHONE, - &WPD_CONTACT_MOBILE_PHONE, - &WPD_CONTACT_BUSINESS_PHONE, - &WPD_OBJECT_ORIGINAL_FILE_NAME, - &WPD_OBJECT_SIZE, -}; - -const PROPERTYKEY* g_SupportedPropertiesForRenderingInformation[] = -{ - &WPD_OBJECT_ID, - &WPD_OBJECT_PERSISTENT_UNIQUE_ID, - &WPD_OBJECT_PARENT_ID, - &WPD_OBJECT_NAME, - &WPD_OBJECT_CONTENT_TYPE, - &WPD_OBJECT_FORMAT, - &WPD_OBJECT_CAN_DELETE, - &WPD_OBJECT_ISHIDDEN, - &WPD_OBJECT_ISSYSTEM, - &WPD_OBJECT_NON_CONSUMABLE, - &WPD_FUNCTIONAL_OBJECT_CATEGORY, - &WPD_RENDERING_INFORMATION_PROFILES, -}; - -const PROPERTYKEY* g_SupportedPropertiesForNetworkConfiguration[] = -{ - &WPD_OBJECT_ID, - &WPD_OBJECT_PERSISTENT_UNIQUE_ID, - &WPD_OBJECT_PARENT_ID, - &WPD_OBJECT_NAME, - &WPD_OBJECT_CONTENT_TYPE, - &WPD_OBJECT_FORMAT, - &WPD_OBJECT_CAN_DELETE, - &WPD_OBJECT_ISHIDDEN, - &WPD_OBJECT_ISSYSTEM, - &WPD_FOLDER_CONTENT_TYPES_ALLOWED, - &WPD_OBJECT_NON_CONSUMABLE, - &WPD_FUNCTIONAL_OBJECT_CATEGORY, -}; - -const PROPERTYKEY* g_SupportedPropertiesForNetworkAssociation[] = -{ - &WPD_OBJECT_ID, - &WPD_OBJECT_PERSISTENT_UNIQUE_ID, - &WPD_OBJECT_PARENT_ID, - &WPD_OBJECT_NAME, - &WPD_OBJECT_CONTENT_TYPE, - &WPD_OBJECT_FORMAT, - &WPD_OBJECT_CAN_DELETE, - &WPD_OBJECT_ISHIDDEN, - &WPD_OBJECT_ISSYSTEM, - &WPD_OBJECT_NON_CONSUMABLE, - &WPD_NETWORK_ASSOCIATION_HOST_NETWORK_IDENTIFIERS, -}; - - -const PROPERTYKEY* g_SupportedPropertiesForMicrosoftWFC[] = -{ - &WPD_OBJECT_ID, - &WPD_OBJECT_PERSISTENT_UNIQUE_ID, - &WPD_OBJECT_PARENT_ID, - &WPD_OBJECT_NAME, - &WPD_OBJECT_CONTENT_TYPE, - &WPD_OBJECT_FORMAT, - &WPD_OBJECT_CAN_DELETE, - &WPD_OBJECT_ISHIDDEN, - &WPD_OBJECT_ISSYSTEM, - &WPD_OBJECT_NON_CONSUMABLE, -}; - -const PROPERTYKEY* g_SupportedPropertiesForFakeMemoContentFormat[] = -{ - &WPD_OBJECT_ID, - &WPD_OBJECT_PERSISTENT_UNIQUE_ID, - &WPD_OBJECT_PARENT_ID, - &WPD_OBJECT_NAME, - &WPD_OBJECT_CONTENT_TYPE, - &WPD_OBJECT_FORMAT, - &WPD_OBJECT_CAN_DELETE, - &WPD_OBJECT_ISHIDDEN, - &WPD_OBJECT_ISSYSTEM, - &WPD_OBJECT_NON_CONSUMABLE, - &WPD_OBJECT_SIZE, - &WPD_OBJECT_DATE_AUTHORED, - &WPD_OBJECT_DATE_MODIFIED, - &WPD_OBJECT_ORIGINAL_FILE_NAME, -}; - -KeyAndAttributesEntry g_FixedAttributesTable[] = -{ - // Properties for all objects, regardless of format - {&WPD_OBJECT_FORMAT_ALL, &WPD_OBJECT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_ALL, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_ALL, &WPD_OBJECT_PARENT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_ALL, &WPD_OBJECT_FORMAT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_ALL, &WPD_OBJECT_CONTENT_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_ALL, &WPD_OBJECT_CAN_DELETE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_ALL, &WPD_OBJECT_ISHIDDEN, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_ALL, &WPD_OBJECT_ISSYSTEM, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_ALL, &WPD_OBJECT_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - // Properties for generic objects - {&FakeContent_Format, &WPD_OBJECT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeContent_Format, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeContent_Format, &WPD_OBJECT_PARENT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeContent_Format, &WPD_OBJECT_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&FakeContent_Format, &WPD_OBJECT_FORMAT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeContent_Format, &WPD_OBJECT_CONTENT_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeContent_Format, &WPD_OBJECT_CAN_DELETE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeContent_Format, &WPD_OBJECT_ISHIDDEN, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeContent_Format, &WPD_OBJECT_ISSYSTEM, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeContent_Format, &WPD_FOLDER_CONTENT_TYPES_ALLOWED, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeContent_Format, &WPD_OBJECT_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeContent_Format, &WPD_OBJECT_ORIGINAL_FILE_NAME, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - // Properties for the device object - {&FakeDeviceContent_Format, &WPD_OBJECT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_OBJECT_PARENT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_OBJECT_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_OBJECT_FORMAT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_OBJECT_CONTENT_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_OBJECT_CAN_DELETE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_OBJECT_ISHIDDEN, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_OBJECT_ISSYSTEM, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_DEVICE_SUPPORTS_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_OBJECT_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_FUNCTIONAL_OBJECT_CATEGORY, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_DEVICE_FIRMWARE_VERSION, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_DEVICE_POWER_LEVEL, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_DEVICE_POWER_SOURCE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_DEVICE_PROTOCOL, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_DEVICE_MODEL, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_DEVICE_SERIAL_NUMBER, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_DEVICE_MANUFACTURER, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_DEVICE_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_DEVICE_NETWORK_IDENTIFIER, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_DEVICE_FRIENDLY_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&FakeDeviceContent_Format, &WPD_DEVICE_SYNC_PARTNER, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - // Properties for storage objects - {&FakeStorageContent_Format, &WPD_OBJECT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_OBJECT_PARENT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_OBJECT_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_OBJECT_FORMAT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_OBJECT_CONTENT_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_OBJECT_CAN_DELETE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_OBJECT_ISHIDDEN, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_OBJECT_ISSYSTEM, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_FOLDER_CONTENT_TYPES_ALLOWED, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_OBJECT_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_DEVICE_SUPPORTS_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_STORAGE_CAPACITY, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_STORAGE_FREE_SPACE_IN_BYTES, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_FUNCTIONAL_OBJECT_CATEGORY, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeStorageContent_Format, &WPD_STORAGE_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - // Properties for Image objects - {&WPD_OBJECT_FORMAT_EXIF, &WPD_OBJECT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_EXIF, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_EXIF, &WPD_OBJECT_PARENT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_EXIF, &WPD_OBJECT_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_EXIF, &WPD_OBJECT_CONTENT_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_EXIF, &WPD_OBJECT_FORMAT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_EXIF, &WPD_OBJECT_CAN_DELETE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_EXIF, &WPD_OBJECT_ISHIDDEN, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_EXIF, &WPD_OBJECT_ISSYSTEM, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_EXIF, &WPD_OBJECT_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_EXIF, &WPD_MEDIA_HEIGHT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_EXIF, &WPD_MEDIA_WIDTH, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_EXIF, &WPD_OBJECT_DATE_CREATED, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_EXIF, &WPD_OBJECT_ORIGINAL_FILE_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_EXIF, &WPD_OBJECT_SIZE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - // Properties for Music objects - {&WPD_OBJECT_FORMAT_WMA, &WPD_OBJECT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_OBJECT_PARENT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_OBJECT_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_OBJECT_CONTENT_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_OBJECT_FORMAT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_OBJECT_CAN_DELETE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_OBJECT_ISHIDDEN, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_OBJECT_ISSYSTEM, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_OBJECT_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_MEDIA_TITLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_MEDIA_ARTIST, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_MEDIA_DURATION, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_OBJECT_SIZE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_OBJECT_DATE_AUTHORED, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_OBJECT_DATE_MODIFIED, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_MUSIC_ALBUM, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_MEDIA_GENRE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_MUSIC_TRACK, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMA, &WPD_OBJECT_ORIGINAL_FILE_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - // Properties for video objects - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_PARENT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_CONTENT_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_FORMAT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_CAN_DELETE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_ISHIDDEN, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_ISSYSTEM, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_MEDIA_TITLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_MEDIA_DURATION, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_SIZE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_MEDIA_HEIGHT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_MEDIA_WIDTH, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_DATE_AUTHORED, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_DATE_MODIFIED, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_ORIGINAL_FILE_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_VIDEO_SCAN_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_VIDEO_BITRATE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_VIDEO_FOURCC_CODE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_WMV, &WPD_OBJECT_GENERATE_THUMBNAIL_FROM_RESOURCE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - // Properties for contact objects - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_OBJECT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_OBJECT_PARENT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_OBJECT_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_OBJECT_FORMAT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_OBJECT_CONTENT_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_OBJECT_CAN_DELETE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_OBJECT_ISHIDDEN, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_OBJECT_ISSYSTEM, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_OBJECT_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_CONTACT_DISPLAY_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_CONTACT_PRIMARY_PHONE, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_CONTACT_MOBILE_PHONE, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_CONTACT_BUSINESS_PHONE, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_OBJECT_ORIGINAL_FILE_NAME, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_VCARD2, &WPD_OBJECT_SIZE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - // Properties for Rendering Information object - {&WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, &WPD_OBJECT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, &WPD_OBJECT_PARENT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, &WPD_OBJECT_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, &WPD_OBJECT_FORMAT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, &WPD_OBJECT_CONTENT_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, &WPD_OBJECT_CAN_DELETE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, &WPD_OBJECT_ISHIDDEN, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, &WPD_OBJECT_ISSYSTEM, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, &WPD_OBJECT_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, &WPD_FUNCTIONAL_OBJECT_CATEGORY, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION, &WPD_RENDERING_INFORMATION_PROFILES, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - // Properties for Network Configuration object - {&WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, &WPD_OBJECT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, &WPD_OBJECT_PARENT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, &WPD_OBJECT_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, &WPD_OBJECT_FORMAT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, &WPD_OBJECT_CONTENT_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, &WPD_OBJECT_CAN_DELETE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, &WPD_OBJECT_ISHIDDEN, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, &WPD_OBJECT_ISSYSTEM, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, &WPD_FOLDER_CONTENT_TYPES_ALLOWED, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, &WPD_OBJECT_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION, &WPD_FUNCTIONAL_OBJECT_CATEGORY, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - // Properties for Network Association object - {&WPD_OBJECT_FORMAT_NETWORK_ASSOCIATION, &WPD_OBJECT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_NETWORK_ASSOCIATION, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_NETWORK_ASSOCIATION, &WPD_OBJECT_PARENT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_NETWORK_ASSOCIATION, &WPD_OBJECT_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_NETWORK_ASSOCIATION, &WPD_OBJECT_FORMAT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_NETWORK_ASSOCIATION, &WPD_OBJECT_CONTENT_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_NETWORK_ASSOCIATION, &WPD_OBJECT_CAN_DELETE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_NETWORK_ASSOCIATION, &WPD_OBJECT_ISHIDDEN, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_NETWORK_ASSOCIATION, &WPD_OBJECT_ISSYSTEM, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_NETWORK_ASSOCIATION, &WPD_OBJECT_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_NETWORK_ASSOCIATION, &WPD_NETWORK_ASSOCIATION_HOST_NETWORK_IDENTIFIERS, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - // Properties for Microsoft WFC object - {&WPD_OBJECT_FORMAT_MICROSOFT_WFC, &WPD_OBJECT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_MICROSOFT_WFC, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_MICROSOFT_WFC, &WPD_OBJECT_PARENT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_MICROSOFT_WFC, &WPD_OBJECT_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_MICROSOFT_WFC, &WPD_OBJECT_FORMAT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_MICROSOFT_WFC, &WPD_OBJECT_CONTENT_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_MICROSOFT_WFC, &WPD_OBJECT_CAN_DELETE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_MICROSOFT_WFC, &WPD_OBJECT_ISHIDDEN, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_MICROSOFT_WFC, &WPD_OBJECT_ISSYSTEM, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&WPD_OBJECT_FORMAT_MICROSOFT_WFC, &WPD_OBJECT_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - // Properties for Memo object - {&FakeMemoContent_Format, &WPD_OBJECT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeMemoContent_Format, &WPD_OBJECT_PERSISTENT_UNIQUE_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeMemoContent_Format, &WPD_OBJECT_PARENT_ID, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeMemoContent_Format, &WPD_OBJECT_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, - {&FakeMemoContent_Format, &WPD_OBJECT_FORMAT, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeMemoContent_Format, &WPD_OBJECT_CONTENT_TYPE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeMemoContent_Format, &WPD_OBJECT_CAN_DELETE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeMemoContent_Format, &WPD_OBJECT_ISHIDDEN, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeMemoContent_Format, &WPD_OBJECT_ISSYSTEM, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeMemoContent_Format, &WPD_OBJECT_NON_CONSUMABLE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeMemoContent_Format, &WPD_OBJECT_SIZE, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeMemoContent_Format, &WPD_OBJECT_DATE_AUTHORED, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeMemoContent_Format, &WPD_OBJECT_DATE_MODIFIED, UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast}, - {&FakeMemoContent_Format, &WPD_OBJECT_ORIGINAL_FILE_NAME, UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast}, -}; - -HRESULT AddPropertyKeyArrayToCollection( - _In_reads_(cKeys) const PROPERTYKEY** ppKeys, - const DWORD cKeys, - _In_ IPortableDeviceKeyCollection* pCollection) -{ - - HRESULT hr = S_OK; - - if (hr == S_OK) - { - // Add the keys - for (DWORD dwIndex = 0; dwIndex < cKeys; dwIndex++) - { - hr = pCollection->Add(*ppKeys[dwIndex]); - CHECK_HR(hr, "Failed to add key at index %d", dwIndex); - if (FAILED(hr)) - { - break; - } - } - } - - return hr; -} - -HRESULT AddFixedAttributesByType( - FakeDevicePropertyAttributesType AttributesType, - _In_ IPortableDeviceValues* pAttributes) -{ - - HRESULT hr = S_OK; - - if(pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - // Initialize our default values for the static attributes - DWORD dwForm = WPD_PROPERTY_ATTRIBUTE_FORM_UNSPECIFIED; - BOOL bCanRead = TRUE; - BOOL bCanWrite = FALSE; - BOOL bCanDelete = FALSE; - BOOL bFastProperty = TRUE; - - // Adjust the attributes for the specific property type if needed - if(AttributesType == UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast) - { - bCanWrite = TRUE; - } - - // Add the static attributes for this property. - if(hr == S_OK) - { - if (hr == S_OK) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_FORM, dwForm); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FORM"); - } - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_READ, bCanRead); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_READ"); - } - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_WRITE, bCanWrite); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_WRITE"); - } - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_CAN_DELETE, bCanDelete); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_CAN_DELETE"); - } - if (hr == S_OK) - { - hr = pAttributes->SetBoolValue(WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY, bFastProperty); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FAST_PROPERTY"); - } - } - - return hr; -} - -HRESULT AddFixedPropertyAttributes( - _In_ REFGUID guidObjectFormat, - _In_ REFPROPERTYKEY key, - _In_ IPortableDeviceValues* pAttributes) -{ - HRESULT hr = S_OK; - - if(pAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - if (hr == S_OK) - { - for (DWORD dwIndex = 0; dwIndex < ARRAYSIZE(g_FixedAttributesTable); dwIndex++) - { - if((*g_FixedAttributesTable[dwIndex].pFormat == guidObjectFormat) && - (IsEqualPropertyKey(*g_FixedAttributesTable[dwIndex].pKey, key))) - { - hr = AddFixedAttributesByType(g_FixedAttributesTable[dwIndex].type, pAttributes); - CHECK_HR(hr, "Failed to add fixed attributes for %ws.%d on format %ws", (LPWSTR)CComBSTR(key.fmtid), key.pid, (LPWSTR)CComBSTR(guidObjectFormat)); - break; - } - } - } - - return hr; -} - -HRESULT AddSupportedProperties( - _In_ REFGUID guidObjectFormatOrCategory, - _COM_Outptr_ IPortableDeviceKeyCollection** ppKeys) -{ - HRESULT hr = S_OK; - - if(ppKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - *ppKeys = NULL; - CComPtr<IPortableDeviceKeyCollection> pCollection; - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceKeyCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceKeyCollection, - (VOID**) &pCollection); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceKeyCollection"); - } - - if (SUCCEEDED(hr)) - { - hr = AddSupportedProperties(guidObjectFormatOrCategory, pCollection); - CHECK_HR(hr, "Failed to add supported properties"); - } - - if (SUCCEEDED(hr)) - { - hr = pCollection->QueryInterface(IID_PPV_ARGS(ppKeys)); - CHECK_HR(hr, "Failed to QI IPortableDeviceKeyCollection for IPortableDeviceKeyCollection"); - } - - return hr; -} - -HRESULT AddSupportedProperties( - _In_ REFGUID guidObjectFormatOrCategory, - _In_ IPortableDeviceKeyCollection* pKeys) -{ - HRESULT hr = S_OK; - - if(pKeys == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - if (guidObjectFormatOrCategory == WPD_OBJECT_FORMAT_ALL) - { - hr = AddPropertyKeyArrayToCollection(g_SupportedPropertiesForFormatAll, - ARRAYSIZE(g_SupportedPropertiesForFormatAll), - pKeys); - } else if (guidObjectFormatOrCategory == FakeContent_Format) - { - hr = AddPropertyKeyArrayToCollection(g_SupportedPropertiesForFakeContentFormat, - ARRAYSIZE(g_SupportedPropertiesForFakeContentFormat), - pKeys); - } - else if (guidObjectFormatOrCategory == WPD_OBJECT_FORMAT_EXIF) - { - hr = AddPropertyKeyArrayToCollection(g_SupportedPropertiesForFakeImageContentFormat, - ARRAYSIZE(g_SupportedPropertiesForFakeImageContentFormat), - pKeys); - } - else if (guidObjectFormatOrCategory == WPD_OBJECT_FORMAT_WMA) - { - hr = AddPropertyKeyArrayToCollection(g_SupportedPropertiesForFakeMusicContentFormat, - ARRAYSIZE(g_SupportedPropertiesForFakeMusicContentFormat), - pKeys); - } - else if (guidObjectFormatOrCategory == WPD_OBJECT_FORMAT_WMV) - { - hr = AddPropertyKeyArrayToCollection(g_SupportedPropertiesForFakeVideoContentFormat, - ARRAYSIZE(g_SupportedPropertiesForFakeVideoContentFormat), - pKeys); - } - else if (guidObjectFormatOrCategory == WPD_OBJECT_FORMAT_VCARD2) - { - hr = AddPropertyKeyArrayToCollection(g_SupportedPropertiesForFakeContactContentFormat, - ARRAYSIZE(g_SupportedPropertiesForFakeContactContentFormat), - pKeys); - } - else if (guidObjectFormatOrCategory == WPD_FUNCTIONAL_CATEGORY_RENDERING_INFORMATION) - { - hr = AddPropertyKeyArrayToCollection(g_SupportedPropertiesForRenderingInformation, - ARRAYSIZE(g_SupportedPropertiesForRenderingInformation), - pKeys); - } - else if (guidObjectFormatOrCategory == WPD_FUNCTIONAL_CATEGORY_NETWORK_CONFIGURATION) - { - hr = AddPropertyKeyArrayToCollection(g_SupportedPropertiesForNetworkConfiguration, - ARRAYSIZE(g_SupportedPropertiesForNetworkConfiguration), - pKeys); - } - else if (guidObjectFormatOrCategory == WPD_OBJECT_FORMAT_NETWORK_ASSOCIATION) - { - hr = AddPropertyKeyArrayToCollection(g_SupportedPropertiesForNetworkAssociation, - ARRAYSIZE(g_SupportedPropertiesForNetworkAssociation), - pKeys); - } - else if (guidObjectFormatOrCategory == WPD_OBJECT_FORMAT_MICROSOFT_WFC) - { - hr = AddPropertyKeyArrayToCollection(g_SupportedPropertiesForMicrosoftWFC, - ARRAYSIZE(g_SupportedPropertiesForMicrosoftWFC), - pKeys); - } - else if (guidObjectFormatOrCategory == WPD_FUNCTIONAL_CATEGORY_STORAGE) - { - hr = AddPropertyKeyArrayToCollection(g_SupportedPropertiesForFakeStorageContentFormat, - ARRAYSIZE(g_SupportedPropertiesForFakeStorageContentFormat), - pKeys); - } - else if (guidObjectFormatOrCategory == WPD_FUNCTIONAL_CATEGORY_DEVICE) - { - hr = AddPropertyKeyArrayToCollection(g_SupportedPropertiesForFakeDeviceContentFormat, - ARRAYSIZE(g_SupportedPropertiesForFakeDeviceContentFormat), - pKeys); - } - else if (guidObjectFormatOrCategory == FakeMemoContent_Format) - { - hr = AddPropertyKeyArrayToCollection(g_SupportedPropertiesForFakeMemoContentFormat, - ARRAYSIZE(g_SupportedPropertiesForFakeMemoContentFormat), - pKeys); - } - - return hr; -} - -HRESULT GetPreferredAudioProfile( - _COM_Outptr_ IPortableDeviceValues** ppProfile) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pProfile; - - if(ppProfile == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - *ppProfile = NULL; - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pProfile); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Set the value for WPD_OBJECT_FORMAT to indicate this profile applies to WMA objects - if (SUCCEEDED(hr)) - { - hr = pProfile->SetGuidValue(WPD_OBJECT_FORMAT, WPD_OBJECT_FORMAT_WMA); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT"); - } - - // Set the preferred value for WPD_MEDIA_TOTAL_BITRATE - if (SUCCEEDED(hr)) - { - hr = pProfile->SetUnsignedIntegerValue(WPD_MEDIA_TOTAL_BITRATE, 192000); - CHECK_HR(hr, "Failed to set WPD_MEDIA_TOTAL_BITRATE"); - } - - // Set the preferred value for WPD_AUDIO_CHANNEL_COUNT - if (SUCCEEDED(hr)) - { - hr = pProfile->SetUnsignedIntegerValue(WPD_AUDIO_CHANNEL_COUNT, 2); - CHECK_HR(hr, "Failed to set WPD_AUDIO_CHANNEL_COUNT"); - } - - // Set the preferred value for WPD_AUDIO_FORMAT_CODE - if (SUCCEEDED(hr)) - { - hr = pProfile->SetUnsignedIntegerValue(WPD_AUDIO_FORMAT_CODE, WAVE_FORMAT_MSAUDIO3); - CHECK_HR(hr, "Failed to set WPD_AUDIO_FORMAT_CODE"); - } - - // Set the output result - if (SUCCEEDED(hr)) - { - hr = pProfile->QueryInterface(IID_PPV_ARGS(ppProfile)); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues"); - } - - return hr; -} - -HRESULT GetAudioProfile2( - _COM_Outptr_ IPortableDeviceValues** ppProfile) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pProfile; - CComPtr<IPortableDeviceValues> pTotalBitRate; - - if(ppProfile == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - *ppProfile = NULL; - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pProfile); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pTotalBitRate); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Set the value for WPD_OBJECT_FORMAT to indicate this profile applies to WMA objects - if (SUCCEEDED(hr)) - { - hr = pProfile->SetGuidValue(WPD_OBJECT_FORMAT, WPD_OBJECT_FORMAT_WMA); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT"); - } - - // Set the value for WPD_MEDIA_TOTAL_BITRATE - if (SUCCEEDED(hr)) - { - // First, set the values for the range which will be contained in pTotalBitRate - hr = pTotalBitRate->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_FORM, WPD_PROPERTY_ATTRIBUTE_FORM_RANGE); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FORM for WPD_MEDIA_TOTAL_BITRATE"); - - if (SUCCEEDED(hr)) - { - hr = pTotalBitRate->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_RANGE_MIN, 64000); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_RANGE_MIN for WPD_MEDIA_TOTAL_BITRATE"); - } - if (SUCCEEDED(hr)) - { - hr = pTotalBitRate->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_RANGE_MAX, 256000); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_RANGE_MAX for WPD_MEDIA_TOTAL_BITRATE"); - } - if (SUCCEEDED(hr)) - { - hr = pTotalBitRate->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_RANGE_STEP, 1000); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_RANGE_STEP for WPD_MEDIA_TOTAL_BITRATE"); - } - - // Now set the bit rate property to be pTotalBitRate - if (SUCCEEDED(hr)) - { - hr = pProfile->SetIPortableDeviceValuesValue(WPD_MEDIA_TOTAL_BITRATE, pTotalBitRate); - CHECK_HR(hr, "Failed to set WPD_MEDIA_TOTAL_BITRATE"); - } - } - - // Set the value for WPD_AUDIO_CHANNEL_COUNT - if (SUCCEEDED(hr)) - { - hr = pProfile->SetUnsignedIntegerValue(WPD_AUDIO_CHANNEL_COUNT, 2); - CHECK_HR(hr, "Failed to set WPD_AUDIO_CHANNEL_COUNT"); - } - - // Set the value for WPD_AUDIO_FORMAT_CODE - if (SUCCEEDED(hr)) - { - hr = pProfile->SetUnsignedIntegerValue(WPD_AUDIO_FORMAT_CODE, WAVE_FORMAT_MSAUDIO3); - CHECK_HR(hr, "Failed to set WPD_AUDIO_FORMAT_CODE"); - } - - // Set the output result - if (SUCCEEDED(hr)) - { - hr = pProfile->QueryInterface(IID_PPV_ARGS(ppProfile)); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues"); - } - - return hr; -} - -HRESULT GetVideoProfile( - _COM_Outptr_ IPortableDeviceValues** ppProfile) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pProfile; - CComPtr<IPortableDeviceValues> pFourCCCode; - - if(ppProfile == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - *ppProfile = NULL; - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pProfile); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pFourCCCode); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValues"); - } - - // Set the value for WPD_OBJECT_FORMAT to indicate this profile applies to WMV objects - if (SUCCEEDED(hr)) - { - hr = pProfile->SetGuidValue(WPD_OBJECT_FORMAT, WPD_OBJECT_FORMAT_WMV); - CHECK_HR(hr, "Failed to set WPD_OBJECT_FORMAT to WPD_OBJECT_FORMAT_WMV for the rendering profile"); - } - - - // Set the value for WPD_VIDEO_FOURCC_CODE - if (SUCCEEDED(hr)) - { - CComPtr<IPortableDevicePropVariantCollection> pFourCCCodeEnumElements; - - hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDevicePropVariantCollection, - (VOID**) &pFourCCCodeEnumElements); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDevicePropVariantCollection"); - - if (SUCCEEDED(hr)) - { - hr = pFourCCCode->SetUnsignedIntegerValue(WPD_PROPERTY_ATTRIBUTE_FORM, WPD_PROPERTY_ATTRIBUTE_FORM_ENUMERATION); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_FORM for WPD_VIDEO_FOURCC_CODE"); - } - - if (SUCCEEDED(hr)) - { - // Only 1 sample value is set here, add more as appropriate for your device - PROPVARIANT pvValue; - PropVariantInit(&pvValue); - pvValue.vt = VT_UI4; - pvValue.ulVal = MAKEFOURCC('W', 'M', 'V', '3'); // No need to PropVariantClear as we are assigning a value - hr = pFourCCCodeEnumElements->Add(&pvValue); - CHECK_HR(hr, "Failed to populate the FourCC Code Enumeration Elements"); - } - - if (SUCCEEDED(hr)) - { - hr = pFourCCCode->SetIPortableDevicePropVariantCollectionValue(WPD_PROPERTY_ATTRIBUTE_ENUMERATION_ELEMENTS, pFourCCCodeEnumElements); - CHECK_HR(hr, "Failed to set WPD_PROPERTY_ATTRIBUTE_ENUMERATION_ELEMENTS for WPD_VIDEO_FOURCC_CODE"); - } - - // Now set the Video FourCC Code property to be pFourCCCode - if (SUCCEEDED(hr)) - { - hr = pProfile->SetIPortableDeviceValuesValue(WPD_VIDEO_FOURCC_CODE, pFourCCCode); - CHECK_HR(hr, "Failed to add the WPD_VIDEO_FOURCC_CODE attributes to the WPD_OBJECT_FORMAT_WMV rendering profile"); - } - } - - // Set the output result - if (SUCCEEDED(hr)) - { - hr = pProfile->QueryInterface(IID_PPV_ARGS(ppProfile)); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues"); - } - - return hr; -} - -HRESULT SetRenderingProfiles( - _In_ IPortableDeviceValues* pValues) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pPreferredAudioProfile; - CComPtr<IPortableDeviceValues> pAudioProfile2; - CComPtr<IPortableDeviceValues> pVideoProfile; - - CComPtr<IPortableDeviceValuesCollection> pProfiles; - - if(pValues == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - // Create the collection to hold the profiles - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValuesCollection, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValuesCollection, - (VOID**) &pProfiles); - CHECK_HR(hr, "Failed to CoCreateInstance CLSID_PortableDeviceValuesCollection"); - } - - // Get the preferred audio profile - if (hr == S_OK) - { - hr = GetPreferredAudioProfile(&pPreferredAudioProfile); - CHECK_HR(hr, "Failed to get preferred audio profile properties"); - } - - // Add the profile - if (hr == S_OK) - { - hr = pProfiles->Add(pPreferredAudioProfile); - CHECK_HR(hr, "Failed to add preferred audio profile to profile collection"); - } - - // Get the second audio profile - if (hr == S_OK) - { - hr = GetAudioProfile2(&pAudioProfile2); - CHECK_HR(hr, "Failed to get second audio profile properties"); - } - - // Add the profile - if (hr == S_OK) - { - hr = pProfiles->Add(pAudioProfile2); - CHECK_HR(hr, "Failed to add second audio profile to profile collection"); - } - - // Get the video profile - if (hr == S_OK) - { - hr = GetVideoProfile(&pVideoProfile); - CHECK_HR(hr, "Failed to get video profile properties"); - } - - // Add the profile - if (hr == S_OK) - { - hr = pProfiles->Add(pVideoProfile); - CHECK_HR(hr, "Failed to add second audio profile to profile collection"); - } - - // Set the WPD_RENDERING_INFORMATION_PROFILES - if (hr == S_OK) - { - hr = pValues->SetIPortableDeviceValuesCollectionValue(WPD_RENDERING_INFORMATION_PROFILES, pProfiles); - CHECK_HR(hr, "Failed to set WPD_RENDERING_INFORMATION_PROFILES"); - } - - return hr; -} - -DWORD GetResourceSize( - UINT uiResource) -{ - HRESULT hr = S_OK; - LONG lError = ERROR_SUCCESS; - DWORD dwResourceSize = 0; - - HRSRC hResource = FindResource(g_hInstance, MAKEINTRESOURCE(uiResource), TEXT("DATA_FILE")); - if (hResource) - { - HGLOBAL hGlobal = LoadResource(g_hInstance, hResource); - if (hGlobal) - { - dwResourceSize = SizeofResource(g_hInstance, hResource); - } - else - { - lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - } - else - { - lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get resource size for '%d'", uiResource); - } - - return dwResourceSize; -} - -PBYTE GetResourceData( - UINT uiResource) -{ - HRESULT hr = S_OK; - LONG lError = ERROR_SUCCESS; - PBYTE pData = NULL; - - HRSRC hResource = FindResource(g_hInstance, MAKEINTRESOURCE(uiResource), TEXT("DATA_FILE")); - if (hResource) - { - HGLOBAL hGlobal = LoadResource(g_hInstance, hResource); - if (hGlobal) - { - pData = static_cast<BYTE*>(LockResource(hGlobal)); - } - else - { - lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - } - else - { - lError = GetLastError(); - hr = HRESULT_FROM_WIN32(lError); - } - - if (FAILED(hr)) - { - CHECK_HR(hr, "Failed to get resource data pointer for '%d'", uiResource); - } - - return pData; -} - -HRESULT IsValidContentType( - _In_ REFGUID guidObjectContentType, - _In_ CAtlArray<GUID>& RestrictedTypes) -{ - HRESULT hr = S_OK; - - size_t numElems = RestrictedTypes.GetCount(); - if(numElems > 0) - { - BOOL bContentTypeAllowed = FALSE; - for(size_t typeIndex = 0; typeIndex < numElems; typeIndex++) - { - if(RestrictedTypes[typeIndex] == guidObjectContentType) - { - bContentTypeAllowed = TRUE; - } - } - if(!bContentTypeAllowed) - { - hr = E_INVALIDARG; - CHECK_HR(hr, "Parent Object does not allow creation of content type %ws", CComBSTR(guidObjectContentType)); - } - } - - return hr; -} - -HRESULT GetClientContext( - _In_ IPortableDeviceValues* pParams, - _In_ LPCWSTR pszContextKey, - _COM_Outptr_ IUnknown** ppContext) -{ - HRESULT hr = S_OK; - ContextMap* pContextMap = NULL; - - if(ppContext == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, ("Cannot have NULL parameter")); - return hr; - } - - *ppContext = NULL; - - if (SUCCEEDED(hr)) - { - hr = pParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, (IUnknown**) &pContextMap); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP"); - } - - if (SUCCEEDED(hr) && pContextMap == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Client context map is NULL"); - } - - if (SUCCEEDED(hr)) - { - *ppContext = pContextMap->GetContext(pszContextKey); - if(*ppContext == NULL) - { - hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); - CHECK_HR(hr, "Failed to find context %ws for this client", pszContextKey); - } - } - - SAFE_RELEASE(pContextMap); - - return hr; -} - -HRESULT GetClientEventCookie( - _In_ IPortableDeviceValues* pParams, - _Outptr_result_maybenull_ LPWSTR* ppszEventCookie) -{ - HRESULT hr = S_OK; - LPWSTR pszClientContext = NULL; - ClientContext* pClientContext = NULL; - - if ((pParams == NULL) || - (ppszEventCookie == NULL)) - { - return E_POINTER; - } - - *ppszEventCookie = NULL; - - hr = pParams->GetStringValue(WPD_PROPERTY_COMMON_CLIENT_INFORMATION_CONTEXT, &pszClientContext); - CHECK_HR(hr, "Missing value for WPD_PROPERTY_COMMON_CLIENT_INFORMATION_CONTEXT"); - - if (SUCCEEDED(hr)) - { - // Get the client context for this request. - hr = GetClientContext(pParams, pszClientContext, (IUnknown**)&pClientContext); - CHECK_HR(hr, "Failed to get the client context"); - } - - if (SUCCEEDED(hr) && (pClientContext->EventCookie.GetLength() > 0)) - { - // Get the event cookie only if it has been set - *ppszEventCookie = AtlAllocTaskWideString(pClientContext->EventCookie); - if (*ppszEventCookie == NULL) - { - hr = E_OUTOFMEMORY; - CHECK_HR(hr, "Failed to allocate the client event cookie"); - } - } - - // We're done with the context - SAFE_RELEASE(pClientContext); - - CoTaskMemFree(pszClientContext); - pszClientContext = NULL; - - return hr; -} - -HRESULT PostWpdEvent( - _In_ IPortableDeviceValues* pCommandParams, - _In_ IPortableDeviceValues* pEventParams) -{ - HRESULT hr = S_OK; - BYTE* pBuffer = NULL; - DWORD cbBuffer = 0; - LPWSTR pszEventCookie = NULL; - - CComPtr<IWDFDevice> pDevice; - CComPtr<IWpdSerializer> pSerializer; - - // Get the WUDF Device Object - hr = pCommandParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT, (IUnknown**) &pDevice); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT"); - - // Get the WpdSerializer Object - if (hr == S_OK) - { - hr = pCommandParams->GetIUnknownValue(PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT, (IUnknown**) &pSerializer); - CHECK_HR(hr, "Failed to get PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT"); - } - - if (hr == S_OK) - { - // Set the client event cookie if available. This is benign, as some clients may not provide a cookie. - HRESULT hrEventCookie = GetClientEventCookie(pCommandParams, &pszEventCookie); - if ((hrEventCookie == S_OK) && (pszEventCookie != NULL)) - { - hrEventCookie = pEventParams->SetStringValue(WPD_CLIENT_EVENT_COOKIE, pszEventCookie); - CHECK_HR(hrEventCookie, "Failed to set WPD_CLIENT_EVENT_COOKIE (error ignored)"); - } - } - - if (hr == S_OK) - { - // Create a buffer with the serialized parameters - hr = pSerializer->GetBufferFromIPortableDeviceValues(pEventParams, &pBuffer, &cbBuffer); - CHECK_HR(hr, "Failed to get buffer from IPortableDeviceValues"); - } - - // Send the event - if (hr == S_OK && pBuffer != NULL) - { - hr = pDevice->PostEvent(WPD_EVENT_NOTIFICATION, WdfEventBroadcast, pBuffer, cbBuffer); - CHECK_HR(hr, "Failed to post WPD (broadcast) event"); - } - - // Free the memory - CoTaskMemFree(pBuffer); - pBuffer = NULL; - - CoTaskMemFree(pszEventCookie); - pszEventCookie = NULL; - - return hr; -} - -HRESULT PostWpdEventWithProgress( - _In_ IPortableDeviceValues* pCommandParams, - _In_ IPortableDeviceValues* pEventParams, - _In_ REFGUID guidEvent, - const DWORD dwOperationState, - const DWORD dwOperationProgress) -{ - HRESULT hr = S_OK; - - if((pCommandParams == NULL) || (pEventParams == NULL)) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL parameter"); - return hr; - } - - hr = pEventParams->SetGuidValue(WPD_EVENT_PARAMETER_EVENT_ID, guidEvent); - CHECK_HR(hr, "Failed to set WPD_EVENT_PARAMETER_EVENT_ID"); - - if (hr == S_OK) - { - hr = pEventParams->SetUnsignedIntegerValue(WPD_EVENT_PARAMETER_OPERATION_STATE, dwOperationState); - CHECK_HR(hr, "Failed to set WPD_EVENT_PARAMETER_OPERATION_STATE"); - } - - if (hr == S_OK) - { - hr = pEventParams->SetUnsignedIntegerValue(WPD_EVENT_PARAMETER_OPERATION_PROGRESS, dwOperationProgress); - CHECK_HR(hr, "Failed to set WPD_EVENT_PARAMETER_OPERATION_PROGRESS"); - } - - if (hr == S_OK) - { - hr = PostWpdEvent(pCommandParams, pEventParams); - CHECK_HR(hr, "Failed to post event with progress"); - } - - return hr; -} - - -BOOL ExistsInCollection( - _In_ REFGUID guid, - _In_ IPortableDevicePropVariantCollection* pCollection) -{ - HRESULT hr = S_OK; - - BOOL bFound = FALSE; - DWORD dwNumGuids = 0; - - if(pCollection != NULL) - { - hr = pCollection->GetCount(&dwNumGuids); - if (SUCCEEDED(hr)) - { - // Loop through each guid in the collection - for (DWORD dwIndex = 0; dwIndex < dwNumGuids; dwIndex++) - { - PROPVARIANT pv = {0}; - PropVariantInit(&pv); - hr = pCollection->GetAt(dwIndex, &pv); - if (SUCCEEDED(hr)) - { - if ((pv.puuid != NULL) && (pv.vt == VT_CLSID)) - { - bFound = IsEqualGUID(guid, *pv.puuid); - } - } - - PropVariantClear(&pv); - - if (bFound == TRUE) - { - break; - } - } - } - } - - return bFound; -} - -HRESULT GetAtlStringValue( - _In_ REFPROPERTYKEY Key, - _In_ IPortableDeviceValues* pValues, - _Out_ CAtlStringW& strValue) -{ - HRESULT hr = S_OK; - LPWSTR wszValue = NULL; - strValue = L""; - - if (pValues == NULL) - { - hr = E_POINTER; - return hr; - } - - hr = pValues->GetStringValue(Key, &wszValue); - if (hr == S_OK) - { - strValue = wszValue; - } - - if (wszValue != NULL) - { - CoTaskMemFree(wszValue); - wszValue = NULL; - } - - return hr; -} - -HRESULT CreateVCard( - _In_ IPortableDeviceValues* pValues, - _Out_ CAtlStringA& strVCard) -{ - CAtlStringW strLastName; // WPD_CONTACT_LAST_NAME - CAtlStringW strFirstName; // WPD_CONTACT_FIRST_NAME - CAtlStringW strDisplayName; // WPD_CONTACT_DISPLAY_NAME - CAtlStringW strCompanyName; // WPD_CONTACT_COMPANY_NAME - CAtlStringW strRole; // WPD_CONTACT_ROLE - CAtlStringW strPrimaryPhoneNumber; // WPD_CONTACT_PRIMARY_PHONE or WPD_CONTACT_PERSONAL_PHONE - CAtlStringW strBusinessPhoneNumber; // WPD_CONTACT_BUSINESS_PHONE - CAtlStringW strMobilePhoneNumber; // WPD_CONTACT_MOBILE_PHONE - CAtlStringW strPrimaryFaxPhoneNumber; // WPD_CONTACT_PRIMARY_FAX - CAtlStringW strAddressLine1; // WPD_CONTACT_PERSONAL_POSTAL_ADDRESS_LINE1 - CAtlStringW strAddressLine2; // WPD_CONTACT_PERSONAL_POSTAL_ADDRESS_LINE2 - CAtlStringW strAddressCity; // WPD_CONTACT_PERSONAL_POSTAL_ADDRESS_CITY - CAtlStringW strAddressPostalCode; // WPD_CONTACT_PERSONAL_POSTAL_ADDRESS_POSTAL_CODE - - if (pValues != NULL) - { - // Read the contact property values from IPortableDeviceValues - // NOTE: ALL values are not required to be present to create a valid VCARD file. If no properties are - // found then a blank VCARD will be created. - GetAtlStringValue(WPD_CONTACT_LAST_NAME, pValues, strLastName); // WPD_CONTACT_LAST_NAME - GetAtlStringValue(WPD_CONTACT_FIRST_NAME, pValues, strFirstName); // WPD_CONTACT_FIRST_NAME - GetAtlStringValue(WPD_CONTACT_DISPLAY_NAME, pValues, strDisplayName); // WPD_CONTACT_DISPLAY_NAME - GetAtlStringValue(WPD_CONTACT_COMPANY_NAME, pValues, strCompanyName); // WPD_CONTACT_COMPANY_NAME - GetAtlStringValue(WPD_CONTACT_ROLE, pValues, strRole); // WPD_CONTACT_ROLE - GetAtlStringValue(WPD_CONTACT_PRIMARY_PHONE, pValues, strPrimaryPhoneNumber); // WPD_CONTACT_PRIMARY_PHONE or WPD_CONTACT_PERSONAL_PHONE - GetAtlStringValue(WPD_CONTACT_BUSINESS_PHONE, pValues, strBusinessPhoneNumber); // WPD_CONTACT_BUSINESS_PHONE - GetAtlStringValue(WPD_CONTACT_MOBILE_PHONE, pValues, strMobilePhoneNumber); // WPD_CONTACT_MOBILE_PHONE - GetAtlStringValue(WPD_CONTACT_PRIMARY_FAX, pValues, strPrimaryFaxPhoneNumber); // WPD_CONTACT_PRIMARY_FAX - GetAtlStringValue(WPD_CONTACT_PERSONAL_POSTAL_ADDRESS_LINE1, pValues, strAddressLine1); // WPD_CONTACT_PERSONAL_POSTAL_ADDRESS_LINE1 - GetAtlStringValue(WPD_CONTACT_PERSONAL_POSTAL_ADDRESS_LINE2, pValues, strAddressLine2); // WPD_CONTACT_PERSONAL_POSTAL_ADDRESS_LINE2 - GetAtlStringValue(WPD_CONTACT_PERSONAL_POSTAL_ADDRESS_CITY, pValues, strAddressCity); // WPD_CONTACT_PERSONAL_POSTAL_ADDRESS_CITY - GetAtlStringValue(WPD_CONTACT_PERSONAL_POSTAL_ADDRESS_POSTAL_CODE, pValues, strAddressPostalCode); // WPD_CONTACT_PERSONAL_POSTAL_ADDRESS_POSTAL_CODE - } - - // Create the VCARD from the properties found in the IPortableDeviceValues - strVCard.Format(VCARD_FORMAT, strLastName.GetString(), strFirstName.GetString(), - strDisplayName.GetString(), - strCompanyName.GetString(), - strRole.GetString(), - strPrimaryPhoneNumber.GetString(), - strBusinessPhoneNumber.GetString(), - strMobilePhoneNumber.GetString(), - strPrimaryFaxPhoneNumber.GetString(), - strAddressLine1.GetString(), strAddressLine2.GetString(), - strAddressCity.GetString(), strAddressPostalCode.GetString()); - return S_OK; -} - -HRESULT UpdateDeviceFriendlyName( - _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension, - _In_ LPCWSTR wszDeviceFriendlyName) -{ - HRESULT hr = S_OK; - - // If we were passed NULL parameters we have nothing to do, return S_OK. - if ((pPortableDeviceClassExtension == NULL) || (wszDeviceFriendlyName == NULL)) - { - return S_OK; - } - - CComPtr<IPortableDeviceValues> pParams; - CComPtr<IPortableDeviceValues> pResults; - CComPtr<IPortableDeviceValues> pValues; - - // Prepare to make a call to set the device information - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, NULL, CLSCTX_INPROC_SERVER, IID_IPortableDeviceValues, (VOID**)&pParams); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, NULL, CLSCTX_INPROC_SERVER, IID_IPortableDeviceValues, (VOID**)&pResults); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues for results"); - } - - if (hr == S_OK) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, NULL, CLSCTX_INPROC_SERVER, IID_IPortableDeviceValues, (VOID**)&pValues); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues for results"); - } - - // Get the information values to update and set them in WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES - if (hr == S_OK) - { - hr = pValues->SetStringValue(WPD_DEVICE_FRIENDLY_NAME, wszDeviceFriendlyName); - CHECK_HR(hr, ("Failed to set WPD_DEVICE_FRIENDLY_NAME")); - } - - // Set the params - if (hr == S_OK) - { - hr = pParams->SetGuidValue(WPD_PROPERTY_COMMON_COMMAND_CATEGORY, WPD_COMMAND_CLASS_EXTENSION_WRITE_DEVICE_INFORMATION.fmtid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_CATEGORY")); - } - if (hr == S_OK) - { - hr = pParams->SetUnsignedIntegerValue(WPD_PROPERTY_COMMON_COMMAND_ID, WPD_COMMAND_CLASS_EXTENSION_WRITE_DEVICE_INFORMATION.pid); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_COMMON_COMMAND_ID")); - } - if (hr == S_OK) - { - hr = pParams->SetIPortableDeviceValuesValue(WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES, pValues); - CHECK_HR(hr, ("Failed to set WPD_PROPERTY_CLASS_EXTENSION_DEVICE_INFORMATION_VALUES")); - } - - // Make the call - if (hr == S_OK) - { - hr = pPortableDeviceClassExtension->ProcessLibraryMessage(pParams, pResults); - CHECK_HR(hr, ("Failed to process update device information message")); - } - - // A Failed ProcessLibraryMessage operation for updating this value is not considered - // fatal and should return S_OK. - - return S_OK; -} - -HRESULT GetCommonResourceAttributes( - _COM_Outptr_ IPortableDeviceValues** ppAttributes) -{ - HRESULT hr = S_OK; - CComPtr<IPortableDeviceValues> pAttributes; - - if(ppAttributes == NULL) - { - hr = E_POINTER; - CHECK_HR(hr, "Cannot have NULL attributes parameter"); - return hr; - } - - *ppAttributes = NULL; - - if (SUCCEEDED(hr)) - { - hr = CoCreateInstance(CLSID_PortableDeviceValues, - NULL, - CLSCTX_INPROC_SERVER, - IID_IPortableDeviceValues, - (VOID**) &pAttributes); - CHECK_HR(hr, "Failed to CoCreate CLSID_PortableDeviceValues"); - } - - // Add the attributes that are common to all our resources. - if (SUCCEEDED(hr)) - { - // Add a default value for size. This will be overridden by the content objects with the actual value. - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE, FAKE_DATA_SIZE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_TOTAL_SIZE"); - } - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_READ, TRUE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_READ"); - } - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_WRITE, FALSE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_WRITE"); - } - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetBoolValue(WPD_RESOURCE_ATTRIBUTE_CAN_DELETE, FALSE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_CAN_DELETE"); - } - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_OPTIMAL_READ_BUFFER_SIZE, OPTIMAL_BUFFER_SIZE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_OPTIMAL_READ_BUFFER_SIZE"); - } - if (SUCCEEDED(hr)) - { - hr = pAttributes->SetUnsignedIntegerValue(WPD_RESOURCE_ATTRIBUTE_OPTIMAL_WRITE_BUFFER_SIZE, OPTIMAL_BUFFER_SIZE); - CHECK_HR(hr, "Failed to set WPD_RESOURCE_ATTRIBUTE_OPTIMAL_WRITE_BUFFER_SIZE"); - } - - // Return the resource attributes - if (SUCCEEDED(hr)) - { - hr = pAttributes->QueryInterface(IID_IPortableDeviceValues, (VOID**) ppAttributes); - CHECK_HR(hr, "Failed to QI for IPortableDeviceValues on Wpd IPortableDeviceValues"); - } - return hr; -} - - diff --git a/wpd/WpdWudfSampleDriver/helpers.h b/wpd/WpdWudfSampleDriver/helpers.h deleted file mode 100644 index d2e2cf18..00000000 --- a/wpd/WpdWudfSampleDriver/helpers.h +++ /dev/null @@ -1,188 +0,0 @@ -#pragma once - -#define FAKE_DATA_SIZE (5 * 1024 * 1024 + 1831) -#define OPTIMAL_BUFFER_SIZE (2 * 1024 * 1024) - -// {9b2dce3f-cf02-4643-ae09-2bcf0012ac6d} -DEFINE_GUID(FakeContent_Format, 0x9b2dce3f, 0xcf02, 0x4643, 0xae, 0x09, 0x2b, 0xcf, 0x00, 0x12, 0xac, 0x6d); -// {8E829938-D838-479E-8489-5EC84986EE3B} -DEFINE_GUID(FakeDeviceContent_Format, 0x8E829938, 0xD838, 0x479E, 0x84, 0x89, 0x5E, 0xC8, 0x49, 0x86, 0xEE, 0x3B); -// {BDC7BBF8-3AAC-458F-92C9-7CD236186552} -DEFINE_GUID(FakeStorageContent_Format, 0xBDC7BBF8, 0x3AAC, 0x458F, 0x92, 0xC9, 0x7C, 0xD2, 0x36, 0x18, 0x65, 0x52); -// We will define a custom format for memo objects: {C6F2ECC0-C351-42D6-AE20-837CE1EF433C} -DEFINE_GUID(FakeMemoContent_Format, 0xC6F2ECC0, 0xC351, 0x42D6, 0xAE, 0x20, 0x83, 0x7C, 0xE1, 0xEF, 0x43, 0x3C); - -// {4DF6C8C7-2CE5-457C-9F53-EFCECAA95C04} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_CLIENT_CONTEXT_MAP, 0x4DF6C8C7, 0x2CE5, 0x457C, 0x9F, 0x53, 0xEF, 0xCE, 0xCA, 0xA9, 0x5C, 0x04, 2); -// {CDD18979-A7B0-4D5E-9EB2-0A826805CBBD} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_WUDF_DEVICE_OBJECT, 0xCDD18979, 0xA7B0, 0x4D5E, 0x9E, 0xB2, 0x0A, 0x82, 0x68, 0x05, 0xCB, 0xBD, 2); -// {9BD949E5-59CF-41AE-90A9-BE1D044F578F} -DEFINE_PROPERTYKEY(PRIVATE_SAMPLE_DRIVER_WPD_SERIALIZER_OBJECT, 0x9BD949E5, 0x59CF, 0x41AE, 0x90, 0xA9, 0xBE, 0x1D, 0x04, 0x4F, 0x57, 0x8F, 2); - -#ifndef SAFE_RELEASE - #define SAFE_RELEASE(p) if( NULL != p ) { ( p )->Release(); p = NULL; } -#endif - -typedef enum tagFakeDevicePropertyAttributesType -{ - UnspecifiedForm_CanRead_CanWrite_CannotDelete_Fast, - UnspecifiedForm_CanRead_CannotWrite_CannotDelete_Fast, -} FakeDevicePropertyAttributesType; - -typedef struct tagKeyAndAttributesEntry -{ - const GUID* pFormat; - const PROPERTYKEY* pKey; - FakeDevicePropertyAttributesType type; -} KeyAndAttributesEntry; - -HRESULT AddFixedAttributesByType( - FakeDevicePropertyAttributesType AttributesType, - _In_ IPortableDeviceValues* pAttributes); - -HRESULT AddFixedPropertyAttributes( - _In_ REFGUID guidObjectFormat, - _In_ REFPROPERTYKEY key, - _In_ IPortableDeviceValues* pAttributes); - -HRESULT AddSupportedProperties( - _In_ REFGUID guidObjectFormatOrCategory, - _COM_Outptr_ IPortableDeviceKeyCollection** ppKeys); - -HRESULT AddSupportedProperties( - _In_ REFGUID guidObjectFormatOrCategory, - _In_ IPortableDeviceKeyCollection* pKeys); - -HRESULT SetRenderingProfiles( - _In_ IPortableDeviceValues* pValues); - -HRESULT AddExtraSupportedProperties( - _In_ LPCWSTR pszObjectID, - _In_ IPortableDeviceKeyCollection* pKeys); - -HRESULT AddExtraPropertyValues( - _In_ LPCWSTR pszObjectID, - _In_ IPortableDeviceValues* pValues); - -DWORD GetResourceSize( - UINT uiResource); - -PBYTE GetResourceData( - UINT uiResource); - -HRESULT IsValidContentType( - _In_ REFGUID guidObjectContentType, - _In_ CAtlArray<GUID>& RestrictedTypes); - -HRESULT GetClientContext( - _In_ IPortableDeviceValues* pParams, - _In_ LPCWSTR pszContextKey, - _COM_Outptr_ IUnknown** ppContext); - -HRESULT GetClientEventCookie( - _In_ IPortableDeviceValues* pParams, - _Outptr_result_maybenull_ LPWSTR* ppszEventCookie); - -HRESULT PostWpdEvent( - _In_ IPortableDeviceValues* pCommandParams, - _In_ IPortableDeviceValues* pEventParams); - -HRESULT PostWpdEventWithProgress( - _In_ IPortableDeviceValues* pCommandParams, - _In_ IPortableDeviceValues* pEventParams, - _In_ REFGUID guidEvent, - const DWORD dwOperationState, - const DWORD dwOperationProgress); - -BOOL ExistsInCollection(_In_ REFGUID guid, _In_ IPortableDevicePropVariantCollection* pCollection); - -class PropVariantWrapper : public tagPROPVARIANT -{ -public: - PropVariantWrapper() - { - PropVariantInit(this); - } - - PropVariantWrapper(_In_ LPCWSTR pszSrc) - { - PropVariantInit(this); - - *this = pszSrc; - } - - virtual ~PropVariantWrapper() - { - Clear(); - } - - void Clear() - { - PropVariantClear(this); - } - - PropVariantWrapper& operator= (ULONG ulValue) - { - Clear(); - vt = VT_UI4; - ulVal = ulValue; - - return *this; - } - - PropVariantWrapper& operator= (_In_ LPCWSTR pszSrc) - { - Clear(); - - pwszVal = AtlAllocTaskWideString(pszSrc); - if(pwszVal != NULL) - { - vt = VT_LPWSTR; - } - return *this; - } - - PropVariantWrapper& operator= (_In_ IUnknown* punkSrc) - { - Clear(); - - // Need to AddRef as PropVariantClear will Release - if (punkSrc != NULL) - { - vt = VT_UNKNOWN; - punkVal = punkSrc; - punkVal->AddRef(); - } - return *this; - } - - void SetErrorValue(HRESULT hr) - { - Clear(); - vt = VT_ERROR; - scode = hr; - } - - void SetBoolValue(bool bValue) - { - Clear(); - vt = VT_BOOL; - if(bValue) - { - boolVal = VARIANT_TRUE; - } - else - { - boolVal = VARIANT_FALSE; - } - } -}; - -HRESULT CreateVCard(_In_ IPortableDeviceValues* pValues, _Out_ CAtlStringA& strVCard); - -HRESULT UpdateDeviceFriendlyName( - _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension, - _In_ LPCWSTR wszDeviceFriendlyName); - -HRESULT GetCommonResourceAttributes( - _COM_Outptr_ IPortableDeviceValues** ppAttributes); diff --git a/wpd/WpdWudfSampleDriver/resource.h b/wpd/WpdWudfSampleDriver/resource.h deleted file mode 100644 index e0594a3f..00000000 --- a/wpd/WpdWudfSampleDriver/resource.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once -#define IDR_WpdWudfSampleDriver 101 - -#define IDR_WPD_SAMPLEDRIVER_IMAGE 3000 -#define IDR_WPD_SAMPLEDRIVER_IMAGE_THUMBNAIL 3001 -#define IDR_WPD_SAMPLEDRIVER_MUSIC 3002 -#define IDR_WPD_SAMPLEDRIVER_DEVICE_ICON 3003 -#define IDR_WPD_SAMPLEDRIVER_AUDIO_ANNOTATION 3004 -#define IDR_WPD_SAMPLEDRIVER_VIDEO 3005 -#define IDR_WPD_SAMPLEDRIVER_CONTACT_PHOTO 3006 -#define IDR_WPD_SAMPLEDRIVER_INTERNAL_STORAGE_ICON 3007 -#define IDR_WPD_SAMPLEDRIVER_EXTERNAL_STORAGE_ICON 3008 -#define IDR_WPD_SAMPLEDRIVER_MEMO 3009 -#define IDR_WPD_SAMPLEDRIVER_MEMO_ICON 3010 -#define IDR_WPD_SAMPLEDRIVER_MEMO_FOLDER_ICON 3011 - diff --git a/wpd/WpdWudfSampleDriver/stdafx.h b/wpd/WpdWudfSampleDriver/stdafx.h deleted file mode 100644 index 7a57563e..00000000 --- a/wpd/WpdWudfSampleDriver/stdafx.h +++ /dev/null @@ -1,118 +0,0 @@ -// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, -// but are changed infrequently - -#pragma once - -#include "resource.h" -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#define STRSAFE_NO_DEPRECATE - -#include <stdio.h> -#include <tchar.h> - -#include <atlbase.h> -#include <atlcom.h> -#include <atlcoll.h> -#include <atlstr.h> - -#include <initguid.h> -#include <propkeydef.h> - -// -// Driver specific tracing #defines -// Declared here as some headers below use these macros -// -// TODO: Change these values to be appropriate for your driver. -// -#define MYDRIVER_TRACING_ID L"Microsoft\\WPD\\WudfSampleDriver" - -// -// TODO: Choose a different trace control GUID -// -#define WPP_CONTROL_GUIDS \ - WPP_DEFINE_CONTROL_GUID(WudfSampleDriverCtlGuid,(92f71133,1850,4757,899f,96f28bae2f0b), \ - WPP_DEFINE_BIT(TRACE_FLAG_ALL) \ - WPP_DEFINE_BIT(TRACE_FLAG_DEVICE) \ - WPP_DEFINE_BIT(TRACE_FLAG_DRIVER) \ - WPP_DEFINE_BIT(TRACE_FLAG_QUEUE) \ - ) - -#define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) \ - WPP_LEVEL_LOGGER(flags) - -#define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) \ - (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_ ## flags).Level >= lvl) - -// -// This comment block is scanned by the trace preprocessor to define our -// TraceEvents function. -// -// begin_wpp config -// FUNC Trace{FLAG=TRACE_FLAG_ALL}(LEVEL, MSG, ...); -// FUNC TraceEvents(LEVEL, FLAGS, MSG, ...); -// end_wpp - -// -// This comment block is scanned by the trace preprocessor to define our -// CHECK_HR function. -// -// -// begin_wpp config -// USEPREFIX (CHECK_HR,"%!STDPREFIX!"); -// FUNC CHECK_HR{FLAG=TRACE_FLAG_ALL}(hrCheck, MSG, ...); -// USESUFFIX (CHECK_HR, " hr= %!HRESULT!", hrCheck); -// end_wpp - -// -// PRE macro: The name of the macro includes the condition arguments FLAGS and EXP -// define in FUNC above -// -#define WPP_FLAG_hrCheck_PRE(FLAGS, hrCheck) {if(hrCheck != S_OK) { - -// -// POST macro -// The name of the macro includes the condition arguments FLAGS and EXP -// define in FUNC above -#define WPP_FLAG_hrCheck_POST(FLAGS, hrCheck) ; } } - -// -// The two macros below are for checking if the event should be logged and for -// choosing the logger handle to use when calling the ETW trace API -// -#define WPP_FLAG_hrCheck_ENABLED(FLAGS, hrCheck) WPP_FLAG_ENABLED(FLAGS) -#define WPP_FLAG_hrCheck_LOGGER(FLAGS, hrCheck) WPP_FLAG_LOGGER(FLAGS) - -#include "WpdWudfSampleDriver.h" -#include "PortableDeviceTypes.h" -#include "PortableDeviceClassExtension.h" -#include "PortableDevice.h" -#include "ContextMap.h" -#include "helpers.h" -#include "FakeContent.h" -#include "FakeImageContent.h" -#include "FakeMusicContent.h" -#include "FakeVideoContent.h" -#include "FakeContactContent.h" -#include "FakeMemoContent.h" -#include "FakeFolderContent.h" -#include "RenderingInformationFakeContent.h" -#include "NetworkConfigFakeContent.h" -#include "DeviceObjectFakeContent.h" -#include "StorageObjectFakeContent.h" -#include "FakeDevice.h" -#include "WpdObjectEnum.h" -#include "WpdObjectManagement.h" -#include "WpdObjectProperties.h" -#include "WpdObjectPropertiesBulk.h" -#include "WpdObjectResources.h" -#include "WpdCapabilities.h" -#include "WpdStorage.h" -#include "WpdNetworkConfig.h" -#include "WpdBaseDriver.h" - -extern HINSTANCE g_hInstance; - |
