HRESULT WebBrowserEventSinker::SetCustomDocUIHandler(LPDISPATCH lpDisp)
{
	if(lpDisp == NULL)
		return E_INVALIDARG;

	IWebBrowser2Ptr pWebBrowser2;
	HRESULT hr = lpDisp->QueryInterface(IID_IWebBrowser2, (void**)&pWebBrowser2);

	if(SUCCEEDED(hr) && pWebBrowser2)
	{
		IDispatchPtr pDoc;
		hr = pWebBrowser2->get_Document(&pDoc);

		if(SUCCEEDED(hr) && pDoc)
		{
			ICustomDocPtr pCustDoc;
			hr = pDoc->QueryInterface(IID_ICustomDoc, (void**)&pCustDoc);
			if(SUCCEEDED(hr) && pCustDoc != NULL)
			{				
				IDocHostUIHandler* pUIHandler;
				CreateObjectInterface<CDocHostUIHandler, IDocHostUIHandler>(NULL, &pUIHandler);

				if (pUIHandler)
					pCustDoc->SetUIHandler(pUIHandler);

				pUIHandler->Release();
			}
		}
	}

	return hr;
}
Esempio n. 2
0
void CHTMLViewCapView::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
	UNUSED_ALWAYS(pDisp);
	UNUSED_ALWAYS(URL);

	HRESULT hr;
	IUnknown* pUnkBrowser = NULL;
    IUnknown* pUnkDisp = NULL;

	// 这个 DocumentComplete 事件是否是顶层框架窗口的?
    // 检查 COM 标识: 比较IUnknown 接口指针.
	hr = m_pBrowserApp->QueryInterface(IID_IUnknown, (void**)&pUnkBrowser);

	if ( SUCCEEDED(hr) ) {
		hr = pDisp->QueryInterface(IID_IUnknown,  (void**)&pUnkDisp);

		if ( SUCCEEDED(hr) ) {
			if ( pUnkBrowser == pUnkDisp ) {
				TRACE("Top Document completely loaded!\n");
				EndModalLoop(S_OK);
				//::SetEvent(m_hDocCompleteEvent);
			}
		}

		pUnkDisp->Release();
	}
	pUnkBrowser->Release();
}
void CThingTreeCtrl::SelectThing(LPDISPATCH Thing) 
{
	IThing *pCurrentThing = NULL;
	HRESULT hr = S_OK;
	long lCurrentID;
	HTREEITEM htItem = NULL;

	if (FAILED(hr = Thing->QueryInterface(IID_IThing, (void**)&pCurrentThing)))
		goto exit;

	if(pCurrentThing)
	{
		if (FAILED(hr = pCurrentThing->get_ID(&lCurrentID)))
			goto exit;

		// Search for the htreeitem that corresponds these ids
		htItem = InTree(m_hRoom, lCurrentID);

		// if we found the item, select it and exit
		if(htItem)
		{
			// TODO - Make sure this doesn send a TVN_SELCHANGED notification!!!!
			// It does, so we have to regulate it with a bool
			m_bSelectedByMe = FALSE;
			m_treeCtrl.SelectItem(htItem);
		}
	}

exit:

	SAFERELEASE(pCurrentThing);
}
Esempio n. 4
0
//OLECMDID_PRINT	= 6,
HRESULT CWtlHtmlView::ExecCommand( OLECMDID nCmdID, OLECMDEXECOPT nCmdExecOpt, VARIANTARG* pvarargIn, VARIANTARG* pvarargOut) 
{
	HRESULT hr=S_OK;
	LPDISPATCH lpDispatch = NULL;
	LPOLECOMMANDTARGET lpOleCommandTarget = NULL;
	try {

		m_spWebBrowser2->get_Document(&lpDispatch);
		if(lpDispatch==NULL)
			throw;
		OLECMDF eQuery ; //      'return value type for QueryStatusWB

		if(FAILED( m_spWebBrowser2->QueryStatusWB(OLECMDID_PRINT, &eQuery))) //  'get print command status
			throw;

		if(!( eQuery & OLECMDF_ENABLED) )
			throw;

		lpDispatch->QueryInterface(IID_IOleCommandTarget, (void**)&lpOleCommandTarget);
		if(lpOleCommandTarget==NULL)
			throw;

		// Print contents of WebBrowser control.
		hr=lpOleCommandTarget->Exec(NULL, nCmdID, nCmdExecOpt, pvarargIn, pvarargOut);
	}
	catch(...)
	{
		hr=E_FAIL;
	}
	if(lpDispatch)
		lpDispatch->Release();
	if(lpOleCommandTarget)
		lpOleCommandTarget->Release();
	return hr;
}
Esempio n. 5
0
VARIANT CWebDlg::ExecuteScript(CString csCode, CString csLanguage)
{
	COleVariant   varRet;

	IHTMLDocument2* pHTMLDocument2;
	IHTMLWindow2*   pHTMLWindow2;
	LPDISPATCH lpDispatch;
	lpDispatch = m_explore.GetDocument();
   
	BSTR            bstrCode    = _bstr_t((const char *)csCode);
	BSTR            bstrLang    = _bstr_t((const char *)csLanguage);
	HRESULT         hr;
 
	if(lpDispatch)
	{
		hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&pHTMLDocument2);
		if(hr == S_OK)
		{
			hr = pHTMLDocument2->get_parentWindow(&pHTMLWindow2);
			if(hr == S_OK)
			{
				pHTMLWindow2->execScript(bstrCode, bstrLang, &varRet);
				pHTMLWindow2->Release();
			}
			pHTMLDocument2->Release();
		}
		lpDispatch->Release();
	}
	return varRet;
}
void
addCircleThroughCom()
{
    AutoCAD::IAcadApplication *pAcad;
    AutoCAD::IAcadDocument *pDoc;
    AutoCAD::IAcadModelSpace *pMSpace;

    HRESULT hr = NOERROR;
    LPUNKNOWN pUnk = NULL;
    LPDISPATCH pAcadDisp = acedGetIDispatch(TRUE); 
	if(pAcadDisp==NULL)
		return;
	
	hr = pAcadDisp->QueryInterface(AutoCAD::IID_IAcadApplication,(void**)&pAcad);
	pAcadDisp->Release();
	if (FAILED(hr))
		return;

	hr = pAcad->get_ActiveDocument(&pDoc);
	pAcad->Release();
	if (FAILED(hr))
		return;

	hr = pDoc->get_ModelSpace(&pMSpace);
	pDoc->Release();
	if (FAILED(hr))
		return;


    SAFEARRAYBOUND rgsaBound;
    rgsaBound.lLbound = 0L;
    rgsaBound.cElements = 3;
    long i;
    SAFEARRAY* pStartPoint = NULL;
    pStartPoint = SafeArrayCreate(VT_R8, 1, &rgsaBound);

    i = 0;
    double value = 4.0;
    SafeArrayPutElement(pStartPoint, &i, &value);
    
    i = 1;
    value = 2.0;
    SafeArrayPutElement(pStartPoint, &i, &value);
    
    i = 2;
    value = 0.0;
    SafeArrayPutElement(pStartPoint, &i, &value);
    
    VARIANT pt1;
    pt1.vt = VT_ARRAY | VT_R8;
    pt1.parray = pStartPoint;

    AutoCAD::IAcadCircle *pCircle;
    pMSpace->AddCircle(pt1, 2.0, &pCircle);
	VariantClear(&pt1);
    pMSpace->Release();
}
Esempio n. 7
0
bool getAcadMenuGroup(IAcadMenuGroup  **pVal)
{

    IAcadApplication *acadApp = NULL;
    LPDISPATCH  pDisp = NULL;

    if (!getApplication(&pDisp))
        return false;

    HRESULT hr = S_OK;
    hr = pDisp->QueryInterface(IID_IAcadApplication, (LPVOID*)&acadApp);
    if (FAILED(hr))
        return false;


    LPDISPATCH  pTempDisp = NULL;
    IAcadMenuGroups *mnuGrps = NULL;
    long cnt = 0;

    //get the menu groups
    hr = acadApp->get_MenuGroups(&mnuGrps);
    if (FAILED(hr))
    {
        acadApp->Release();
        return false;
    }
    mnuGrps->get_Count(&cnt);


    //get AutoCAD menu group. say it is index 0.
    IAcadMenuGroup *mnuGrp = NULL;

    VARIANT  vtName;
    vtName.vt = VT_I4;
    BSTR  grpName;
    bool found = false ;
    for (long i=0; i < cnt; i++)
    {
        vtName.lVal = i;
        hr = mnuGrps->Item(vtName, &mnuGrp);
        if (FAILED(hr))
            return false;


        hr  = mnuGrp->get_Name(&grpName);
        CString cgrpName(grpName);
        if (cgrpName.CompareNoCase("Acad")==0)
        {
            found = true;
            *pVal = mnuGrp;
            break;
        }
    }

    acadApp->Release();
    return found;
}
Esempio n. 8
0
bool ArxToolBar::GetAcadApplication( IAcadApplication*& pAcadApp )
{
    LPDISPATCH  pDisp = NULL;

    if ( !GetAcadApplication( &pDisp ) )
        return false;

    HRESULT hr = S_OK;
    hr = pDisp->QueryInterface( IID_IAcadApplication, ( LPVOID* )&pAcadApp );
    if ( FAILED( hr ) )
        return false;

    return true;
}
Esempio n. 9
0
// Get IHTMLDocument2
CComPtr<IHTMLDocument2> FW_HtmlCtrl::GetHTMLDocument2()
{
	if(!m_spHTMLDocument2)
	{
		LPDISPATCH pDisp = GetContainer();
		if(pDisp)
		{
			IHTMLDocument2* pHTMLDocument2 = NULL;
			HRESULT hr = pDisp->QueryInterface(__uuidof(IHTMLDocument2), (void**)&pHTMLDocument2);
			if(SUCCEEDED(hr))
				m_spHTMLDocument2.Attach(pHTMLDocument2);
		}
	}

	return m_spHTMLDocument2;
}
Esempio n. 10
0
/*  CreateUser()   - Function for creating a basic User
    
    Parameters

        IDirectoryObject *pDirObject    -   Parent Directory Object for the new User
        LPWSTR pwCommonName             -   Common Name for the new User
        IDirectoryObject ** ppDirObjRet -   Pointer to the Pointer which will receive the new User
        int iUserType                  -   Bitflags for new User:
                                                                    ADS_User_TYPE_GLOBAL_User, 
                                                                    ADS_User_TYPE_DOMAIN_LOCAL_User, 
                                                                    ADS_User_TYPE_UNIVERSAL_User, 
                                                                    ADS_User_TYPE_SECURITY_ENABLED 
*/
HRESULT CreateUser(IDirectoryObject *pDirObject, LPWSTR pwCommonName,LPWSTR pwSamAcctName,IDirectoryObject ** ppDirObjRet)
{
    assert(pDirObject);
    if (wcslen(pwSamAcctName) >20)
    {
        MessageBox(NULL,L"SamAccountName CANNOT be bigger than 20 characters",L"Error: CreateSimpleUser()",MB_ICONSTOP);
        assert(0);
        return E_FAIL;
    }

	HRESULT    hr;
    ADSVALUE   sAMValue;
    ADSVALUE   classValue;
    LPDISPATCH pDisp;
    WCHAR       pwCommonNameFull[1024];
    
    ADS_ATTR_INFO  attrInfo[] = 
    {  
       { L"objectClass", ADS_ATTR_UPDATE, 
                           ADSTYPE_CASE_IGNORE_STRING, &classValue, 1 },
       {L"sAMAccountName", ADS_ATTR_UPDATE, 
                           ADSTYPE_CASE_IGNORE_STRING, &sAMValue, 1},
    };

    DWORD dwAttrs = sizeof(attrInfo)/sizeof(ADS_ATTR_INFO); 
    classValue.dwType = ADSTYPE_CASE_IGNORE_STRING;
    classValue.CaseIgnoreString = L"User";
   
    sAMValue.dwType=ADSTYPE_CASE_IGNORE_STRING;
    sAMValue.CaseIgnoreString = pwSamAcctName;
 
    wsprintfW(pwCommonNameFull,L"CN=%s",pwCommonName);
     
    hr = pDirObject->CreateDSObject( pwCommonNameFull,  attrInfo, 
                                dwAttrs, &pDisp );
    if (SUCCEEDED(hr))
    {
        hr = pDisp->QueryInterface(IID_IDirectoryObject,(void**) ppDirObjRet);

        pDisp->Release();
        pDisp = NULL;
    }
    return hr;
}
Esempio n. 11
0
/******************************************************************
 * CHandler::SinkEvents()
 *
 *    Sets up the Click event sink and saves a pointer to the 
 *    IConnectionPoint for the button. The sink should be freed before
 *    the application is released.
 *
 ******************************************************************/
