本文整理汇总了C++中IPropertyStore类的典型用法代码示例。如果您正苦于以下问题:C++ IPropertyStore类的具体用法?C++ IPropertyStore怎么用?C++ IPropertyStore使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IPropertyStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DeviceNameGet
static HRESULT
DeviceNameGet(
IMMDeviceCollection *dc, UINT id, wchar_t *name, size_t nameBytes)
{
HRESULT hr = 0;
IMMDevice *device = nullptr;
LPWSTR deviceId = nullptr;
IPropertyStore *ps = nullptr;
PROPVARIANT pv;
assert(dc);
assert(name);
name[0] = 0;
assert(0 < nameBytes);
PropVariantInit(&pv);
HRR(dc->Item(id, &device));
HRR(device->GetId(&deviceId));
HRR(device->OpenPropertyStore(STGM_READ, &ps));
HRG(ps->GetValue(PKEY_Device_FriendlyName, &pv));
SafeRelease(&ps);
wcsncpy_s(name, nameBytes / sizeof name[0], pv.pwszVal, _TRUNCATE);
end:
PropVariantClear(&pv);
CoTaskMemFree(deviceId);
SafeRelease(&ps);
return hr;
}
示例2: GetBufferProgress
HRESULT CPlayer::GetBufferProgress( DWORD *pProgress )
{
IPropertyStore *pProp = NULL;
PROPVARIANT var;
// Get the property store from the media session.
HRESULT hr = MFGetService(
m_pSession,
MFNETSOURCE_STATISTICS_SERVICE,
IID_PPV_ARGS( &pProp )
);
if ( SUCCEEDED( hr ) )
{
PROPERTYKEY key;
key.fmtid = MFNETSOURCE_STATISTICS;
key.pid = MFNETSOURCE_BUFFERPROGRESS_ID;
hr = pProp->GetValue( key, &var );
}
if ( SUCCEEDED( hr ) )
{
*pProgress = var.lVal;
// cout << "buff prog " << *pProgress << endl;
}
PropVariantClear( &var );
SafeRelease( &pProp );
return hr;
}
示例3: CoCreateInstance
// (static) Creates a ShellLink that encapsulate a separator.
nsresult JumpListSeparator::GetSeparator(nsRefPtr<IShellLinkW>& aShellLink)
{
HRESULT hr;
IShellLinkW* psl;
// Create a IShellLink.
hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLinkW, (LPVOID*)&psl);
if (FAILED(hr))
return NS_ERROR_UNEXPECTED;
IPropertyStore* pPropStore = nullptr;
hr = psl->QueryInterface(IID_IPropertyStore, (LPVOID*)&pPropStore);
if (FAILED(hr))
return NS_ERROR_UNEXPECTED;
PROPVARIANT pv;
InitPropVariantFromBoolean(TRUE, &pv);
pPropStore->SetValue(PKEY_AppUserModel_IsDestListSeparator, pv);
pPropStore->Commit();
pPropStore->Release();
PropVariantClear(&pv);
aShellLink = dont_AddRef(psl);
return NS_OK;
}
示例4: CoCreateInstance
void JumpListsManager::addTask(ActionInfo *info)
{
if (!m_destList)
return;
WinApi::IShellLinkW *task;
HRESULT res = CoCreateInstance(WinApi::CLSID_ShellLink, 0, CLSCTX_INPROC_SERVER, WinApi::IID_IShellLinkW, (void**)&task);
if (FAILED(res))
return;
task->SetDescription(info->description);
task->SetPath(L"rundll32.exe");
task->SetArguments(makeArgs(info).c_str());
if (info->iconPath)
task->SetIconLocation(info->iconPath, 0);
IPropertyStore *title;
PROPVARIANT titlepv;
res = task->QueryInterface(IID_IPropertyStore, (void**)&title);
if (FAILED(res)) {
task->Release();
return;
}
InitPropVariantFromString(info->name, &titlepv);
title->SetValue(PKEY_Title, titlepv);
title->Commit();
WinApi::PropVariantClear(&titlepv);
res = m_destListContent->AddObject(task);
title->Release();
task->Release();
m_actionInfoMap.insert(std::make_pair(info->id, info));
}
示例5: _CreateSeparatorLink
HRESULT _CreateSeparatorLink(IShellLink **ppsl)
{
IPropertyStore *pps;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pps));
if (SUCCEEDED(hr))
{
PROPVARIANT propvar;
hr = InitPropVariantFromBoolean(TRUE, &propvar);
if (SUCCEEDED(hr))
{
hr = pps->SetValue(PKEY_AppUserModel_IsDestListSeparator, propvar);
if (SUCCEEDED(hr))
{
hr = pps->Commit();
if (SUCCEEDED(hr))
{
hr = pps->QueryInterface(IID_PPV_ARGS(ppsl));
}
}
PropVariantClear(&propvar);
}
pps->Release();
}
return hr;
}
示例6: GetPropertyValue
HRESULT GetPropertyValue(PCWSTR pszFilename, PCWSTR pszCanonicalName)
{
// Convert the Canonical name of the property to PROPERTYKEY
PROPERTYKEY key;
HRESULT hr = PSGetPropertyKeyFromName(pszCanonicalName, &key);
if (SUCCEEDED(hr))
{
IPropertyStore* pps = NULL;
// Call the helper to get the property store for the initialized item
hr = GetPropertyStore(pszFilename, GPS_DEFAULT, &pps);
if (SUCCEEDED(hr))
{
hr = PrintProperty(pps, key, pszCanonicalName);
pps->Release();
}
else
{
wprintf(L"Error %x: getting the propertystore for the item.\n", hr);
}
}
else
{
wprintf(L"Invalid property specified: %s\n", pszCanonicalName);
}
return hr;
}
示例7: GetDeviceName
//
// Retrieves the device friendly name for a particular device in a device collection.
//
// The returned string was allocated using malloc() so it should be freed using free();
//
String GetDeviceName(IMMDeviceCollection *DeviceCollection, UINT DeviceIndex)
{
IMMDevice *device;
LPWSTR deviceId;
HRESULT hr;
hr = DeviceCollection->Item(DeviceIndex, &device);
PersistentAssert(SUCCEEDED(hr), "DeviceCollection->Item failed");
hr = device->GetId(&deviceId);
PersistentAssert(SUCCEEDED(hr), "device->GetId failed");
IPropertyStore *propertyStore;
hr = device->OpenPropertyStore(STGM_READ, &propertyStore);
SafeRelease(&device);
PersistentAssert(SUCCEEDED(hr), "device->OpenPropertyStore failed");
PROPVARIANT friendlyName;
PropVariantInit(&friendlyName);
hr = propertyStore->GetValue(PKEY_Device_FriendlyName, &friendlyName);
SafeRelease(&propertyStore);
PersistentAssert(SUCCEEDED(hr), "propertyStore->GetValue failed");
String Result = String(UnicodeString(friendlyName.pwszVal)); // + String(" (") + String( UnicodeString(deviceId) ) + String(")")
PropVariantClear(&friendlyName);
CoTaskMemFree(deviceId);
return Result;
}
示例8: GetDeviceName
//
// Retrieves the device friendly name for a particular device in a device collection.
//
LPWSTR GetDeviceName(IMMDeviceCollection *DeviceCollection, UINT DeviceIndex)
{
IMMDevice *device;
LPWSTR deviceId;
HRESULT hr;
hr = DeviceCollection->Item(DeviceIndex, &device);
if (FAILED(hr))
{
printf("Unable to get device %d: %x\n", DeviceIndex, hr);
return NULL;
}
hr = device->GetId(&deviceId);
if (FAILED(hr))
{
printf("Unable to get device %d id: %x\n", DeviceIndex, hr);
return NULL;
}
IPropertyStore *propertyStore;
hr = device->OpenPropertyStore(STGM_READ, &propertyStore);
SafeRelease(&device);
if (FAILED(hr))
{
printf("Unable to open device %d property store: %x\n", DeviceIndex, hr);
return NULL;
}
PROPVARIANT friendlyName;
PropVariantInit(&friendlyName);
hr = propertyStore->GetValue(PKEY_Device_FriendlyName, &friendlyName);
SafeRelease(&propertyStore);
if (FAILED(hr))
{
printf("Unable to retrieve friendly name for device %d : %x\n", DeviceIndex, hr);
return NULL;
}
wchar_t deviceName[128];
hr = StringCbPrintf(deviceName, sizeof(deviceName), L"%s (%s)", friendlyName.vt != VT_LPWSTR ? L"Unknown" : friendlyName.pwszVal, deviceId);
if (FAILED(hr))
{
printf("Unable to format friendly name for device %d : %x\n", DeviceIndex, hr);
return NULL;
}
PropVariantClear(&friendlyName);
CoTaskMemFree(deviceId);
wchar_t *returnValue = _wcsdup(deviceName);
if (returnValue == NULL)
{
printf("Unable to allocate buffer for return\n");
return NULL;
}
return returnValue;
}
示例9: createVolumeController
// ----------------------------------------------------------------------------
//
AudioVolumeController* AudioVolumeController::createVolumeController( )
{
HRESULT hr;
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDevice *pDefaultDevice = NULL;
IAudioEndpointVolume *endpointVolume = NULL;
LPWSTR pstrDefaultId = NULL;
IPropertyStore *pProperties = NULL;
try {
hr = CoCreateInstance(
CLSID_MMDeviceEnumerator, NULL,
CLSCTX_ALL, IID_IMMDeviceEnumerator,
(void**)&pEnumerator);
AUDIO_VOLUME_ASSERT( hr, "Cannot create COM device enumerator instance" );
// Get the default audio endpoint (if we don't get one its not an error)
hr = pEnumerator->GetDefaultAudioEndpoint( eRender, eConsole, &pDefaultDevice );
AUDIO_VOLUME_ASSERT( hr, "Cannot get default audio render device" );
hr = pDefaultDevice->OpenPropertyStore( STGM_READ, &pProperties );
AUDIO_VOLUME_ASSERT( hr, "Cannot open IMMDevice property store" );
PROPVARIANT varName;
// Initialize container for property value.
PropVariantInit(&varName);
// Get the endpoint's friendly-name property.
hr = pProperties->GetValue( PKEY_Device_DeviceDesc , &varName);
AUDIO_VOLUME_ASSERT( hr, "Cannot open IMMDevice name property" );
CString render_name = CW2A( varName.pwszVal );
DMXStudio::log_status( "Default audio render device '%s'", render_name );
PropVariantClear(&varName);
hr = pDefaultDevice->Activate( IID_IAudioEndpointVolume, CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume );
AUDIO_VOLUME_ASSERT( hr, "Cannot activate default render device" );
SAFE_RELEASE( pDefaultDevice );
SAFE_RELEASE( pProperties );
SAFE_RELEASE( pEnumerator );
CoTaskMemFree( pstrDefaultId );
return new AudioVolumeController( endpointVolume, render_name );
}
catch ( ... ) {
CoTaskMemFree( pstrDefaultId );
SAFE_RELEASE( pDefaultDevice );
SAFE_RELEASE( pProperties );
SAFE_RELEASE( pEnumerator );
throw;
}
}
示例10: GetDefaultDevice
std::string CAESinkDirectSound::GetDefaultDevice()
{
IMMDeviceEnumerator* pEnumerator = NULL;
IMMDevice* pDevice = NULL;
IPropertyStore* pProperty = NULL;
HRESULT hr;
PROPVARIANT varName;
std::string strDevName = "default";
hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, IID_IMMDeviceEnumerator, (void**)&pEnumerator);
if (FAILED(hr))
{
CLog::Log(LOGERROR, __FUNCTION__": Could not allocate WASAPI device enumerator. CoCreateInstance error code: %s", WASAPIErrToStr(hr));
goto failed;
}
hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &pDevice);
if (FAILED(hr))
{
CLog::Log(LOGERROR, __FUNCTION__": Retrieval of audio endpoint enumeration failed.");
goto failed;
}
hr = pDevice->OpenPropertyStore(STGM_READ, &pProperty);
if (FAILED(hr))
{
CLog::Log(LOGERROR, __FUNCTION__": Retrieval of DirectSound endpoint properties failed.");
goto failed;
}
PropVariantInit(&varName);
hr = pProperty->GetValue(PKEY_AudioEndpoint_FormFactor, &varName);
if (FAILED(hr))
{
CLog::Log(LOGERROR, __FUNCTION__": Retrieval of DirectSound endpoint form factor failed.");
goto failed;
}
AEDeviceType aeDeviceType = winEndpoints[(EndpointFormFactor)varName.uiVal].aeDeviceType;
PropVariantClear(&varName);
hr = pProperty->GetValue(PKEY_AudioEndpoint_GUID, &varName);
if (FAILED(hr))
{
CLog::Log(LOGERROR, __FUNCTION__": Retrieval of DirectSound endpoint GUID failed.");
goto failed;
}
strDevName = localWideToUtf(varName.pwszVal);
PropVariantClear(&varName);
failed:
SAFE_RELEASE(pProperty);
SAFE_RELEASE(pDevice);
SAFE_RELEASE(pEnumerator);
return strDevName;
}
示例11: CoCreateInstance
HRESULT CTaskbar7::CreateShellLink(Destination destination, IShellLink **ppShellLink)
{
USES_CONVERSION;
IShellLink *pShellLink = NULL;
IPropertyStore *pPropertyStore = NULL;
PROPVARIANT propVariant;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pShellLink));
EXIT_ON_ERROR(hr);
// Path
hr = pShellLink->SetPath(CW2A(destination.path.c_str()));
EXIT_ON_ERROR(hr);
// Arguments
hr = pShellLink->SetArguments(CW2A(destination.arguments.c_str()));
EXIT_ON_ERROR(hr);
// Working Directory
if (!destination.workingFolder.empty())
{
hr = pShellLink->SetWorkingDirectory(CW2A(destination.workingFolder.c_str()));
EXIT_ON_ERROR(hr);
}
// Icon Location
if (!destination.icon.empty())
{
hr = pShellLink->SetIconLocation(CW2A(destination.icon.c_str()), destination.iconIndex);
EXIT_ON_ERROR(hr);
}
hr = pShellLink->QueryInterface(IID_PPV_ARGS(&pPropertyStore));
EXIT_ON_ERROR(hr);
// Name
hr = InitPropVariantFromString(destination.name.c_str(), &propVariant);
EXIT_ON_ERROR(hr);
hr = pPropertyStore->SetValue(PKEY_Title, propVariant);
EXIT_ON_ERROR(hr);
hr = pPropertyStore->Commit();
EXIT_ON_ERROR(hr);
hr = pShellLink->QueryInterface(IID_PPV_ARGS(ppShellLink));
Exit:
PropVariantClear(&propVariant);
SAFE_RELEASE(pPropertyStore);
SAFE_RELEASE(pShellLink);
return hr;
}
示例12: SetPropertyValue
HRESULT SetPropertyValue(PCWSTR pszFilename, PCWSTR pszCanonicalName, PCWSTR pszValue)
{
// Convert the Canonical name of the property to PROPERTYKEY
PROPERTYKEY key;
HRESULT hr = PSGetPropertyKeyFromName(pszCanonicalName, &key);
if (SUCCEEDED(hr))
{
IPropertyStore* pps = NULL;
// Call the helper to get the property store for the
// initialized item
hr = GetPropertyStore(pszFilename, GPS_READWRITE, &pps);
if (SUCCEEDED(hr))
{
PROPVARIANT propvarValue = {0};
hr = InitPropVariantFromString(pszValue, &propvarValue);
if (SUCCEEDED(hr))
{
hr = PSCoerceToCanonicalValue(key, &propvarValue);
if (SUCCEEDED(hr))
{
// Set the value to the property store of the item.
hr = pps->SetValue(key, propvarValue);
if (SUCCEEDED(hr))
{
// Commit does the actual writing back to the file stream.
hr = pps->Commit();
if (SUCCEEDED(hr))
{
wprintf(L"Property %s value %s written successfully \n", pszCanonicalName, pszValue);
}
else
{
wprintf(L"Error %x: Commit to the propertystore failed.\n", hr);
}
}
else
{
wprintf(L"Error %x: Set value to the propertystore failed.\n", hr);
}
}
PropVariantClear(&propvarValue);
}
pps->Release();
}
else
{
wprintf(L"Error %x: getting the propertystore for the item.\n", hr);
}
}
else
{
wprintf(L"Invalid property specified: %s\n", pszCanonicalName);
}
return hr;
}
示例13: GetModuleFileNameW
void Win32TaskbarManager::addRecent(const Common::String &name, const Common::String &description) {
//warning("[Win32TaskbarManager::addRecent] Adding recent list entry: %s (%s)", name.c_str(), description.c_str());
if (_taskbar == NULL)
return;
// ANSI version doesn't seem to work correctly with Win7 jump lists, so explicitly use Unicode interface.
IShellLinkW *link;
// Get the ScummVM executable path.
WCHAR path[MAX_PATH];
GetModuleFileNameW(NULL, path, MAX_PATH);
// Create a shell link.
if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC, IID_IShellLinkW, reinterpret_cast<void **> (&link)))) {
// Convert game name and description to Unicode.
LPWSTR game = ansiToUnicode(name.c_str());
LPWSTR desc = ansiToUnicode(description.c_str());
// Set link properties.
link->SetPath(path);
link->SetArguments(game);
Common::String iconPath = getIconPath(name);
if (iconPath.empty()) {
link->SetIconLocation(path, 0); // No game-specific icon available
} else {
LPWSTR icon = ansiToUnicode(iconPath.c_str());
link->SetIconLocation(icon, 0);
delete[] icon;
}
// The link's display name must be set via property store.
IPropertyStore* propStore;
HRESULT hr = link->QueryInterface(IID_IPropertyStore, reinterpret_cast<void **> (&(propStore)));
if (SUCCEEDED(hr)) {
PROPVARIANT pv;
pv.vt = VT_LPWSTR;
pv.pwszVal = desc;
hr = propStore->SetValue(PKEY_Title, pv);
propStore->Commit();
propStore->Release();
}
// SHAddToRecentDocs will cause the games to be added to the Recent list, allowing the user to pin them.
SHAddToRecentDocs(SHARD_LINK, link);
link->Release();
delete[] game;
delete[] desc;
}
}
示例14: _CreateShellLink
HRESULT _CreateShellLink(PCSTR pszArguments, PCWSTR pszTitle, LPCSTR szDescription, IShellLink **ppsl)
{
IShellLink *psl;
HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl));
if (SUCCEEDED(hr))
{
// Determine our executable's file path so the task will execute this application
CHAR szAppPath[MAX_PATH];
if (GetModuleFileName(NULL, szAppPath, ARRAYSIZE(szAppPath)))
{
hr = psl->SetPath(szAppPath);
if (SUCCEEDED(hr))
{
hr = psl->SetArguments(pszArguments);
if (SUCCEEDED(hr))
{
hr = psl->SetDescription( szDescription );
if (SUCCEEDED(hr))
{
// The title property is required on Jump List items provided as an IShellLink
// instance. This value is used as the display name in the Jump List.
IPropertyStore *pps;
hr = psl->QueryInterface(IID_PPV_ARGS(&pps));
if (SUCCEEDED(hr))
{
PROPVARIANT propvar;
hr = InitPropVariantFromString(pszTitle, &propvar);
if (SUCCEEDED(hr))
{
hr = pps->SetValue(PKEY_Title, propvar);
if (SUCCEEDED(hr))
{
hr = pps->Commit();
if (SUCCEEDED(hr))
{
hr = psl->QueryInterface(IID_PPV_ARGS(ppsl));
}
}
PropVariantClear(&propvar);
}
pps->Release();
}
}
}
}
}
else
{
hr = HRESULT_FROM_WIN32(GetLastError());
}
psl->Release();
}
return hr;
}
示例15: do_QueryInterface
// (static) ShellItems are used to encapsulate links to things. We currently only support URI links,
// but more support could be added, such as local file and directory links.
nsresult JumpListLink::GetShellItem(nsCOMPtr<nsIJumpListItem>& item, nsRefPtr<IShellItem2>& aShellItem)
{
IShellItem2 *psi = nullptr;
nsresult rv;
int16_t type;
if (NS_FAILED(item->GetType(&type)))
return NS_ERROR_INVALID_ARG;
if (type != nsIJumpListItem::JUMPLIST_ITEM_LINK)
return NS_ERROR_INVALID_ARG;
nsCOMPtr<nsIJumpListLink> link = do_QueryInterface(item, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIURI> uri;
rv = link->GetUri(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString spec;
rv = uri->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);
// Create the IShellItem
if (FAILED(WinUtils::SHCreateItemFromParsingName(
NS_ConvertASCIItoUTF16(spec).get(), NULL, IID_PPV_ARGS(&psi)))) {
return NS_ERROR_INVALID_ARG;
}
// Set the title
nsAutoString linkTitle;
link->GetUriTitle(linkTitle);
IPropertyStore* pPropStore = nullptr;
HRESULT hres = psi->GetPropertyStore(GPS_DEFAULT, IID_IPropertyStore, (void**)&pPropStore);
if (FAILED(hres))
return NS_ERROR_UNEXPECTED;
PROPVARIANT pv;
InitPropVariantFromString(linkTitle.get(), &pv);
// May fail due to shell item access permissions.
pPropStore->SetValue(PKEY_ItemName, pv);
pPropStore->Commit();
pPropStore->Release();
PropVariantClear(&pv);
aShellItem = dont_AddRef(psi);
return NS_OK;
}