구성요소 서비스의 내 컴퓨터 기본 DCOM 통신 속성 변경하기

참고 :
http://msdn2.microsoft.com/en-us/library/ms687763(VS.85).aspx
http://msdn2.microsoft.com/en-us/library/ms682790(VS.85).aspx

기본 속성 읽어오기

try
{
ICOMAdminCatalogPtr spCatalog(_T("COMAdmin.COMAdminCatalog"));
spCatalog->Connect(_T("localhost"));

ICatalogCollectionPtr spCatalogCollection =
(ICatalogCollectionPtr)spCatalog->GetCollection(_T("LocalComputer"));
spCatalogCollection->Populate();

long nCount = 0;
nCount = spCatalogCollection->Count;
if (nCount == 0)
{
AfxMessageBox(_T("내 컴퓨터의 DCOM 통신 속성을 읽어오지 못하였습니다."));
return;
}

ASSERT(nCount == 1);

ICatalogObjectPtr spCatalogObject;
spCatalogCollection->get_Item(0, (IDispatch**)&spCatalogObject);

_variant_t value;
spCatalogObject->get_Value(_T("DefaultAuthenticationLevel"), &value);
if (value.vt == VT_I4)
{
if (value.lVal >= 0 && value.lVal <= 6) { CComboBox* pAuthCombo = (CComboBox*)GetDlgItem(IDC_CBO_AUTH); pAuthCombo->SetCurSel(value.lVal);
}
}

spCatalogObject->get_Value(_T("DefaultImpersonationLevel"), &value);
if (value.vt == VT_I4)
{
if (value.lVal >= 1 && value.lVal <= 4) { CComboBox* pImpersonationCombo = (CComboBox*)GetDlgItem(IDC_CBO_IMPERSONATION); pImpersonationCombo->SetCurSel(value.lVal);
}
}
} catch (_com_error& e) {
AfxMessageBox(e.Description());
}

IWebBrowser2와 IHTMLDocument2의 상호변환

1. IWebBrowser2 에서 IHTMLDocument2 인터페이스 구하기

IWebBrowser2 *m_pWebFromUnknown;
IWebBrowser2 *m_pWebFromDoc;

STDMETHODIMP CTestObj::SetSite( IUnknown *pUnkSite )
{
    IOleClientSite *pClientSite;
    HRESULT hr;

    hr = pUnkSite-> QueryInterface( IID_IOleClientSite, 
    (LPVOID *)&pClientSite );
    if ( FAILED( hr ) ) return S_OK;

    IOleContainer *pContainer;
    hr = pClientSite-> GetContainer( &pContainer );
    pClientSite-> Release();
    if ( FAILED( hr ) ) return S_OK;
    
    IServiceProvider *pServiceProvider;
    hr = pContainer-> QueryInterface( IID_IServiceProvider, 
    (LPVOID *)&pServiceProvider );
    pContainer-> Release();
    if ( FAILED( hr ) ) return S_OK;

    hr = pServiceProvider-> QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, (LPVOID *)
                                         &m_pWebFromUnknown );
    pServiceProvider-> Release();
    if ( FAILED( hr ) ) return S_OK;

    LPDISPATCH pDocDisp;
    hr = m_pWebFromUnknown-> get_Document( &pDocDisp