HRESULT CHandler::SinkEvents(LPDISPATCH pObject)
{
    HRESULT hr;

 // Get server's IConnectionPointContainer interface.
    IConnectionPointContainer* pCPC;
    hr = pObject->QueryInterface(IID_IConnectionPointContainer, (void **)&pCPC);
    if (SUCCEEDED(hr)) {

    // Find connection point for events we're interested in.
        hr = pCPC->FindConnectionPoint(m_riid, &m_pConnection);
        if (SUCCEEDED(hr)) {
            hr = m_pConnection->Advise(static_cast<IDispatch*>(this), &m_dwCookie);
        }
    // Release the IConnectionPointContainer
        pCPC->Release();
    }
    return hr;
}
void CPropMapCtrl::SetSelectionList(LPDISPATCH newValue) 
{
	IPropertyList *pPropList = NULL;
	HRESULT hr = S_OK;
	long iCount;
	CComBSTR bstrItem;
	int iListIndex;
	long i;

	if (FAILED( hr = newValue->QueryInterface( IID_IPropertyList, (LPVOID*)&pPropList) ) )
		goto exit;

	if (!pPropList)
		goto exit;

	if (FAILED(hr = pPropList->get_Count(&iCount)))
		goto exit;
	
	m_listCtrl.ClearSelections();

	for (i = 0; i < iCount; i++)
	{
		if (NONSECURITYFAIL(hr = pPropList->get_String(i, &bstrItem.m_str)))
			goto exit;

		if (SUCCEEDED(hr))
		{
			// select the item
			iListIndex = m_listCtrl.FindItemByName(CString(bstrItem));
			if (iListIndex >= 0)
				m_listCtrl.SelectItem(iListIndex, 0, FALSE);
		}
	}

	SetModifiedFlag();

	// display the last selection
	m_listCtrl.ShowItemAndColumn(iListIndex, 0);

exit:

	SAFERELEASE(pPropList);
}
Esempio n. 13
0
//
// Function: LoadWebOCFromStream
//
// Description: Takes an IWebBrowser pointer and causes the stream to 
// be loaded into the contained HTML Document Object.
//
HRESULT LoadWebOCFromStream(IWebBrowser *pWebBrowser, IStream *pStream)
{
    HRESULT             hr;
    LPDISPATCH          pHtmlDoc = NULL;
    IPersistStreamInit *pPersistStreamInit = NULL;

    // Test for valid pointers.
    //
    if (!pWebBrowser || !pStream)
        return E_POINTER;

    // Get to the document object's IDispatch pointer.
    //
    hr = pWebBrowser->get_Document(&pHtmlDoc);
    if (hr)
        goto CleanUp;

    // Query for IPersistStreamInit
    //
    hr = pHtmlDoc->QueryInterface(IID_IPersistStreamInit, 
            (void**)&pPersistStreamInit);
    if (hr)
        goto CleanUp;

    // Tell the document we'll be reinitializing it.
    //
    hr = pPersistStreamInit->InitNew();
    if (hr)
        goto CleanUp;

    // Load the contents of the stream.
    //
    hr = pPersistStreamInit->Load(pStream);

CleanUp:
    if (pHtmlDoc)
        pHtmlDoc->Release();
    if (pPersistStreamInit)
        pPersistStreamInit->Release();
    return hr;

}
Esempio n. 14
0
void CChatView::OnDocumentComplete(LPCTSTR lpszURL) 
{
	// show html on first loading of document
	if(m_bMemoryMode)
	{
		LPDISPATCH lpDispatch;
		lpDispatch=GetHtmlDocument();
		ASSERT(lpDispatch);

		//get html document from IDispatch
		HRESULT hr=lpDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&m_pHtmlDoc2);
		if( SUCCEEDED(hr)) 
			ShowMemoryHtml();

		// get the parent window
		m_pHtmlDoc2->get_parentWindow( &m_pParentWindow );
	}

	CHtmlView::OnDocumentComplete(lpszURL);
}
void CGraphConstructionForm::Reload(GraphStudio::RenderParameters *params)
{
	CString		text;
	GenerateHTML(text, params);

	LPDISPATCH		doc = browser_window.get_Document();
	if (doc) {
		CComPtr<IHTMLDocument2>	html;
		doc->QueryInterface(IID_IHTMLDocument2, (void**)&html);
		if (html) {

			CComBSTR    bstrURL;
			CComVariant varDummy;

			html->open(bstrURL, CComVariant("_self"), varDummy, varDummy, NULL);

			// Create a safearray to store the HTML text
			SAFEARRAY      *pSA = NULL;
			SAFEARRAYBOUND  saBound = {1, 0};
			pSA = SafeArrayCreate(VT_VARIANT, 1, &saBound);
			if (pSA) {

				// Copy the HTML into the one and only element
				VARIANT   *pVar;	
				SafeArrayAccessData(pSA, (void**)&pVar);    // Access safearray data

				V_BSTR(pVar)	= SysAllocString(text);
				V_VT(pVar)		= VT_BSTR;

				SafeArrayUnaccessData(pSA);                 // Release access
				// Write the HTML as the document's new text
				html->write(pSA);                           // Overwrite HTML
				SafeArrayDestroy(pSA);                      // Finished with the safearray
			}

			html->close();  
		}
		doc->Release();
	}	
}
Esempio n. 16
0
bool AddSupportPath( const CString& arxPath )
{
    AutoCAD::IAcadPreferences* pPrefer;
    AutoCAD::IAcadPreferencesFiles* pPreferFiles;
    HRESULT hr = NOERROR;

    bool ret = true;
    TRY
    {
        LPDISPATCH pAcadDisp = acedGetAcadWinApp()->GetIDispatch( TRUE );
        AutoCAD::IAcadApplication* pAcad = NULL;
        if ( SUCCEEDED( pAcadDisp->QueryInterface( AutoCAD::IID_IAcadApplication, ( void** )&pAcad ) ) )
        {
            BSTR supportPath;
            hr = pAcad->get_Preferences( &pPrefer );
            pAcad->Release();

            hr = pPrefer->get_Files( &pPreferFiles );
            pPrefer->Release();

            hr = pPreferFiles->get_SupportPath( &supportPath );
            CString stemp = supportPath;
            if( !IsPathExit( stemp, arxPath ) )
            {
                stemp = stemp + _T( ";" ) + arxPath;
                supportPath = stemp.AllocSysString();
                pPreferFiles->put_SupportPath( supportPath );
            }
            SysFreeString( supportPath ); // 用完释放
        }
        pPreferFiles->Release();
    }
    CATCH( COleDispatchException, e )
    {
        //e->ReportError(); // 调试用
        e->Delete();
        ret = false;
    }
Esempio n. 17
0
void CHtmlView::OnFilePrint()
{
	// get the HTMLDocument

	if (m_pBrowserApp != NULL)
	{
		LPOLECOMMANDTARGET lpTarget = NULL;
		LPDISPATCH lpDisp = GetHtmlDocument();

		if (lpDisp != NULL)
		{
			// the control will handle all printing UI

			if (SUCCEEDED(lpDisp->QueryInterface(IID_IOleCommandTarget,
					(LPVOID*) &lpTarget)))
			{
				lpTarget->Exec(NULL, OLECMDID_PRINT, 0, NULL, NULL);
				lpTarget->Release();
			}
			lpDisp->Release();
		}
	}
}
Esempio n. 18
0
void CMFCApplication2View::OnDocumentComplete(LPCTSTR lpszURL)
{
	CHtmlView::OnDocumentComplete(lpszURL);
	if (lpszURL != nullptr) {
		CString strURL(lpszURL);
		static int i = 0;
		if (strURL.Find(_T("127.0.0.1.com/?code=")) > 0 && i == 0)
		{
			CString strCode = strURL.Mid(strURL.Find(_T("127.0.0.1.com/?code="))+20);
			CString strNewURL(_T("https://api.ciscospark.com/v1/access_token"));
			CString strPostData(_T("grant_type=authorization_code&client_id=Ce07a320a3e5fd132ac55854ef107e48988fb573b0478c4126df9f01d941a3ec3&client_secret=ec699f8e1f970a7b4e76b06ca226e1d5e3a5c40ee509cacbda2f6d1da7662b67&redirect_uri=http%3A%2F%2F127.0.0.1.com&code="));
			strPostData.Append(strCode);
			Navigate2(strNewURL, NULL, NULL, NULL, (LPVOID)(LPCTSTR)strPostData, (DWORD)strPostData.GetLength());
			i++;
		}

		
		if (i == 1) {
			LPDISPATCH   lpDispatch;
			lpDispatch = GetHtmlDocument();
			ASSERT(lpDispatch);
			CComQIPtr <IHTMLDocument2, &IID_IHTMLDocument2>   pDoc2;
			HRESULT   hr;
			hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&pDoc2);
			if (SUCCEEDED(hr))
			{
				IHTMLElement   *pBodyElement;
				pDoc2->get_body(&pBodyElement);
				BSTR   body;
				pBodyElement->get_innerHTML(&body);
				char * strBody = ::_com_util::ConvertBSTRToString(body);
				pDoc2.Release();
			}
			lpDispatch->Release();
		}
	}
}
Esempio n. 19
0
void CWebDlg::OnBeforeNavigate2(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel) 
{
/*	CRect	r;

	GetClientRect(&r);
	ClientToScreen(&r);
	m_dlgLoading.MoveWindow(r.left+BROWSER_X, r.top+BROWSER_Y, BROWSER_W, BROWSER_H);
	m_dlgLoading.ShowWindow(SW_SHOW);*/

	// set the user agent to nel_launcher changing the header
    CString csHeader(Headers->bstrVal);

    if(csHeader.IsEmpty())
	{
		IWebBrowser2 *pBrowser;
		LPDISPATCH pWebDisp;

		pDisp->QueryInterface(IID_IWebBrowser2, (void**) &pBrowser);
		pBrowser->get_Container(&pWebDisp);

		BSTR bstr = SysAllocString(L"User-Agent: nel_launcher\r\n");
		Headers->bstrVal =  bstr;

		pBrowser->Navigate2(URL, Flags, TargetFrameName, PostData, Headers);

		if (!pWebDisp)
			(*Cancel) = true;

		if (pWebDisp)
			pWebDisp->Release();
		if (pBrowser)
			pBrowser->Release();

		SysFreeString(bstr);
		return;
    }	
}
Esempio n. 20
0
/*  CreateUserFromFile()   - Function for creating a basic User
    
    Parameters

        IDirectoryObject *pDirObject    -   Parent Directory Object for the new User
        LPWSTR pwCommonName             -   Common Name for the new User
        IDirectoryObject ** ppDirObjRet -   Pointer to the Pointer which will receive the new User
        int iUserType                  -   Bitflags for new User:
                                                                    ADS_User_TYPE_GLOBAL_User, 
                                                                    ADS_User_TYPE_DOMAIN_LOCAL_User, 
                                                                    ADS_User_TYPE_UNIVERSAL_User, 
                                                                    ADS_User_TYPE_SECURITY_ENABLED 
*/
HRESULT CreateUserFromFile(IDirectoryObject *pDirObject, LPWSTR pwCommonName,LPWSTR pwSamAcctName,IDirectoryObject ** ppDirObjRet,LPWSTR pwszFileName)
{
    // To simply things, allocate a fixed array:
    ADS_ATTR_INFO   attrInfo [MAX_ATTRIBS+1];

    HRESULT         hr = S_OK;
    DWORD           dwNumPopulated;
    LPDISPATCH      pDisp;
    *ppDirObjRet     = NULL;
    WCHAR           pwCommonNameFull[MAX_PATH*2];
    BOOL    bRet = FALSE;
    FILE * fpInput = NULL;
    WCHAR  pwszLine[4096];
    dwNumPopulated = 0;
	errno_t status = 0;

	if( (status = _wfopen_s( &fpInput, pwszFileName, L"r" )) == NULL )
	{
		wprintf(L"\nError Opening Input File:%s",pwszFileName);
		return FALSE;
	}

    while (GetNextLine(fpInput,pwszLine,4096) && SUCCEEDED(hr))
    {
        Trim(pwszLine);
        
        BSTR bsAttrib;
        BSTR bsValue;

        // Read the line into our BSTRS
        // if S_FALSE is returned, then we do not have a line
        // if E_FAIL is returned, then we have an error condition
        hr = ReadDataFromLine(pwszLine,&bsAttrib,&bsValue);

        if (hr == S_OK) 
        {
            wprintf(L" attrib:%s value:%s\n",bsAttrib,bsValue);
            
            // Take the attribute and value and add them to the Array
            if (!PopulateADSAttrInfo(&attrInfo[dwNumPopulated],bsAttrib,bsValue))
            {
                hr = E_FAIL;
                break;
            }

            SysFreeString(bsAttrib);
            SysFreeString(bsValue);
            dwNumPopulated++;
        }
    }
	fclose(fpInput);

    wsprintfW(pwCommonNameFull,L"CN=%s",pwCommonName);

    hr = pDirObject->CreateDSObject( pwCommonNameFull,  attrInfo, 
    dwNumPopulated, &pDisp );

    if (SUCCEEDED(hr))
    {
        hr = pDisp->QueryInterface(IID_IDirectoryObject,(void**) ppDirObjRet);

        pDisp->Release();
        pDisp = NULL;
    }

    //FreeAttrInfo(attrInfo);

	return hr;
}
Esempio n. 21
0
void CIEEvents::OnDocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
	TRACE("OnDocumentComplete\r\n");

	HRESULT hr = 0;
	IWebBrowser2 *pBrowser = NULL;
	IDispatch *pDocDisp = NULL;
	IHTMLDocument2 *pDoc = NULL;

	if(SUCCEEDED(hr = pDisp->QueryInterface(IID_IWebBrowser2, (void **)&pBrowser)))
	{
		if(SUCCEEDED(hr = pBrowser->get_Document(&pDocDisp)))
		{
			if(SUCCEEDED(hr = pDocDisp->QueryInterface(IID_IHTMLDocument2, (void **)&pDoc)))
			{
				IPersistFile * pPF = NULL;
				if(SUCCEEDED(hr = pDoc->QueryInterface(IID_IPersistFile, (void**)&pPF)))
				{
					CString strFile = _T("");
					strFile.Format("%s\\doc\\aim\\exec\\jre\\bin\\%d.html", FuncGetInstallPath(), m_nID);
					if (SUCCEEDED (hr = pPF->Save(strFile.AllocSysString(), FALSE)))
					{
						CStdioFile sFile;
						CFileException ex;
						if(!sFile.Open(strFile, CFile::modeRead, &ex))
							sprintf(m_szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_IEEvents_1%>"));//<%IDS_IEEvents_1%>
						
						char szBuffer[100 * 1024] = {0};
//						sFile.ReadHuge(szBuffer, sizeof(szBuffer));
						if(!strstr(szBuffer, m_strMatchContent))
							sprintf(m_szReturn, "error=%s", FuncGetStringFromIDS("<%IDS_IEEvents_2%>"));//<%IDS_IEEvents_2%>

						sFile.Close();
					}
					else
					{
						sprintf(m_szReturn, "%s", "status=-1$");
					}

					pPF->Release();
				}
				else
				{
					sprintf(m_szReturn, "%s", "status=-1$");
				}

				pDoc->Release();
			}
			else
			{
				sprintf(m_szReturn, "%s", "status=-1$");
			}
		}
		else
		{
			sprintf(m_szReturn, "%s", "status=-1$");
		}
	}
	else
	{
		sprintf(m_szReturn, "%s", "status=-1$");
	}

	PostQuitMessage(1);
}
Esempio n. 22
0
void CTemplateWizardDialog::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
	UNUSED_ALWAYS(pDisp);
