/** * 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_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( IPortableDeviceValues* pParams, 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 (hr != S_OK) { 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 (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"); } //Free the context if (hr == S_OK) { 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; }