本文整理汇总了C++中CComPtr::Add方法的典型用法代码示例。如果您正苦于以下问题:C++ CComPtr::Add方法的具体用法?C++ CComPtr::Add怎么用?C++ CComPtr::Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CComPtr
的用法示例。
在下文中一共展示了CComPtr::Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OutputString
/**
*\fn HRESULT OutputString(const char *pszCaption, const char *pszText)
*\brief 向输出窗体输出文字
*\param[in] const char * pszCaption 标题
*\param[in] const char * pszText 内容
*\return HRESULT 0成功,其它失败
*/
HRESULT CAddinProcess::OutputString(const char *pszCaption, const char *pszText)
{
if (NULL == pszCaption || NULL == pszText) return E_INVALIDARG;
CComPtr<Window> pWindow;
HRESULT hr = m_pWindows->Item(CComVariant(EnvDTE::vsWindowKindOutput), &pWindow);
if (NULL == pWindow) return E_INVALIDARG;
CComPtr<IDispatch> pDisp;
CComQIPtr<OutputWindow> pOutputWindow;
hr = pWindow->get_Object(&pDisp);
pOutputWindow = pDisp;
if (NULL == pOutputWindow) return E_INVALIDARG;
CComPtr<OutputWindowPanes> pOutputWindowPanes;
hr = pOutputWindow->get_OutputWindowPanes(&pOutputWindowPanes);
if (NULL == pOutputWindowPanes) return E_INVALIDARG;
long nCount = 0;
hr = pOutputWindowPanes->get_Count(&nCount);
CComPtr<OutputWindowPane> pOutputWindowPane;
int i = 1;
for (; i <= nCount; i++)
{
VARIANT varIndex;
VariantInit(&varIndex);
varIndex.vt = VT_I4;
varIndex.lVal = i;
CComPtr<OutputWindowPane> pPane;
hr = pOutputWindowPanes->Item(varIndex, &pPane);
if (NULL == pPane) continue;
BSTR bstrName;
pPane->get_Name(&bstrName);
std::string name = BstrToStr(bstrName);
if (0 == strcmp(name.c_str(), pszCaption))
{
pOutputWindowPane = pPane;
break;
}
}
if (i > nCount)
{
hr = pOutputWindowPanes->Add(CComBSTR(pszCaption), &pOutputWindowPane);
}
hr = pOutputWindowPane->OutputString(CComBSTR(pszText));
return hr;
}
示例2: MultipleSelection
void TestPropSheetExt::MultipleSelection()
{
CComPtr<MSF::CFileList> rfilelist = MSF::CFileList::CreateInstance();
rfilelist->Add(MSF::GetModuleDirectory() + _T("sample1.vvv"));
rfilelist->Add(MSF::GetModuleDirectory() + _T("sample2.vvv"));
TestExecutePropSheetExt(rfilelist);
}
示例3: OnGetSupportedFormats
/**
* 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;
}
示例4: bstrResourceLoc
HRESULT
AsdkSheetSet::addResourceFileLocation(char* resourceFileLocation)
{
if(FAILED(isInitialized("addResourceFileLocation")))
return E_FAIL;
// lock the the database first before doing any operation on it
if (FAILED(LockDatabase()))
{
acutPrintf("\n Database lock failed!");
return E_FAIL;
}
CComPtr<IAcSmResources> pResources = NULL;
if (FAILED(m_pSheetSet->GetResources(&pResources)))
return E_FAIL;
CComBSTR bstrResourceLoc(resourceFileLocation);
CComPtr<IAcSmFileReference> pFileReference = NULL;
if (FAILED(pFileReference.CoCreateInstance(L"AcSmComponents.AcSmFileReference")))
{
return E_POINTER;
}
if (FAILED(pFileReference->InitNew(m_pDb)))
{
return E_FAIL;
}
if (FAILED(pFileReference->SetFileName(bstrResourceLoc)))
{
return E_FAIL;
}
// add the resource location.
if (FAILED(pResources->Add(pFileReference)))
return E_FAIL;
// Unlock database
if (FAILED(UnlockDatabase()))
{
acutPrintf("\n Cannot unlock database");
return E_FAIL;
}
return S_OK;
}
示例5: OnGetFunctionalCategories
/**
* 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;
}
示例6: AddSelfToWindowsFirewall
void ToolCollection::AddSelfToWindowsFirewall(const CAtlStringW name)
{
CComPtr<INetFwMgr> FwMgr;
CComPtr<INetFwPolicy> FwPolocy;
CComPtr<INetFwProfile> FwProfile;
if(FAILED(FwMgr.CoCreateInstance( __uuidof(NetFwMgr),nullptr,CLSCTX_INPROC_SERVER))) return;
if(FAILED(FwMgr->get_LocalPolicy(&FwPolocy))) return;
if(FAILED(FwPolocy->get_CurrentProfile(&FwProfile))) return;
VARIANT_BOOL res;
if(FAILED(FwProfile->get_FirewallEnabled(&res))) return;
if(res==VARIANT_FALSE) return;
if(FAILED(FwProfile->get_ExceptionsNotAllowed(&res))) return;
if(res==VARIANT_TRUE) return;
CComPtr<INetFwAuthorizedApplication> FwApp;
CComPtr<INetFwAuthorizedApplications> FwApps;
if(FAILED(FwProfile->get_AuthorizedApplications(&FwApps))) return;
CAtlStringW filename,fullfilename;
::GetModuleFileNameW(nullptr,filename.GetBuffer(MAX_PATH),MAX_PATH);
filename.ReleaseBuffer();
DWORD size=::GetFullPathName(filename,0,0,0);
size=GetFullPathName(filename,size,fullfilename.GetBuffer(size),nullptr);
fullfilename.ReleaseBuffer();
if(SUCCEEDED(FwApps->Item(CComBSTR(fullfilename),&FwApp)))
{
FwApp->put_Enabled(VARIANT_TRUE);
}
else
{
if(FAILED(FwApp.CoCreateInstance(__uuidof(NetFwAuthorizedApplication),
nullptr,CLSCTX_INPROC_SERVER))) return;
if(FAILED(FwApp->put_Name(CComBSTR(name)))) return;
if(FAILED(FwApp->put_ProcessImageFileName(CComBSTR(fullfilename)))) return;
if(FAILED(FwApp->put_Enabled(VARIANT_TRUE)) ) return;
FwApps->Add(FwApp);
}
}
示例7: selSet
HRESULT
AsdkSheetSet::addSheetSelectionSet(char* selSetName, // Name of selection set
char* selSetDesc, // Description
IAcSmSheetSelSet **pSelSet) // Output pointer to selection set
{
if(FAILED(isInitialized("addSheetSelectionSet")))
return E_FAIL;
// lock the the database first before doing any operation on it
if (FAILED(LockDatabase()))
{
acutPrintf("\n Database lock failed!");
return E_FAIL;
}
CComPtr<IAcSmSheetSelSets> pSelSetS = NULL;
if (FAILED(m_pSheetSet->GetSheetSelSets(&pSelSetS)) || (pSelSetS == NULL))
{
acutPrintf("\n addSheetSelectionSet failed! Cannot get selection sets!!");
return E_FAIL;
}
// add a selection set to the selection set collection of the sheet set
CComBSTR selSet(selSetName);
CComBSTR selDesc(selSetDesc);
if (FAILED (pSelSetS->Add(selSet, selDesc, pSelSet)))
{
acutPrintf("\n addSheetSelectionSet failed! Cannot add selection set %s!!", selSetName);
return E_FAIL;
}
// Unlock database
if (FAILED(UnlockDatabase()))
{
acutPrintf("\n Cannot unlock database");
return E_FAIL;
}
return S_OK;
}
示例8: OnGetSupportedCommands
/**
* 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;
}
示例9: get_OutputPane
STDMETHODIMP CTangramHelper::get_OutputPane(IDispatch** pVal)
{
CComBSTR bstrDTE(L"DTE");
CComPtr<IDispatch> pDisp;
if (theApp.m_pTangramCore)
{
theApp.m_pTangramCore->get_TangramExtender(bstrDTE,&pDisp);
if (pDisp)
{
//pDisp.p->Release();
CComQIPtr<DTE2> pDTE2(pDisp);
CComPtr<Window> pWnd;
pDTE2->get_MainWindow(&pWnd);
long h = 0;
if(pWnd)
pWnd->get_HWnd(&h);
CComPtr<ToolWindows> pToolWindows;
pDTE2->get_ToolWindows(&pToolWindows);
if (pToolWindows)
{
CComPtr<VxDTE::OutputWindow> pOutWnd;
pToolWindows->get_OutputWindow(&pOutWnd);
if (pOutWnd)
{
CComPtr<OutputWindowPane> pPane;
CComPtr<OutputWindowPanes> pPanes;
pOutWnd->get_OutputWindowPanes(&pPanes);
pPanes->Add(CComBSTR(L"Tangram"), &pPane);
pPane->OutputString(CComBSTR(L"Welcome to Tangram!\r\n"));
*pVal = pPane.p;
(*pVal)->AddRef();
m_pOutputWindowPane = pPane.Detach();
//m_pOutputWindowPane->AddRef();
}
}
}
}
return S_OK;
}
示例10: PostDataEvent
// Post a data updated event
HRESULT CSampleEvents::PostDataEvent(IPortableDeviceValues* pValues)
{
HRESULT hr = (NULL == m_spSensorCXT) ? E_UNEXPECTED : S_OK ;
if (SUCCEEDED(hr))
{
CComPtr<IPortableDeviceValuesCollection> spValuesCollection;
hr = spValuesCollection.CoCreateInstance(CLSID_PortableDeviceValuesCollection);
if (SUCCEEDED(hr))
{
hr = spValuesCollection->Add(pValues);
if (SUCCEEDED(hr))
{
hr = m_spSensorCXT->PostEvent(g_wszSensorID, spValuesCollection);
}
}
}
return hr;
}
示例11: Process
STDMETHODIMP CSWFBuilder::Process(
/*[in]*/ BSTR /*sFile*/,
/*[in]*/ ISXMLElement* pXML)
{
if ( ! pXML )
return E_POINTER;
CComPtr <ISXMLElements> pISXMLRootElements;
HRESULT hr = pXML->get_Elements( &pISXMLRootElements );
if ( FAILED(hr) ) return hr;
CComPtr <ISXMLElement> pXMLRootElement;
hr = pISXMLRootElements->Create( CComBSTR("videos"), &pXMLRootElement );
if ( FAILED(hr) ) return hr;
CComPtr <ISXMLAttributes> pISXMLRootAttributes;
hr = pXMLRootElement->get_Attributes( &pISXMLRootAttributes );
if ( FAILED(hr) ) return hr;
pISXMLRootAttributes->Add( CComBSTR("xmlns:xsi"),
CComBSTR("http://www.w3.org/2001/XMLSchema-instance") );
pISXMLRootAttributes->Add( CComBSTR("xsi:noNamespaceSchemaLocation"),
CComBSTR("http://schemas.getenvy.com/Video.xsd") );
CComPtr <ISXMLElements> pISXMLElements;
hr = pXMLRootElement->get_Elements( &pISXMLElements );
if ( FAILED(hr) ) return hr;
CComPtr <ISXMLElement> pXMLElement;
hr = pISXMLElements->Create( CComBSTR("video"), &pXMLElement );
if ( FAILED(hr) ) return hr;
CComPtr <ISXMLAttributes> pISXMLAttributes;
hr = pXMLElement->get_Attributes( &pISXMLAttributes );
if ( FAILED(hr) ) return hr;
pISXMLAttributes->Add( CComBSTR("type"), CComBSTR("Shockwave Flash") );
pISXMLAttributes->Add( CComBSTR("codec"), CComBSTR("SWF") );
CString tmp;
tmp.Format( L"%lu", cx );
pISXMLAttributes->Add( CComBSTR("width"), CComBSTR(tmp) );
tmp.Format( L"%lu", cy );
pISXMLAttributes->Add( CComBSTR("height"), CComBSTR(tmp) );
return hr;
}
示例12: OnSetValuesByObjectListNext
//.........这里部分代码省略.........
// 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;
}
示例13: bstrBlockName
HRESULT
AsdkSheetSet::addCalloutBlock(char* blockName,
char* drawingName)
{
if(FAILED(isInitialized("addCalloutBlock")))
return E_FAIL;
// lock the the database first before doing any operation on it
if (FAILED(LockDatabase()))
{
acutPrintf("\n Database lock failed!");
return E_FAIL;
}
CComPtr<IAcSmCalloutBlocks> pCalloutBlk = NULL;
if (FAILED(m_pSheetSet->GetCalloutBlocks(&pCalloutBlk)))
{
acutPrintf("\n addCalloutBlock failed! Cannot get callout blocks!!");
return E_FAIL;
}
CComBSTR bstrBlockName(blockName);
CComBSTR bstrFileName(drawingName);
CComPtr<IAcSmAcDbBlockRecordReference> pCalloutRef = NULL;
if (FAILED(pCalloutRef.CoCreateInstance(L"AcSmComponents.AcSmAcDbBlockRecordReference")))
{
acutPrintf("\n addCalloutBlock failed! Cannot get named object reference!!");
return E_POINTER;
}
if (FAILED(pCalloutRef->InitNew(m_pDb)))
return E_FAIL;
if (FAILED(pCalloutRef->SetFileName(bstrFileName)))
{
acutPrintf("\n addCalloutBlock failed! Cannot set file name %s!!", drawingName);
return E_FAIL;
}
if (FAILED(pCalloutRef->SetName(bstrBlockName)))
{
acutPrintf("\n addCalloutBlock failed! Cannot set block name %s!!", blockName);
return E_FAIL;
}
if(FAILED(pCalloutBlk->Add(pCalloutRef)))
{
acutPrintf("\n addCalloutBlock failed! Cannot add callout reference!!");
return E_FAIL;
}
// Unlock database
if (FAILED(UnlockDatabase()))
{
acutPrintf("\n Cannot unlock database");
return E_FAIL;
}
return S_OK;
}
示例14: GetObjectIdentifierFromPersistentUniqueIdentifier
// Retreives the object identifier for the persistent unique identifer
void GetObjectIdentifierFromPersistentUniqueIdentifier(
IPortableDevice* pDevice)
{
if (pDevice == NULL)
{
printf("! A NULL IPortableDevice interface pointer was received\n");
return;
}
HRESULT hr = S_OK;
WCHAR szSelection[81] = {0};
CComPtr<IPortableDeviceContent> pContent;
CComPtr<IPortableDevicePropVariantCollection> pPersistentUniqueIDs;
CComPtr<IPortableDevicePropVariantCollection> pObjectIDs;
//<SnippetContentProp7>
// Prompt user to enter an unique identifier to convert to an object idenifier.
printf("Enter the Persistant Unique Identifier of the object you wish to convert into an object identifier.\n>");
hr = StringCbGetsW(szSelection,sizeof(szSelection));
if (FAILED(hr))
{
printf("An invalid persistent object identifier was specified, aborting the query operation\n");
}
//</SnippetContentProp7>
// 1) Get an IPortableDeviceContent interface from the IPortableDevice interface to
// access the content-specific methods.
//<SnippetContentProp8>
if (SUCCEEDED(hr))
{
hr = pDevice->Content(&pContent);
if (FAILED(hr))
{
printf("! Failed to get IPortableDeviceContent from IPortableDevice, hr = 0x%lx\n",hr);
}
}
//</SnippetContentProp8>
// 2) CoCreate an IPortableDevicePropVariantCollection interface to hold the the Unique Identifiers
// to query for Object Identifiers.
//
// NOTE: This is a collection interface so more than 1 identifier can be requested at a time.
// This sample only requests a single unique identifier.
//<SnippetContentProp9>
hr = CoCreateInstance(CLSID_PortableDevicePropVariantCollection,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pPersistentUniqueIDs));
//</SnippetContentProp9>
//<SnippetContentProp10>
if (SUCCEEDED(hr))
{
if (pPersistentUniqueIDs != NULL)
{
PROPVARIANT pv = {0};
PropVariantInit(&pv);
// Initialize a PROPVARIANT structure with the object identifier string
// that the user selected above. Notice we are allocating memory for the
// PWSTR value. This memory will be freed when PropVariantClear() is
// called below.
pv.vt = VT_LPWSTR;
pv.pwszVal = AtlAllocTaskWideString(szSelection);
if (pv.pwszVal != NULL)
{
// Add the object identifier to the objects-to-delete list
// (We are only deleting 1 in this example)
hr = pPersistentUniqueIDs->Add(&pv);
if (SUCCEEDED(hr))
{
// 3) Attempt to get the unique idenifier for the object from the device
hr = pContent->GetObjectIDsFromPersistentUniqueIDs(pPersistentUniqueIDs,
&pObjectIDs);
if (SUCCEEDED(hr))
{
PROPVARIANT pvId = {0};
hr = pObjectIDs->GetAt(0, &pvId);
if (SUCCEEDED(hr))
{
printf("The persistent unique identifier '%ws' relates to object identifier '%ws' on the device.\n", szSelection, pvId.pwszVal);
}
else
{
printf("! Failed to get the object identifier for '%ws' from the IPortableDevicePropVariantCollection, hr = 0x%lx\n",szSelection, hr);
}
// Free the returned allocated string from the GetAt() call
PropVariantClear(&pvId);
}
else
{
printf("! Failed to get the object identifier from persistent object idenifier '%ws', hr = 0x%lx\n",szSelection, hr);
}
}
else
{
printf("! Failed to get the object identifier from persistent object idenifier because we could no add the persistent object identifier string to the IPortableDevicePropVariantCollection, hr = 0x%lx\n",hr);
}
}
else
{
//.........这里部分代码省略.........
示例15: OnGetValuesByObjectFormatNext
//.........这里部分代码省略.........
}
// 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;
}