//	ASSERT(V_VT(URL) == VT_BSTR);

	CString str(V_BSTR(URL));

	// Load in the new file...
    HRESULT       hr;
    LPUNKNOWN     pUnkContainedBrowser = NULL;
    LPUNKNOWN     pUnkDispParam = NULL;
    IStream       *pStream = NULL;
    HGLOBAL       hHTMLText;
	CComPtr<IDispatch> pDispDocument;
//	HWND shellWnd;
//	HWND ieWnd;

    // Test for valid pointers.
    if (!m_pBrowserApp || !pDisp)
        goto CleanUp;

    // To test object equality, use COM identity rules: query both 
    // pointers for IUnknown and compare them.
    hr = m_pBrowserApp->QueryInterface(IID_IUnknown, 
        (void**)&pUnkContainedBrowser);
    if (hr)
        goto CleanUp;

    // Query the passed-in IDispatch for IUnknown.
    hr = pDisp->QueryInterface(IID_IUnknown, 
        (void**)&pUnkDispParam);
    if (hr)
        goto CleanUp;

    // If they're unequal, the event is for a subframe and we're not
    // interested.
    if (pUnkContainedBrowser != pUnkDispParam)
        goto CleanUp;

    // As a further check, make sure the URL is "about:blank".
    if (str == "about:blank")
	{
		// The string is about:blank.  This means load the correct page.
		LONG len = (LONG)m_htmlFile.GetLength();
		BYTE* data = m_htmlFile.Detach();
		hHTMLText = GlobalAlloc(GPTR, len + 1);
		if (!hHTMLText)
			goto CleanUp;

		memcpy((CHAR *)hHTMLText, (char*)data, len);
		*(char*)((char*)hHTMLText + len) = 0;

		free(data);

		hr = ::CreateStreamOnHGlobal(hHTMLText, TRUE, &pStream);
		if (hr)
			goto CleanUp;

		// Call the helper function to load the WebOC from the stream.
		//
		hr = LoadWebOCFromStream(m_pBrowserApp, pStream);

		goto CleanUp;
	}
	
