<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[IWebBrowser2::get_Document - HILFE!]]></title><description><![CDATA[<p>Hallo,<br />
ich will in ein Browserfenster direkt HTML Code reinladen, was ich mit IHTMLDocument2::write() ja machen kann.<br />
Aber um ein IHTMLDocument2-Objekt zu kriegen muss ich das ja von meinem IWebBrowser2-Objekt mir holen. Das geht aber irgendwie nicht. Ich mach das so:</p>
<pre><code>LPDISPATCH lpDispatch;
IHTMLDocument2	*htmlDoc2;

// m_pWebBrowser2 ist ein funktionierendes IWebBrowser2-Objekt
// das gibt S_OK zurück:
m_pWebBrowser2-&gt;get_Document(&amp;lpDispatch)
// aber hier stürzt es ab:
lpDispatch-&gt;QueryInterface(IID_IHTMLDocument2, (void**)&amp;htmlDoc2)
</code></pre>
<p>wie gesagt, ich erhalte keinen Fehler, sondern mein Programm stürzt ab.<br />
Wenn ich das im Debug-Modus laufen lass krieg ich diese Meldung:<br />
Unhandled exception in ole.exe: 0xC0000005: Access Violation.</p>
<p>Aber wo ist hier eine Zugriffsverletzung? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Vielen Dank für Hilfe,<br />
Black Shadow</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/171391/iwebbrowser2-get_document-hilfe</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 11:13:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/171391.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 24 Jan 2007 23:04:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to IWebBrowser2::get_Document - HILFE! on Wed, 24 Jan 2007 23:04:56 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich will in ein Browserfenster direkt HTML Code reinladen, was ich mit IHTMLDocument2::write() ja machen kann.<br />
Aber um ein IHTMLDocument2-Objekt zu kriegen muss ich das ja von meinem IWebBrowser2-Objekt mir holen. Das geht aber irgendwie nicht. Ich mach das so:</p>
<pre><code>LPDISPATCH lpDispatch;
IHTMLDocument2	*htmlDoc2;

// m_pWebBrowser2 ist ein funktionierendes IWebBrowser2-Objekt
// das gibt S_OK zurück:
m_pWebBrowser2-&gt;get_Document(&amp;lpDispatch)
// aber hier stürzt es ab:
lpDispatch-&gt;QueryInterface(IID_IHTMLDocument2, (void**)&amp;htmlDoc2)
</code></pre>
<p>wie gesagt, ich erhalte keinen Fehler, sondern mein Programm stürzt ab.<br />
Wenn ich das im Debug-Modus laufen lass krieg ich diese Meldung:<br />
Unhandled exception in ole.exe: 0xC0000005: Access Violation.</p>
<p>Aber wo ist hier eine Zugriffsverletzung? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>Vielen Dank für Hilfe,<br />
Black Shadow</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1216506</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1216506</guid><dc:creator><![CDATA[Black Shadow]]></dc:creator><pubDate>Wed, 24 Jan 2007 23:04:56 GMT</pubDate></item><item><title><![CDATA[Reply to IWebBrowser2::get_Document - HILFE! on Thu, 25 Jan 2007 09:24:24 GMT]]></title><description><![CDATA[<p>ok ich weiß nun dass get_Document zwar S_OK zurückliefert, aber lpDispatch ist danach weiterhin 0.<br />
<img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /><br />
Weiß einer Rat?</p>
<p>Danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1216656</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1216656</guid><dc:creator><![CDATA[Black Shadow]]></dc:creator><pubDate>Thu, 25 Jan 2007 09:24:24 GMT</pubDate></item><item><title><![CDATA[Reply to IWebBrowser2::get_Document - HILFE! on Thu, 25 Jan 2007 11:22:49 GMT]]></title><description><![CDATA[<p>Ist im WebBrowser denn ne Seite geladen? Zumindest \1:blank oder so?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1216764</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1216764</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Thu, 25 Jan 2007 11:22:49 GMT</pubDate></item><item><title><![CDATA[Reply to IWebBrowser2::get_Document - HILFE! on Sun, 28 Jan 2007 10:53:58 GMT]]></title><description><![CDATA[<p>geeky schrieb:</p>
<blockquote>
<p>Ist im WebBrowser denn ne Seite geladen? Zumindest \1:blank oder so?</p>
</blockquote>
<p>Danke für den Hinweis, daran könnte es gelegen haben, zumindest klappts jetzt :).<br />
Ich hab bei der OLE-Initialisierung auch was geändert, vielleicht war auch da der Fehler.</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1218499</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1218499</guid><dc:creator><![CDATA[Black Shadow]]></dc:creator><pubDate>Sun, 28 Jan 2007 10:53:58 GMT</pubDate></item><item><title><![CDATA[Reply to IWebBrowser2::get_Document - HILFE! on Sun, 04 Feb 2007 03:17:06 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Hat jemand Ahnung wie ich Kontrolle über eine bestehende IE Instanz erlangen kann um beispielsweise auf eine andere Seite zu navigieren?<br />
Habe bei MS ein altes Beispiel für den IE4 gefunden. Das klappt allerdings alles nicht mehr bei IE7.<br />
Wäre für Beispiele dankbar!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1222509</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1222509</guid><dc:creator><![CDATA[Ender]]></dc:creator><pubDate>Sun, 04 Feb 2007 03:17:06 GMT</pubDate></item><item><title><![CDATA[Reply to IWebBrowser2::get_Document - HILFE! on Sun, 04 Feb 2007 07:43:06 GMT]]></title><description><![CDATA[<p>Du musst zuerst eine Seite &quot;laden&quot;, bevor ein Document verfügbar ist!</p>
<p>So geht es (this ist CHtmlView oder abgeleitet davon; geht natürlich auch *ohne* CHtmlView!):</p>
<pre><code class="language-cpp">this-&gt;Navigate2(_T(&quot;\1:blank&quot;),NULL,NULL); 
  IDispatch *pDisp = this-&gt;GetHtmlDocument();
  if (pDisp != NULL)
  {
    CComPtr&lt;IHTMLDocument2&gt; doc;
    pDisp-&gt;QueryInterface(IID_IHTMLDocument2, (void**) &amp;doc);

    HRESULT hresult = S_OK;
      VARIANT *param;
      SAFEARRAY *sfArray;
      BSTR bstr = SysAllocString(OLESTR(&quot;Written by IHTMLDocument2::write().&quot;));

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

      if (sfArray == NULL || doc == NULL) {
      goto cleanup;
      }

    hresult = SafeArrayAccessData(sfArray,(LPVOID*) &amp; param);
      param-&gt;vt = VT_BSTR;
      param-&gt;bstrVal = bstr;
      hresult = SafeArrayUnaccessData(sfArray);
      hresult = doc-&gt;write(sfArray);

  cleanup:
      SysFreeString(bstr);
      if (sfArray != NULL) {
          SafeArrayDestroy(sfArray);
      }
      pDisp-&gt;Release();
  }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1222524</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1222524</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Sun, 04 Feb 2007 07:43:06 GMT</pubDate></item><item><title><![CDATA[Reply to IWebBrowser2::get_Document - HILFE! on Sun, 04 Feb 2007 11:09:50 GMT]]></title><description><![CDATA[<p>Danke Jochen, so in der Art klappts bei mir jetzt auch :).<br />
Mein Code:</p>
<pre><code class="language-cpp">bool CWebBrowser::HTML(const char *psz)
{
	LPDISPATCH		lpDispatch = 0;
	IHTMLDocument2	*htmlDoc2 = 0;

	if(m_pWebBrowser2-&gt;get_Document(&amp;lpDispatch) != S_OK)
	{
		MessageBox(m_hwnd, &quot;HTML Write: get_Document()&quot;, &quot;Fehler&quot;, 0);
		return false;
	}
	if(!lpDispatch)
	{
		MessageBox(m_hwnd, &quot;HTML Write: get_Document() return value&quot;, &quot;Fehler&quot;, 0);
		return false;
	}

	if(lpDispatch-&gt;QueryInterface(IID_IHTMLDocument2, (void**)&amp;htmlDoc2) != S_OK)
	{
		MessageBox(m_hwnd, &quot;HTML Write: QueryInterface() Dispatch&quot;, &quot;Fehler&quot;, 0);
		htmlDoc2-&gt;Release();
		return false;
	}
	if(!htmlDoc2)
	{
		MessageBox(m_hwnd, &quot;HTML Write: QueryInterface() Dispatch return value&quot;, &quot;Fehler&quot;, 0);
		htmlDoc2-&gt;Release();
		return false;
	}

	SAFEARRAY       *sfArray;
	VARIANT         *pVar;
	BSTR             bstr_html_txt;
	OLECHAR			*pszOle;

	bool bRet = true;

	SAFEARRAYBOUND ArrayBound = {1, 0};

	sfArray = SafeArrayCreate(VT_VARIANT, 1, &amp;ArrayBound);
	if(sfArray)
	{
		if(SafeArrayAccessData(sfArray, (void**)&amp;pVar) == S_OK)
		{
			pVar-&gt;vt = VT_BSTR;

			int iStrLen = lstrlen(psz);
			pszOle = (OLECHAR*)malloc(sizeof(OLECHAR) * (iStrLen + 1));
			MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, psz, -1,
					pszOle, iStrLen);
			pszOle[iStrLen] = 0;

			bstr_html_txt = SysAllocString(pszOle);
			pVar-&gt;bstrVal = bstr_html_txt;

			if(pVar-&gt;bstrVal)
			{
				htmlDoc2-&gt;write(sfArray);
				content.append(psz);
			}
			else
			{
				MessageBox(m_hwnd, &quot;pVar Initialisierung&quot;, &quot;Fehler&quot;, MB_ICONERROR);
				bRet = false;
			}
		}
		else
		{
			MessageBox(m_hwnd, &quot;SafeArrayAccessData()&quot;, &quot;Fehler&quot;, MB_ICONERROR);
			bRet = false;
		}
	}
	else
	{
		MessageBox(m_hwnd, &quot;sfArray Create&quot;, &quot;Fehler&quot;, MB_ICONERROR);
		bRet = false;
	}

	SysFreeString(bstr_html_txt);
	SafeArrayDestroyData(sfArray);
	SafeArrayDestroy(sfArray);
	htmlDoc2-&gt;Release();
	lpDispatch-&gt;Release();
	m_pWebBrowser2-&gt;Refresh();
	free(pszOle);

	return bRet;
}
</code></pre>
<p>was ich mich frage - ist das mit dem Release richtig? weil dein code released net so viel.<br />
Außerdem: Ist die Umwandlung in einen OleString, dann in einen SysString notwendig? gehts nicht von char* in einen SysString?</p>
<p>Und warum liefert m_pWebBrowser2-&gt;get_Document S_OK zurück, auch wenn kein \1:blank dokument geladen ist und pDispatch 0 dann ist?</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/35415">@ender</a>: kriegst du irgendwo ne fehlermeldung? gibt auch mal link</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1222593</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1222593</guid><dc:creator><![CDATA[Black Shadow]]></dc:creator><pubDate>Sun, 04 Feb 2007 11:09:50 GMT</pubDate></item><item><title><![CDATA[Reply to IWebBrowser2::get_Document - HILFE! on Sun, 04 Feb 2007 12:20:30 GMT]]></title><description><![CDATA[<p>Bzgl. OleStr: Man macht das halt bei statischen Texten so... ist aber historisch bedingt und Du könntest anstelle von OLESTR() auch L verwenden.<br />
Bzgl. Release: Ich habe teilweise auch CComPtr verwendet, der macht automatisch ein release...<br />
AFAIK muss man vorher irgendwas geladen haben, damit es funktioniert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1222650</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1222650</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Sun, 04 Feb 2007 12:20:30 GMT</pubDate></item></channel></rss>