<?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[ATL&#x2F;COM: _com_error: &amp;quot;Unzulässiger Zugriff auf einen Speicherbereich.&amp;quot;]]></title><description><![CDATA[<p>(VC++6, NT 4)</p>
<p>hallo,</p>
<p>ich habe einen Test ATL Server, und einen Test ATL Client.<br />
Atl-Server hat folgende Methode:</p>
<pre><code>// Interface:
[id(1), helpstring(&quot;Methode getString&quot;)] HRESULT getString([out, retval] BSTR str);
// Implementierung:
// Methode soll eine memeber (CString m_Message) zurück geben
// die im Konstruktor mit &quot;--- nothing ---&quot; initialisiert wird
STDMETHODIMP CHello::getString(BSTR str)
{
   AFX_MANAGE_STATE(AfxGetStaticModuleState())

   str = m_Message.AllocSysString();
   _bstr_t bstr(str, false);

   CString stemp2(_T(&quot;&quot;));
   W2A(bstr, stemp2.GetBuffer(256), 256);
   stemp2.ReleaseBuffer();
   stemp2.Format(stemp2, &quot;ATL_Server msg: %s&quot;, stemp2);
   AfxMessageBox(stemp2);

   return S_OK;
}
</code></pre>
<p>ATL-Client benutzt den Server so:</p>
<pre><code>void CATL_ClientDlg::OnButtonTest()
{
   BSTR bstr = NULL;
   CString stemp(_T(&quot;---------- an empty CString ----------&quot;));
   bstr = stemp.AllocSysString();

   try
   {  // rufe Methode des ATL-Serversauf:
      m_IHello-&gt;getString(bstr);

      CString stemp2(_T(&quot;&quot;));
      W2A(bstr, stemp2.GetBuffer(256), 256);
      stemp2.ReleaseBuffer();
      stemp2.Format(stemp2, &quot;ATL_Client msg: %s&quot;, stemp2);
      AfxMessageBox(stemp2);
      //m_Message = bsTemp.operator const wchar_t *();
      //showCurrEvent(m_Message);
   }
   catch(_com_error&amp; rExc)
   {
      CString sMsg;
      _bstr_t temp(rExc.Description());
      //temp = rExc.Description()
      //sMsg = temp.operator const wchar_t *();
      W2A(temp, sMsg.GetBuffer(256), 256);
      sMsg.ReleaseBuffer();
      //showCurrEvent(sMsg);
      AfxMessageBox(sMsg);

      if (sMsg.IsEmpty())
      {
         sMsg = &quot;Returned error code is empty..\n\nSomething goes wrong =(&quot;;	
      }

      AfxMessageBox(sMsg);
   }

   if (bstr != NULL)
   {
      SysFreeString(bstr);
   }
}
</code></pre>
<p>Ich bekomme immer am Anfang nach dem Aufruf der Methode m_IHello-&gt;getString(bstr); Eine MessageBox, wo halt &quot;--- nothing ---&quot; steht, also der Wert meines CStrings (m_Message vom ATL-Server)<br />
Dann wird der catch Block ausgeführt, wobei die oben gennante Fehlermeldung steht.</p>
<p>Was mache ich falsch?</p>
<p>P.S. Ich will bloss eine Methode auf dem Server haben, die mir den Wert eines CStrings zurückgibt und Möglichkeit, sie vom Client aufzurufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/75517/atl-com-_com_error-quot-unzulässiger-zugriff-auf-einen-speicherbereich-quot</link><generator>RSS for Node</generator><lastBuildDate>Sat, 25 Apr 2026 10:51:54 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/75517.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 01 Jun 2004 14:25:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ATL&#x2F;COM: _com_error: &amp;quot;Unzulässiger Zugriff auf einen Speicherbereich.&amp;quot; on Tue, 01 Jun 2004 14:25:58 GMT]]></title><description><![CDATA[<p>(VC++6, NT 4)</p>
<p>hallo,</p>
<p>ich habe einen Test ATL Server, und einen Test ATL Client.<br />
Atl-Server hat folgende Methode:</p>
<pre><code>// Interface:
[id(1), helpstring(&quot;Methode getString&quot;)] HRESULT getString([out, retval] BSTR str);
// Implementierung:
// Methode soll eine memeber (CString m_Message) zurück geben
// die im Konstruktor mit &quot;--- nothing ---&quot; initialisiert wird
STDMETHODIMP CHello::getString(BSTR str)
{
   AFX_MANAGE_STATE(AfxGetStaticModuleState())

   str = m_Message.AllocSysString();
   _bstr_t bstr(str, false);

   CString stemp2(_T(&quot;&quot;));
   W2A(bstr, stemp2.GetBuffer(256), 256);
   stemp2.ReleaseBuffer();
   stemp2.Format(stemp2, &quot;ATL_Server msg: %s&quot;, stemp2);
   AfxMessageBox(stemp2);

   return S_OK;
}
</code></pre>
<p>ATL-Client benutzt den Server so:</p>
<pre><code>void CATL_ClientDlg::OnButtonTest()
{
   BSTR bstr = NULL;
   CString stemp(_T(&quot;---------- an empty CString ----------&quot;));
   bstr = stemp.AllocSysString();

   try
   {  // rufe Methode des ATL-Serversauf:
      m_IHello-&gt;getString(bstr);

      CString stemp2(_T(&quot;&quot;));
      W2A(bstr, stemp2.GetBuffer(256), 256);
      stemp2.ReleaseBuffer();
      stemp2.Format(stemp2, &quot;ATL_Client msg: %s&quot;, stemp2);
      AfxMessageBox(stemp2);
      //m_Message = bsTemp.operator const wchar_t *();
      //showCurrEvent(m_Message);
   }
   catch(_com_error&amp; rExc)
   {
      CString sMsg;
      _bstr_t temp(rExc.Description());
      //temp = rExc.Description()
      //sMsg = temp.operator const wchar_t *();
      W2A(temp, sMsg.GetBuffer(256), 256);
      sMsg.ReleaseBuffer();
      //showCurrEvent(sMsg);
      AfxMessageBox(sMsg);

      if (sMsg.IsEmpty())
      {
         sMsg = &quot;Returned error code is empty..\n\nSomething goes wrong =(&quot;;	
      }

      AfxMessageBox(sMsg);
   }

   if (bstr != NULL)
   {
      SysFreeString(bstr);
   }
}
</code></pre>
<p>Ich bekomme immer am Anfang nach dem Aufruf der Methode m_IHello-&gt;getString(bstr); Eine MessageBox, wo halt &quot;--- nothing ---&quot; steht, also der Wert meines CStrings (m_Message vom ATL-Server)<br />
Dann wird der catch Block ausgeführt, wobei die oben gennante Fehlermeldung steht.</p>
<p>Was mache ich falsch?</p>
<p>P.S. Ich will bloss eine Methode auf dem Server haben, die mir den Wert eines CStrings zurückgibt und Möglichkeit, sie vom Client aufzurufen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/530984</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/530984</guid><dc:creator><![CDATA[lazydot]]></dc:creator><pubDate>Tue, 01 Jun 2004 14:25:58 GMT</pubDate></item><item><title><![CDATA[Reply to ATL&#x2F;COM: _com_error: &amp;quot;Unzulässiger Zugriff auf einen Speicherbereich.&amp;quot; on Wed, 02 Jun 2004 09:30:06 GMT]]></title><description><![CDATA[<p>Ich habe den Fehler gefunden. War eigentlich ziemlich bllöd.<br />
ich musste die Funktion meines Interfaces anders deklarieren:</p>
<pre><code>// ALT &amp; FALSCH
[id(1), helpstring(&quot;Methode getString&quot;)] HRESULT getString([out, retval] BSTR str)
// RICHTIG
[id(1), helpstring(&quot;Methode getString&quot;)] HRESULT getString([out, retval] BSTR *str)
//-----------------
// Beim COM-Client sollte muss dan die Funktion auch anders aufgerufen werden:
   ...   
   BSTR bstr = NULL;

   try
   {  // rufe Methode des ATL-Serversauf:
      bstr = m_IHello-&gt;getString();
      ...
</code></pre>
<p>Dann funktioniert der ganze Kramm auch <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title="=)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/531468</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/531468</guid><dc:creator><![CDATA[lazydot]]></dc:creator><pubDate>Wed, 02 Jun 2004 09:30:06 GMT</pubDate></item></channel></rss>