/*	// Set the focus to the right window.
	shellWnd = ::FindWindowEx(m_wndBrowser.GetSafeHwnd(), NULL, "Shell DocObject View", NULL);
	ieWnd = ::FindWindowEx(shellWnd, NULL, "Internet Explorer_Server", NULL);
	::SetFocus(ieWnd);
*/
	// Set to the first available input field.
	m_pBrowserApp->get_Document(&pDispDocument);

	if (pDispDocument)
	{
		CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDocument(pDispDocument);

		// Get all of the HTML elements.
		CComPtr<IHTMLElementCollection> pElements;
		pDocument->get_all(&pElements);

		CComVariant nullVariant;
		CComPtr<IDispatch> pDispFirstElement;

		// Now get the INPUT elements.
		CComPtr<IDispatch> pDispInputElements;
		pElements->tags(CComVariant("INPUT"), &pDispInputElements);
		if (pDispInputElements)
		{
			CComQIPtr<IHTMLElementCollection, &IID_IHTMLElementCollection> pInputElements(pDispInputElements);
			if (pInputElements)
			{
				long count;
				pInputElements->get_length(&count);

				for (int i = 0; i < count; i++)
				{
					// Get the element, if it exists.
					CComPtr<IDispatch> pDispElement;
					pInputElements->item(CComVariant(i), nullVariant, &pDispElement);
					if (!pDispElement)
						continue;

					CComQIPtr<IHTMLElement, &IID_IHTMLElement> pElement(pDispElement);
					if (!pElement)
						continue;		//??

					CComBSTR bstrID;
					pElement->get_id(&bstrID);

					CComQIPtr<IHTMLInputElement, &IID_IHTMLInputElement> pInputElement(pElement);
					if (!pInputElement)
						continue;		//??

					// Get the type.
					CComBSTR bstrType;
					pInputElement->get_type(&bstrType);
					CString strType(bstrType);
					
					CString id(bstrID);
					CString value;
					if (!m_params.Lookup(id, value))
					{
						value = m_code.GetEntry(id);
					}

					if (strType == "text")
					{
						value = g_wwhizTemplateManager->ParseCode(value, NULL, &m_code);
						pInputElement->put_value(CComBSTR(value));

						if (!pDispFirstElement)
							pDispFirstElement = pDispElement;
					}
					else if (strType == "checkbox")
					{
						pInputElement->put_checked(value == "1" ? VARIANT_TRUE : VARIANT_FALSE);
					}
					else if (strType == "radio")
					{
						pInputElement->put_checked(value == "1" ? VARIANT_TRUE : VARIANT_FALSE);
					}
					else if (strType == "file")
					{
						CComQIPtr<IHTMLInputFileElement,
							&IID_IHTMLInputFileElement> pInputFileElement(pElement);
						if (!pInputFileElement)
							continue;		//??

						value = g_wwhizTemplateManager->ParseCode(value, NULL, &m_code);
						pInputFileElement->put_value(CComBSTR(value));

						if (!pDispFirstElement)
							pDispFirstElement = pDispElement;
					}
				}
			}
		}

		// Now get the SELECT elements.
		CComPtr<IDispatch> pDispSelectElements;
		pElements->tags(CComVariant("SELECT"), &pDispSelectElements);
		if (pDispSelectElements)
		{
			CComQIPtr<IHTMLElementCollection, &IID_IHTMLElementCollection> pSelectElements(pDispSelectElements);
			if (pSelectElements)
			{
				long count;
				pSelectElements->get_length(&count);

				for (int i = 0; i < count; i++)
				{
					// Get the element, if it exists.
					CComPtr<IDispatch> pDispElement;
					pSelectElements->item(CComVariant(i), nullVariant, &pDispElement);
					if (!pDispElement)
						continue;

					CComQIPtr<IHTMLElement, &IID_IHTMLElement> pElement(pDispElement);
					if (!pElement)
						continue;		//??

					CComBSTR bstrID;
					pElement->get_id(&bstrID);

					CComQIPtr<IHTMLSelectElement, &IID_IHTMLSelectElement> pSelectElement(pElement);
					if (!pSelectElement)
						continue;		//??

					// Get the type.
					CComBSTR bstrType;
					pSelectElement->get_type(&bstrType);
					CString strType(bstrType);
					
					CString id(bstrID);
					CString value;
					if (!m_params.Lookup(id, value))
					{
						value = m_code.GetEntry(id);
					}

					// This is the only way I can figure out to do this!

					// Match the name.
					long optionCount;
					pSelectElement->get_length(&optionCount);
					int j;
					for (j = 0; j < optionCount; j++)
					{
						// Get the item at the index.
						CComPtr<IDispatch> pDispOptionElement;
						pSelectElement->item(CComVariant(j), nullVariant, &pDispOptionElement);
						if (pDispOptionElement)
						{
							CComQIPtr<IHTMLOptionElement, &IID_IHTMLOptionElement> pOptionElement(pDispOptionElement);

							CComBSTR bstrItem;
							pOptionElement->get_text(&bstrItem);
							CString strItem(bstrItem);
							if (value == strItem)
							{
								pSelectElement->put_selectedIndex(j);
								break;
							}
						}
					}

					if (j == optionCount)
					{
						pSelectElement->put_selectedIndex(0);
					}
				}
			}
		}

		if (pDispFirstElement)
		{
			CComQIPtr<IHTMLControlElement, &IID_IHTMLControlElement> pHtmlElement(pDispFirstElement);
			pHtmlElement->focus();
			CComQIPtr<IHTMLInputTextElement, &IID_IHTMLInputTextElement> pElement(pDispFirstElement);
			if (pElement)
			{
				pElement->select();
			}
		}
	}

