HRESULT CWtlHtmlView::SetDocumentText( CString cstr)
{
	_bstr_t str(cstr);
	HRESULT hr = S_OK;
	VARIANT *param;
	SAFEARRAY *sfArray;
	IHTMLDocument2 *document;
	BSTR bstr = str.Detach();

	// Creates a new one-dimensional array
	sfArray = SafeArrayCreateVector(VT_VARIANT, 0, 1);

	if(m_spHTMLDocument==NULL)
		this->GetBody();

	document= m_spHTMLDocument;
	if (sfArray == NULL || document == NULL) {
		hr=E_FAIL;
		goto cleanup;
	}

	hr = SafeArrayAccessData(sfArray,(LPVOID*) & param);
	param->vt = VT_BSTR;
	param->bstrVal = bstr;
	hr = SafeArrayUnaccessData(sfArray);
	hr = document->write(sfArray);

cleanup:
	if (sfArray != NULL) {
		SafeArrayDestroy(sfArray);
	}
	return hr;
}
void IEView::write(const wchar_t *text) {
	IHTMLDocument2 *document = getDocument();
	if (document != NULL) {
		SAFEARRAY *safe_array = SafeArrayCreateVector(VT_VARIANT,0,1);
		if (safe_array != NULL) {
			VARIANT	*variant;
			BSTR bstr;
			SafeArrayAccessData(safe_array,(LPVOID *)&variant);
			variant->vt = VT_BSTR;
			variant->bstrVal = bstr = SysAllocString(text);
			SafeArrayUnaccessData(safe_array);
			document->write(safe_array);
			//SysFreeString(bstr); -> SafeArrayDestroy should be enough
			SafeArrayDestroy(safe_array);
		}
		document->Release();
	}
}
Beispiel #3
0
void SimpleBrowser::Write(LPCTSTR string)
{
	if (m_pBrowser!= NULL) 
	{
		// get document interface
		IHTMLDocument2 *document = GetDocument();
		if (document != NULL) 
		{
			// construct text to be written to browser as SAFEARRAY
			SAFEARRAY *safe_array = SafeArrayCreateVector(VT_VARIANT,0,1);
			VARIANT	*variant;
			SafeArrayAccessData(safe_array,(LPVOID *)&variant);
			variant->vt      = VT_BSTR;
			variant->bstrVal = CString(string).AllocSysString();
			SafeArrayUnaccessData(safe_array);
			// write SAFEARRAY to browser document
			document->write(safe_array);
			document->Release();
			document = NULL;
		}
	}
}
void CWtlHtmlView::Write(LPCTSTR string)
{
	if (m_spWebBrowser2 == NULL)
	GetBody();

	if (m_spWebBrowser2 != NULL) {

		// get document interface

		IHTMLDocument2 *document = GetDocument();
		
		if (document != NULL) {

			// construct text to be written to browser as SAFEARRAY

			SAFEARRAY *safe_array = SafeArrayCreateVector(VT_VARIANT,0,1);
			
			VARIANT	*variant;
			
			SafeArrayAccessData(safe_array,(LPVOID *)&variant);
			CComBSTR bstrTmp = string;
			variant->vt      = VT_BSTR;
			variant->bstrVal = bstrTmp;
			// write SAFEARRAY to browser document

			document->write(safe_array);
			
			SafeArrayUnaccessData(safe_array);

			
			document->Release();
			document = NULL;

		}

	}
}