本文整理汇总了C++中CComPtr::Advise方法的典型用法代码示例。如果您正苦于以下问题:C++ CComPtr::Advise方法的具体用法?C++ CComPtr::Advise怎么用?C++ CComPtr::Advise使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CComPtr
的用法示例。
在下文中一共展示了CComPtr::Advise方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RegisterEventHandler
HRESULT CWebBrowserUI::RegisterEventHandler( BOOL inAdvise )
{
CComPtr<IWebBrowser2> pWebBrowser;
CComPtr<IConnectionPointContainer> pCPC;
CComPtr<IConnectionPoint> pCP;
HRESULT hr = GetControl(IID_IWebBrowser2, (void**)&pWebBrowser);
if (FAILED(hr))
return hr;
hr=pWebBrowser->QueryInterface(IID_IConnectionPointContainer,(void **)&pCPC);
if (FAILED(hr))
return hr;
hr=pCPC->FindConnectionPoint(DIID_DWebBrowserEvents2,&pCP);
if (FAILED(hr))
return hr;
if (inAdvise)
{
hr = pCP->Advise((IDispatch*)this, &m_dwCookie);
}
else
{
hr = pCP->Unadvise(m_dwCookie);
}
return hr;
}
示例2: initialize
HRESULT CPolyCommand::initialize()
{
HRESULT hr = S_OK;
try {
// Get an instance of a wrapper for a non-db-resident polygon
if (FAILED(hr = m_pPoly.CoCreateInstance(CLSID_ComPolygon))) {
// most likely problem, be a little more descriptive here
acutPrintf("\nUnable to load ComPolygon");
throw hr;
}
// Get the base object - needed for those methods inherited by polygon
m_pBaseObj = m_pPoly;
m_pBaseObj->CreateObject();
// Get an instance of a listner so we know when input has been
// entered in OPM
if (FAILED(hr = CComObject<CComPolyCmd>::CreateInstance(&m_pPolyCmd)))
throw hr;
m_pPolyCmd->SetDocument(curDoc());
hr = m_pPolyCmd->QueryInterface(IID_IUnknown,(LPVOID *)&m_pUnkCmd);
if (FAILED(hr))
throw hr;
// Attach the listener to the polygon wrapper
CComQIPtr<IConnectionPointContainer> pPtContainer;
pPtContainer = m_pPoly;
hr = pPtContainer->FindConnectionPoint(
IID_IPropertyNotifySink,&m_pConPt);
if (FAILED(hr))
throw hr;
if (FAILED(hr = m_pConPt->Advise(m_pUnkCmd,&m_dConnectionID)))
throw hr;
acedSetIUnknownForCurrentCommand(m_pPoly);
m_pDb = curDoc()->database();
setDefaults();
} catch (HRESULT) {
fail();
}
return hr;
}
示例3: advise
bool IEDebugger::advise(IDebugApplicationNode* node, bool isRoot, bool recurse) {
CComPtr<IConnectionPointContainer> connectionPointContainer = NULL;
HRESULT hr = node->QueryInterface(IID_IConnectionPointContainer, (void**)&connectionPointContainer);
if (FAILED(hr)) {
Logger::error("IEDebugger.advise(): QI(IID_IConnectionPointContainer) failed", hr);
return false;
}
CComPtr<IConnectionPoint> nodeConnectionPoint = NULL;
hr = connectionPointContainer->FindConnectionPoint(IID_IDebugApplicationNodeEvents, &nodeConnectionPoint);
if (FAILED(hr)) {
Logger::error("IEDebugger.advise(): FindConnectionPoint() failed", hr);
return false;
}
DWORD connectionPointCookie = 0;
hr = nodeConnectionPoint->Advise(static_cast<IIEDebugger*>(this), &connectionPointCookie);
if (FAILED(hr)) {
Logger::error("IEDebugger.advise(): Advise() failed", hr);
return false;
}
if (isRoot) {
m_rootCookie = connectionPointCookie;
m_rootNode = node;
} else {
m_adviseCookies->insert(std::pair<IDebugApplicationNode*,DWORD>(node, connectionPointCookie));
}
node->AddRef();
if (recurse) {
CComPtr<IEnumDebugApplicationNodes> nodes = NULL;
hr = node->EnumChildren(&nodes);
if (FAILED(hr)) {
Logger::error("IEDebugger.advise(): EnumChildren() failed", hr);
} else {
IDebugApplicationNode* current = NULL;
ULONG count = 0;
hr = nodes->Next(1, ¤t, &count);
while (SUCCEEDED(hr) && count) {
advise(current, false, true);
current->Release();
hr = nodes->Next(1, ¤t, &count);
}
}
}
return true;
}
示例4: Connect
HRESULT CBhoApp::Connect()
{
HRESULT hr;
CComPtr<IConnectionPoint> spCP;
// Receives the connection point for WebBrowser events
hr = m_spCPC->FindConnectionPoint(DIID_DWebBrowserEvents2, &spCP);
if (FAILED(hr))
return hr;
// Pass our event handlers to the container. Each time an event occurs
// the container will invoke the functions of the IDispatch interface
// we implemented.
hr = spCP->Advise(reinterpret_cast<IDispatch*>(this),&m_dwCookie);
return hr;
}
示例5: RegisterEventHandler
HRESULT Cdlext::RegisterEventHandler(BOOL inAdvise)
{
CComPtr<IConnectionPoint> spCP;
// Receives the connection point for WebBrowser events
CComQIPtr<IConnectionPointContainer,&IID_IConnectionPointContainer> spCPC(mWebBrowser2);
HRESULT hr = spCPC->FindConnectionPoint(DIID_DWebBrowserEvents2, &spCP);
if (FAILED(hr))
return hr;
if(inAdvise)
{
//hr=spCP->Advise(reinterpret_cast(this),&mCookie);
hr = spCP->Advise((IDispatch*)this, &mCookie);
}
else
{
spCP->Unadvise(mCookie);
}
return hr;
}
示例6: Exception
void IISxpressAPI::ResponseHistory::AttachConnectionPoint()
{
m_dwCookie = 0;
m_pHTTPNotifyCP = nullptr;
if (m_pNotifyObj == nullptr)
{
// TODO: a better error message here
throw gcnew System::Exception();
}
CComPtr<IIISxpressHTTPRequest> pHTTPRequest;
HRESULT hr = GetHTTPRequest(&pHTTPRequest);
if (hr != S_OK)
{
throw gcnew IISxpressAPI::IISxpressAPIException(hr);
}
CComQIPtr<IConnectionPointContainer> pConnPointCont = pHTTPRequest;
if (pConnPointCont != NULL)
{
if (pConnPointCont != NULL)
{
CComPtr<IConnectionPoint> pHTTPNotifyCP;
HRESULT hr = pConnPointCont->FindConnectionPoint(IID_IIISxpressHTTPNotify, &pHTTPNotifyCP);
if (pHTTPNotifyCP != NULL)
{
CComPtr<IUnknown> pUnk;
m_pNotifyObj->QueryInterface(IID_IUnknown, (void**) &pUnk);
DWORD dwCookie = 0;
hr = pHTTPNotifyCP->Advise(pUnk, &dwCookie);
m_pHTTPNotifyCP = pHTTPNotifyCP.Detach();
m_dwCookie = dwCookie;
}
}
}
}
示例7: advise
///////////////////////////////////////////////////////////////////////////
// Connect/Disconnect to the DWebBrowserEvents2 Source
///////////////////////////////////////////////////////////////////////////
bool CHtmlWindowEventSink::advise(IHTMLWindow2 *pHtmlWindow) {
HRESULT hr;
if (!pHtmlWindow)
return false;
m_spHtmlWindow=pHtmlWindow;
CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> spCPContainer=m_spHtmlWindow;
if (spCPContainer != NULL) {
CComPtr<IConnectionPoint> spConnectionPoint;
hr = spCPContainer->FindConnectionPoint(DIID_HTMLWindowEvents2, &spConnectionPoint);
if (SUCCEEDED(hr) && !m_dwCookie) {
hr = spConnectionPoint->Advise((IDispatch*)this, &m_dwCookie);
if (FAILED(hr))
ATLTRACE("CWebBrowserEventSink: advise(): Failed\n\n");
}
return SUCCEEDED(hr);
}
return false;
}
示例8: Show
CBrowseFolder::retVal CBrowseFolder::Show(HWND parent, CString& path, const CString& sDefaultPath /* = CString() */)
{
m_sDefaultPath = sDefaultPath;
if (m_sDefaultPath.IsEmpty() && !path.IsEmpty())
{
while (!PathFileExists(path) && !path.IsEmpty())
{
CString p = path.Left(path.ReverseFind(L'\\'));
if ((p.GetLength() == 2) && (p[1] == L':'))
{
p += L"\\";
if (p.Compare(path) == 0)
p.Empty();
}
if (p.GetLength() < 2)
p.Empty();
path = p;
}
// if the result path already contains a path, use that as the default path
m_sDefaultPath = path;
}
// Create a new common open file dialog
CComPtr<IFileOpenDialog> pfd;
if (FAILED(pfd.CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_INPROC_SERVER)))
return CANCEL;
// Set the dialog as a folder picker
DWORD dwOptions;
if (FAILED(pfd->GetOptions(&dwOptions)))
return CANCEL;
if (FAILED(pfd->SetOptions(dwOptions | FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST)))
return CANCEL;
// Set a title
TCHAR* nl = _tcschr(m_title, '\n');
if (nl)
*nl = 0;
pfd->SetTitle(m_title);
// set the default folder
CComPtr<IShellItem> psiDefault;
if (FAILED(SHCreateItemFromParsingName(m_sDefaultPath, nullptr, IID_PPV_ARGS(&psiDefault))))
return CANCEL;
if (FAILED(pfd->SetFolder(psiDefault)))
return CANCEL;
CComObjectStackEx<BrowseFolderDlgEventHandler> cbk;
cbk.m_DisableCheckbox2WhenCheckbox1IsChecked = m_DisableCheckbox2WhenCheckbox1IsChecked;
CComQIPtr<IFileDialogEvents> pEvents = cbk.GetUnknown();
if (!m_CheckText.IsEmpty())
{
CComPtr<IFileDialogCustomize> pfdCustomize;
if (FAILED(pfd.QueryInterface(&pfdCustomize)))
return CANCEL;
pfdCustomize->StartVisualGroup(100, L"");
pfdCustomize->AddCheckButton(101, m_CheckText, FALSE);
if (!m_CheckText2.IsEmpty())
pfdCustomize->AddCheckButton(102, m_CheckText2, FALSE);
pfdCustomize->EndVisualGroup();
}
DWORD eventsCookie;
if (FAILED(pfd->Advise(pEvents, &eventsCookie)))
return CANCEL;
SCOPE_EXIT { pfd->Unadvise(eventsCookie); };
// Show the open file dialog
if (FAILED(pfd->Show(parent)))
return CANCEL;
// Get the selection from the user
CComPtr<IShellItem> psiResult;
if (FAILED(pfd->GetResult(&psiResult)))
return CANCEL;
PWSTR pszPath = nullptr;
if (SUCCEEDED(psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszPath)))
{
path = pszPath;
CoTaskMemFree(pszPath);
}
CComPtr<IFileDialogCustomize> pfdCustomize;
if (SUCCEEDED(pfd.QueryInterface(&pfdCustomize)))
{
pfdCustomize->GetCheckButtonState(101, &m_bCheck);
pfdCustomize->GetCheckButtonState(102, &m_bCheck2);
}
return OK;
}
示例9: InitInstance
//.........这里部分代码省略.........
if (fbrowser.Show(NULL, pFrame->m_Data.m_sPatchPath)==CBrowseFolder::CANCEL)
return FALSE;
}
}
if ((parser.HasKey(_T("patchpath")))&&(!parser.HasVal(_T("diff"))))
{
// A path was given for applying a patchfile, but
// the patchfile itself was not.
// So ask the user for that patchfile
HRESULT hr;
// Create a new common save file dialog
CComPtr<IFileOpenDialog> pfd = NULL;
hr = pfd.CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER);
if (SUCCEEDED(hr))
{
// Set the dialog options
DWORD dwOptions;
if (SUCCEEDED(hr = pfd->GetOptions(&dwOptions)))
{
hr = pfd->SetOptions(dwOptions | FOS_FILEMUSTEXIST | FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST);
}
// Set a title
if (SUCCEEDED(hr))
{
CString temp;
temp.LoadString(IDS_OPENDIFFFILETITLE);
pfd->SetTitle(temp);
}
CSelectFileFilter fileFilter(IDS_PATCHFILEFILTER);
hr = pfd->SetFileTypes(fileFilter.GetCount(), fileFilter);
bool bAdvised = false;
DWORD dwCookie = 0;
CComObjectStackEx<PatchOpenDlgEventHandler> cbk;
CComQIPtr<IFileDialogEvents> pEvents = cbk.GetUnknown();
{
CComPtr<IFileDialogCustomize> pfdCustomize;
hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdCustomize));
if (SUCCEEDED(hr))
{
// check if there's a unified diff on the clipboard and
// add a button to the fileopen dialog if there is.
UINT cFormat = RegisterClipboardFormat(_T("TSVN_UNIFIEDDIFF"));
if ((cFormat)&&(OpenClipboard(NULL)))
{
HGLOBAL hglb = GetClipboardData(cFormat);
if (hglb)
{
pfdCustomize->AddPushButton(101, CString(MAKEINTRESOURCE(IDS_PATCH_COPYFROMCLIPBOARD)));
hr = pfd->Advise(pEvents, &dwCookie);
bAdvised = SUCCEEDED(hr);
}
CloseClipboard();
}
}
}
// Show the save file dialog
if (SUCCEEDED(hr) && SUCCEEDED(hr = pfd->Show(pFrame->m_hWnd)))
{
// Get the selection from the user
CComPtr<IShellItem> psiResult = NULL;
hr = pfd->GetResult(&psiResult);