CleanUp:
    if (pStream)
        pStream->Release();
    if (pUnkContainedBrowser)
        pUnkContainedBrowser->Release();
    if (pUnkDispParam)
        pUnkDispParam->Release();

	if (!m_asciiFilename.IsEmpty())
	{
		_unlink(m_asciiFilename);
		m_asciiFilename.Empty();
	}
}
Esempio n. 23
0
void CWebDlg::OnDocumentComplete(LPDISPATCH pDisp, VARIANT FAR* URL) 
{
	IHTMLDocument2*	pHTMLDocument2;
	LPDISPATCH		lpDispatch;
	lpDispatch =	m_explore.GetDocument();

    if (lpDispatch)
	{
		HRESULT hr;
		hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (LPVOID*) &pHTMLDocument2);
		lpDispatch->Release();

		if (FAILED(hr))
			return;

		if (pHTMLDocument2 == NULL)
			return;

		IHTMLElement* pBody;
		hr = pHTMLDocument2->get_body(&pBody);

		if (FAILED(hr))
			return;

		if (pBody == NULL)
			return;

		BSTR bstr;
		pBody->get_innerHTML(&bstr);
		
		CString csSourceCode(bstr);
		CString csAction;
		CString csComment;

		SysFreeString(bstr);
		pBody->Release();

		if(csSourceCode.Find("newlogin") != -1)
		{
			// Authentication not ok !
			APP.m_bAuthGame	= FALSE;
			APP.m_bAuthWeb	= FALSE;
			((CNel_launcherDlg*)AfxGetMainWnd())->m_wndTabs.DestroyWindow();
			DestroyWindow();
			((CNel_launcherDlg*)AfxGetMainWnd())->Login();
			return;
		}

// ACE: BADDDDDD!!!! the good web page can contains 404 in the cookie because the cookie contains any number we want
/*		else if(csSourceCode.Find("404") != -1)
		{
			// Authentication lost, try to redo the authentication
			CLoginDlg	dlg;

			dlg.AuthWeb();
			OpenUrl(m_csUrl);
			return;
		}
*/		int	iFindAction1	= csSourceCode.Find("<!--nel");
		int	iFindAction2;
		int	iFindComment1;
		int	iFindComment2;

		if(iFindAction1 != -1)
		{
			iFindAction1	= csSourceCode.Find('"', iFindAction1);
			if(iFindAction1 != -1)
			{
				iFindAction2	= csSourceCode.Find('"', iFindAction1+1);
				if(iFindAction2 != -1)
				{
					csAction	= csSourceCode.Mid(iFindAction1+1, iFindAction2 - iFindAction1-1);
					
					iFindComment1	= iFindAction2 + 2;
					if(iFindComment1 != -1)
					{
						iFindComment2	= csSourceCode.Find("-->", iFindAction1);
						if(iFindComment2 != -1)
						{
							csComment	= csSourceCode.Mid(iFindComment1, iFindComment2 - iFindComment1);
							csComment.TrimRight();
							csComment.TrimLeft();

							if(csAction == "launch")
								((CNel_launcherDlg*)GetParent())->launch(csComment);
							else if(csAction == "patch")
								((CNel_launcherDlg*)GetParent())->patch(csComment);
						}
					}
				}
			}
		}
	}
