in wpd/WpdWudfSampleDriver/FakeDevice.h [44:643]
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;
}