Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The mapping function, WpdBaseDriver::OnGetObjectIDsFromPersistentUniqueIDs, handles the mapping of object identifiers to persistent identifiers. In the WPD driver model, an object identifier is an identifier that is only valid for a given device session. A persistent identifier is valid across all device sessions.
The following excerpt from the sample driver contains the code for WpdBaseDriver::OnGetObjectIDsFromPersistentUniqueIDs.
HRESULT WpdBaseDriver::OnGetObjectIDsFromPersistentUniqueIDs(
IPortableDeviceValues* pParams,
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);
// Because our persistent unique identifiers 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;
}
Some devices might store the persistent identifiers in an object, some might generate a persistent identifier based on a hash of object data, and others might treat their object identifiers as persistent identifiers (because they will never change). The WpdHelloWorldDriver sample implements this latter case.
When a client application calls the IPortableDeviceContent::GetObjectIDsFromPersistentUniqueIDs method, the driver, in turn, calls WpdBaseDriver::OnGetObjectIDsFromPersistentUniqueIDs.