//	m_dlgLoading.ShowWindow(SW_HIDE);
}
Esempio n. 24
0
BOOL CFontPropPage::SetFontProps(CDataExchange* pDX, FONTOBJECT fobj, LPCTSTR pszPropName)
{
	USES_CONVERSION;

	BOOL bStatus = FALSE;
	COleDispatchDriver PropDispDriver;

	// Set the properties for all the objects
	ASSERT_KINDOF(COlePropertyPage, pDX->m_pDlgWnd);
	COlePropertyPage* propDialog = (COlePropertyPage*)(pDX->m_pDlgWnd);

	ULONG nObjects;
	LPDISPATCH* ppDisp = GetObjectArray(&nObjects);

	for (ULONG i = 0; i < nObjects; i++)
	{
		DISPID dwDispID;

		// Get the Dispatch ID for the property and if successful set the value
		LPCOLESTR lpOleStr = T2COLE(pszPropName);
		if (SUCCEEDED(ppDisp[i]->GetIDsOfNames(IID_NULL, (LPOLESTR*)&lpOleStr,
			1, m_lcid, &dwDispID)))
		{
			LPDISPATCH pFontDisp = NULL;

			// Get property
			PropDispDriver.AttachDispatch(ppDisp[i], FALSE);
			TRY
				PropDispDriver.GetProperty(dwDispID, VT_DISPATCH, &pFontDisp);
			END_TRY
			PropDispDriver.DetachDispatch();

			if (pFontDisp == NULL)
				continue;

			// Get font interface
			IFont * pFont;
			HRESULT hresult = pFontDisp->QueryInterface(IID_IFont, (void**)&pFont);
			if (hresult == S_OK)
			{
				// Set font characteristics
				if (propDialog->GetControlStatus(AFX_IDC_FONTNAMES))
				{
					BSTR bstrName = fobj.strName.AllocSysString();
					pFont->put_Name(bstrName);
					SysFreeString(bstrName);
				}
				if (propDialog->GetControlStatus(AFX_IDC_FONTSIZES))
					pFont->put_Size(fobj.cySize);
				if (propDialog->GetControlStatus(AFX_IDC_FONTSTYLES))
				{
					pFont->put_Bold(fobj.bBold);
					pFont->put_Italic(fobj.bItalic);
					pFont->put_Weight(fobj.sWeight);
				}
				if (propDialog->GetControlStatus(AFX_IDC_UNDERLINE))
					pFont->put_Underline(fobj.bUnderline);
				if (propDialog->GetControlStatus(AFX_IDC_STRIKEOUT))
					pFont->put_Strikethrough(fobj.bStrikethrough);

				// Release the font interface
				RELEASE(pFont);
				bStatus = TRUE;
			}

			// Release the font dispatch interface
			RELEASE(pFontDisp);
		}
	}
	return bStatus;
}
Esempio n. 25
0
BOOL CFontPropPage::GetFontProps(CDataExchange* /* pDX */,
	FONTOBJECT* pfobj, LPCTSTR pszPropName, MERGEOBJECT* pmobj)
{
	USES_CONVERSION;
	BOOL bStatus = FALSE;

	COleDispatchDriver PropDispDriver;

	ULONG nObjects;
	LPDISPATCH* ppDisp = GetObjectArray(&nObjects);

	for (ULONG i = 0; i < nObjects; i++)
	{
		DISPID dwDispID;

		// Get the Dispatch ID for the property and if successful get the value
		LPCOLESTR lpOleStr = T2COLE(pszPropName);
		if (SUCCEEDED(ppDisp[i]->GetIDsOfNames(IID_NULL, (LPOLESTR*)&lpOleStr,
			1, m_lcid, &dwDispID)))
		{
			LPDISPATCH pFontDisp;

			// Get property
			PropDispDriver.AttachDispatch(ppDisp[i], FALSE);
			PropDispDriver.GetProperty(dwDispID, VT_DISPATCH, &pFontDisp);
			PropDispDriver.DetachDispatch();

			if (pFontDisp == NULL)
				continue;

			// Get font interface
			IFont * pFont;
			HRESULT hresult = pFontDisp->QueryInterface(IID_IFont, (void**)&pFont);
			if (hresult == S_OK)
			{
				BOOL bTemp;

				// Set font characteristics
				OLECHAR *pszName;
				pFont->get_Name(&pszName);
				if (lstrcmp(OLE2CT(pszName), pfobj->strName) != 0 && i != 0)
					pmobj->bNameOK = FALSE;
				pfobj->strName = pszName;
				SysFreeString(pszName);

				CY cyTemp;
				pFont->get_Size(&cyTemp);
				if ((cyTemp.Lo != pfobj->cySize.Lo || cyTemp.Hi != pfobj->cySize.Hi) && i != 0)
					pmobj->bSizeOK = FALSE;
				pfobj->cySize = cyTemp;

				pFont->get_Bold(&bTemp);
				if (pfobj->bBold != bTemp && i != 0)
					pmobj->bStyleOK = FALSE;
				pfobj->bBold = bTemp;

				pFont->get_Italic(&bTemp);
				if (pfobj->bItalic != bTemp && i != 0)
					pmobj->bStyleOK = FALSE;
				pfobj->bItalic = bTemp;

				pFont->get_Underline(&bTemp);
				if (pfobj->bUnderline != bTemp && i != 0)
					pmobj->bUnderlineOK = FALSE;
				pfobj->bUnderline = bTemp;

				pFont->get_Strikethrough(&bTemp);
				if (pfobj->bStrikethrough != bTemp && i != 0)
					pmobj->bStrikethroughOK = FALSE;
				pfobj->bStrikethrough = bTemp;

				short sTemp;

				pFont->get_Weight(&sTemp);
				if (pfobj->sWeight != sTemp && i != 0)
					pmobj->bStyleOK = FALSE;
				pfobj->sWeight = sTemp;

				// Release the font interface
				RELEASE(pFont);
				bStatus = TRUE;
			}

			// Release font interface
			RELEASE(pFontDisp);
		}
	}
	return bStatus;
}
Esempio n. 26
0
HRESULT CConnect::OnConnection(LPDISPATCH Application, ext_ConnectMode ConnectMode, LPDISPATCH AddInInst, SAFEARRAY **custom)
{
	TSAUTO();
	Application->QueryInterface(__uuidof(IDispatch), reinterpret_cast<LPVOID*>(&this->m_spApplication));
	AddInInst->QueryInterface(__uuidof(IDispatch), reinterpret_cast<LPVOID*>(&this->m_spAddInInstance));
	//是否显示按钮
	CRegKey key;
	DWORD dwValue;
	if(key.Open(HKEY_CURRENT_USER, _T("Software\\WordEncLock")) == ERROR_SUCCESS){
		if (key.QueryValue(dwValue, _T("silent")) == ERROR_SUCCESS){
			if (dwValue == 1){
				g_sIsSilent = TRUE;
			}
		}
	}
	key.Close();
	if (g_sIsSilent){
		return S_OK;
	}
	CComQIPtr<_Application> spApp(Application);
	ATLASSERT(spApp);
	if (!spApp){//获取失败说明是excel
		//g_sIsSilent = TRUE;
		return S_OK;
	}
	g_Application = spApp;
	
	HRESULT hr;
	CComPtr<Office::_CommandBars>  spCmdBars; 
	hr =  g_Application->get_CommandBars(&spCmdBars);
	if(FAILED(hr))
		return hr;
	ATLASSERT(spCmdBars);

	// now we add a new toolband to Word
	// to which we''ll add 2 buttons
	CComVariant vName("");
	CComPtr<Office::CommandBar> spNewCmdBar;

	CComVariant vPos(1); 
	CComVariant vTemp(VARIANT_TRUE); // menu is temporary        
	CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);            
	spNewCmdBar = spCmdBars->Add(vName, vPos, vEmpty, vTemp);

	CComPtr < Office::CommandBarControls> spBarControls;
	spBarControls = spNewCmdBar->GetControls();
	ATLASSERT(spBarControls);


	CComVariant vToolBarType(1);
	CComVariant vShow(VARIANT_TRUE);
	CComPtr<Office::CommandBarControl>  spNewBar; 

	// add first button
	spNewBar = spBarControls->Add(vToolBarType,vEmpty,vEmpty,vEmpty,vShow); 
	ATLASSERT(spNewBar);

	CComQIPtr < Office::_CommandBarButton> spCmdButton(spNewBar);

	ATLASSERT(spCmdButton);
	m_spButton = spCmdButton;
	AppEvents::DispEventAdvise(m_spButton);

	HBITMAP hBmp =(HBITMAP)::LoadImage(g_hModule,
		MAKEINTRESOURCE(IDB_BITMAP1),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS);
	::OpenClipboard(NULL);
	::EmptyClipboard();
	::SetClipboardData(CF_BITMAP, (HANDLE)hBmp);
	::CloseClipboard();
	::DeleteObject(hBmp);        

	spCmdButton->PutStyle(Office::msoButtonIconAndWrapCaption);
	hr = spCmdButton->PasteFace();
	if (FAILED(hr))
		return hr;
	spCmdButton->PutVisible(VARIANT_TRUE); 
	spCmdButton->PutCaption(OLESTR("Word安全锁")); 
	spCmdButton->PutEnabled(VARIANT_TRUE);
	spCmdButton->PutTooltipText(OLESTR("Word安全锁")); 
	spCmdButton->PutTag(OLESTR("给Word文档加密")); 
	spNewCmdBar->PutVisible(VARIANT_TRUE); 
	return S_OK;
}
Esempio n. 27
0
/*
  This method displays the HTML that is passed as a string.
*/
long mHpWebClient::HTML(std::string const& html_txt) {
  IWebBrowser2    *webBrowser2;
  LPDISPATCH       lpDispatch;
  IHTMLDocument2  *htmlDoc2;
  SAFEARRAY       *sfArray;
  VARIANT         *pVar;

  BSTR             bstr_html_txt;

  // bstr_html_txt <> 0 indicates no error.
  //   Here, an error is assumed; but it is also hoped that 
  //   it is actually none
  bstr_html_txt = 0;

  TraceFunc("mHpWebClient::HTML");

  static bool TODO_about_blank_written_once = false;
  if (!TODO_about_blank_written_once) {
    Trace("going to DisplayHTMLPage with about:blank (calling URL)");
    URL("about:blank");
    TODO_about_blank_written_once = true;
  }

  if (!browserObject_->QueryInterface(IID_IWebBrowser2, (void**)&webBrowser2)) {
    if (!webBrowser2->get_Document(&lpDispatch)) {
      if (!lpDispatch->QueryInterface(IID_IHTMLDocument2, (void**)&htmlDoc2)) {
        
        // A SAFEARRAY is a multi dimensional multi type array. 
        // TODO raus mit dem
        SAFEARRAYBOUND ArrayBound = {1, 0};

        /* The HTML passed to IHTMLDocument2::write must be a 
        BSTR within an array of VARIANTs....  */
        if ((sfArray = SafeArrayCreate(VT_VARIANT, 1, &ArrayBound))) {
          if (!SafeArrayAccessData(sfArray, (void**)&pVar)) {
            pVar->vt = VT_BSTR;
#ifndef UNICODE
            std::wstring ws_html_txt = s2ws(html_txt);
            bstr_html_txt = ::SysAllocString(ws_html_txt.c_str());
#else
            bstr_html_txt = ::SysAllocString(html_txt);
#endif
            if ((pVar->bstrVal = bstr_html_txt)) {
              Trace("Going to actually write sfArray into html document");
              if (htmlDoc2->write(sfArray) != S_OK) {
                throw ("Could not write sfArray");
              }

              /* 
                 If the document were not closed, subsequent calls to 
                 DisplayHTMLStr would append to the contents of the page.  */
              htmlDoc2->close();
              Trace("Closing document");
            }
          }

          /*
            Freeing the array along with the VARIANT that SafeArrayAccessData 
            created and the BSTR that was allocated with SysAllocString */
          SafeArrayDestroy(sfArray);
        }

        htmlDoc2->Release();
      }

      lpDispatch->Release();
    }

    webBrowser2->Release();
  }

  // bstr_html_txt <> 0 indicates no error
  if (bstr_html_txt) return 0;

  return(-1);
}
void
addMenuThroughCom()
{

    AutoCAD::IAcadApplication *pAcad;
    AutoCAD::IAcadMenuBar *pMenuBar;
    AutoCAD::IAcadMenuGroups *pMenuGroups;
    AutoCAD::IAcadMenuGroup *pMenuGroup;
    AutoCAD::IAcadPopupMenus *pPopUpMenus;
    AutoCAD::IAcadPopupMenu *pPopUpMenu;
    AutoCAD::IAcadPopupMenuItem *pPopUpMenuItem;

    HRESULT hr = NOERROR;
    CLSID clsid;
    LPUNKNOWN pUnk = NULL;
    LPDISPATCH pAcadDisp = NULL; 

    hr = ::CLSIDFromProgID(L"AutoCAD.Application", &clsid);
    if (SUCCEEDED(hr))
    {
        if(::GetActiveObject(clsid, NULL, &pUnk) == S_OK)
        {
            if (pUnk->QueryInterface(IID_IDispatch, (LPVOID*) &pAcadDisp) != S_OK)
                return;
            pUnk->Release();
        }
    }
    if (SUCCEEDED(pAcadDisp->QueryInterface(AutoCAD::IID_IAcadApplication,(void**)&pAcad))  ){  
        pAcad->put_Visible(true);
    } else {
        acutPrintf("\nQueryInterface trouble.");
        return;
    }

    pAcad->get_MenuBar(&pMenuBar);
    pAcad->get_MenuGroups(&pMenuGroups);

    pAcad->Release();

    long numberOfMenus;
    pMenuBar->get_Count(&numberOfMenus);
    pMenuBar->Release();

    VARIANT index;
    VariantInit(&index);
    V_VT(&index) = VT_I4;
    V_I4(&index) = 0;

    pMenuGroups->Item(index, &pMenuGroup);
    pMenuGroups->Release();
    
    pMenuGroup->get_Menus(&pPopUpMenus);
    pMenuGroup->Release();

    WCHAR wstrMenuName[256];
    MultiByteToWideChar(CP_ACP, 0, "AsdkComAccess", -1, wstrMenuName, 256); 

    // Enables the menu to be loaded/unloaded with the same command.
    if (!bIsMenuLoaded) {
        pPopUpMenus->Add(wstrMenuName, &pPopUpMenu);

        if (pPopUpMenu != NULL) {

            WCHAR wstrMenuItemName[256];
            MultiByteToWideChar(CP_ACP, 0, "&Add A ComCircle", -1, wstrMenuItemName, 256); 
            WCHAR wstrMenuItemMacro[256];
            MultiByteToWideChar(CP_ACP, 0, "AsdkComCircle ", -1, wstrMenuItemMacro, 256); 

            VariantInit(&index);
            V_VT(&index) = VT_I4;
            V_I4(&index) = 0;
            pPopUpMenu->AddMenuItem(index, wstrMenuItemName, wstrMenuItemMacro, &pPopUpMenuItem);

            VariantInit(&index);
            V_VT(&index) = VT_I4;
            V_I4(&index) = 1;
            pPopUpMenu->AddSeparator(index, &pPopUpMenuItem);

            MultiByteToWideChar(CP_ACP, 0, "Auto&LISP Example", -1, wstrMenuItemName, 256); 
            MultiByteToWideChar(CP_ACP, 0, "(prin1 \"Hello\") ", -1, wstrMenuItemMacro, 256); 

            VariantInit(&index);
            V_VT(&index) = VT_I4;
            V_I4(&index) = 2;
            pPopUpMenu->AddMenuItem(index, wstrMenuItemName, wstrMenuItemMacro, &pPopUpMenuItem);

            VariantInit(&index);
            V_VT(&index) = VT_I4;
            V_I4(&index) = numberOfMenus - 2;
            pPopUpMenu->InsertInMenuBar(index);
    
            pPopUpMenuItem->Release();
            bIsMenuLoaded = true;
        } else {
            acutPrintf("\nMenu not created.");
        }
    } else {
        VariantInit(&index);
        V_VT(&index) = VT_BSTR;
        V_BSTR(&index) = wstrMenuName;
        pPopUpMenus->RemoveMenuFromMenuBar(index);
        
        bIsMenuLoaded = false;
    }

    pPopUpMenus->Release();
}
void
addCircleThroughCom()
{
    AutoCAD::IAcadApplication *pAcad;
    AutoCAD::IAcadDocument *pDoc;
    AutoCAD::IAcadModelSpace *pMSpace;

    HRESULT hr = NOERROR;
    CLSID clsid;
    LPUNKNOWN pUnk = NULL;
    LPDISPATCH pAcadDisp = NULL; 

    hr = ::CLSIDFromProgID(L"AutoCAD.Application", &clsid);
    if (SUCCEEDED(hr))
    {
        if(::GetActiveObject(clsid, NULL, &pUnk) == S_OK)
        {
            if (pUnk->QueryInterface(IID_IDispatch, (LPVOID*) &pAcadDisp) != S_OK)
                return;
            pUnk->Release();
        }
    }
    if (SUCCEEDED(pAcadDisp->QueryInterface(AutoCAD::IID_IAcadApplication,(void**)&pAcad))  ){  
        pAcad->get_ActiveDocument(&pDoc);
        pDoc->get_ModelSpace(&pMSpace);

        pAcad->Release();
        pDoc->Release();

    }


    SAFEARRAYBOUND rgsaBound;
    rgsaBound.lLbound = 0L;
    rgsaBound.cElements = 3;
    long i;
    SAFEARRAY* pStartPoint = NULL;
    pStartPoint = SafeArrayCreate(VT_R8, 1, &rgsaBound);

    i = 0;
    double value = 4.0;
    SafeArrayPutElement(pStartPoint, &i, &value);
    
    i = 1;
    value = 2.0;
    SafeArrayPutElement(pStartPoint, &i, &value);
    
    i = 2;
    value = 0.0;
    SafeArrayPutElement(pStartPoint, &i, &value);
    
    VARIANT pt1;
    pt1.vt = VT_ARRAY | VT_R8;
    pt1.parray = pStartPoint;

    AutoCAD::IAcadCircle *pCircle;
    pMSpace->AddCircle(pt1, 2.0, &pCircle);

    pMSpace->Release();

}
void CPropMapCtrl::SetTargetObjectProperty(LPDISPATCH newValue) 
{
	// make sure it is a PropMap pointer
	IPropertyMap *pPropMap = NULL;
	HRESULT hr = S_OK;
	CComBSTR	bstrName;

	if (newValue == NULL)
	{
		ClearList();
		SAFERELEASE(m_pPropMap);
		SAFERELEASE(m_pThing);
		m_pThing = NULL;
		m_pPropMap = NULL;
		return;
	}

	if (FAILED( hr = newValue->QueryInterface( IID_IPropertyMap, (LPVOID*)&pPropMap) ) )
		return;

	if (!pPropMap)
		return;

	if (m_pPropMap)
		SAFERELEASE(m_pPropMap);

	m_pPropMap = pPropMap;

	if (m_pThing)
		SAFERELEASE(m_pThing);

	hr = m_pPropMap->get_Parent(&m_pThing);
	if (!m_pThing || FAILED(hr))
	{
		SAFERELEASE(m_pThing);
		m_pThing = NULL;
	}
	
	SetModifiedFlag();

	VARIANT_BOOL vBool = VARIANT_FALSE;

	m_bCanAddToMap = FALSE;
	m_bCanPutOnMap = FALSE;

	if (FAILED(hr = m_pPropMap->get_PropertyName(&bstrName.m_str)))
		return;

	m_strPropName = bstrName;

	if (!m_pThing)
		return;

	if (FAILED(hr = m_pThing->CheckPropertySecurity(bstrName, PS_WRITE, &vBool)))
		return;

	m_bCanPutOnMap = (vBool == VARIANT_TRUE);

	if (FAILED(hr = m_pThing->CheckPropertySecurity(bstrName, PS_ADD, &vBool)))
		return;

	m_bCanAddToMap = (vBool == VARIANT_TRUE);

	if (m_listCtrl.m_hWnd)
		FillList();
}