<?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[Problem &amp;quot;klassenübergreifend&amp;quot; auf Variablen zuzugeifen]]></title><description><![CDATA[<p>hallo, ich wollte aus der klasse</p>
<blockquote>
<p>CPicToLightView</p>
</blockquote>
<p>auf Variablen in der Klasse</p>
<blockquote>
<p>CPicToLightApp</p>
</blockquote>
<p>zugreifen.<br />
Dazu habe ich erst einmal folgendes gemacht:</p>
<pre><code>void CPicToLightView::OnBnClickedBtninithardw()
{
    CANResult Res;
    CString strIO, strInterrupt, strTemp;

    CPicToLightApp* pApp = dynamic_cast&lt;CPicToLightApp*&gt;(AfxGetApp());
    ASSERT(pApp); ....
</code></pre>
<p>Dabei bleibt das Programm aber stehen, an folgender Stelle:</p>
<pre><code>_CRTIMP void * __cdecl malloc (
        size_t nSize
        )
{
 --&gt;       void *res = _nh_malloc_dbg(nSize, _newmode, _NORMAL_BLOCK, NULL, 0);

        RTCCALLBACK(_RTC_Allocate_hook, (res, nSize, 0));

        return res;
}
</code></pre>
<p>Habe das doch so gemacht, wie es hier steht:</p>
<blockquote>
<p><strong>2 C...App</strong></p>
<p>An die C...App kommt man von JEDER Klasse der Anwendung aus mit</p>
<pre><code>AfxGetApp();
</code></pre>
<p>Da das aber noch nicht den richtigen Typ hat, muss gecastet werden. Ich nutze dynamic_cast, weil dieser am sichersten ist (RTTI muss eingeschaltet sein).<br />
Ein einfacher C-Cast funktioniert meistens auch - wenn er aber mal nicht funktioniert, wird es problematisch.</p>
<pre><code>C...App* pApp = dynamic_cast&lt;C...App*&gt;(AfxGetApp());
ASSERT(pApp); // zur Sicherheit
</code></pre>
</blockquote>
<p>Wäre toll, wenn mir jemand mal einen schubs geben und sagen könne, was ich da falsch mache.</p>
<p>Vielen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/148871/problem-quot-klassenübergreifend-quot-auf-variablen-zuzugeifen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Jul 2026 13:05:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/148871.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 31 May 2006 11:20:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem &amp;quot;klassenübergreifend&amp;quot; auf Variablen zuzugeifen on Wed, 31 May 2006 11:20:45 GMT]]></title><description><![CDATA[<p>hallo, ich wollte aus der klasse</p>
<blockquote>
<p>CPicToLightView</p>
</blockquote>
<p>auf Variablen in der Klasse</p>
<blockquote>
<p>CPicToLightApp</p>
</blockquote>
<p>zugreifen.<br />
Dazu habe ich erst einmal folgendes gemacht:</p>
<pre><code>void CPicToLightView::OnBnClickedBtninithardw()
{
    CANResult Res;
    CString strIO, strInterrupt, strTemp;

    CPicToLightApp* pApp = dynamic_cast&lt;CPicToLightApp*&gt;(AfxGetApp());
    ASSERT(pApp); ....
</code></pre>
<p>Dabei bleibt das Programm aber stehen, an folgender Stelle:</p>
<pre><code>_CRTIMP void * __cdecl malloc (
        size_t nSize
        )
{
 --&gt;       void *res = _nh_malloc_dbg(nSize, _newmode, _NORMAL_BLOCK, NULL, 0);

        RTCCALLBACK(_RTC_Allocate_hook, (res, nSize, 0));

        return res;
}
</code></pre>
<p>Habe das doch so gemacht, wie es hier steht:</p>
<blockquote>
<p><strong>2 C...App</strong></p>
<p>An die C...App kommt man von JEDER Klasse der Anwendung aus mit</p>
<pre><code>AfxGetApp();
</code></pre>
<p>Da das aber noch nicht den richtigen Typ hat, muss gecastet werden. Ich nutze dynamic_cast, weil dieser am sichersten ist (RTTI muss eingeschaltet sein).<br />
Ein einfacher C-Cast funktioniert meistens auch - wenn er aber mal nicht funktioniert, wird es problematisch.</p>
<pre><code>C...App* pApp = dynamic_cast&lt;C...App*&gt;(AfxGetApp());
ASSERT(pApp); // zur Sicherheit
</code></pre>
</blockquote>
<p>Wäre toll, wenn mir jemand mal einen schubs geben und sagen könne, was ich da falsch mache.</p>
<p>Vielen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1068693</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1068693</guid><dc:creator><![CDATA[ABeginner]]></dc:creator><pubDate>Wed, 31 May 2006 11:20:45 GMT</pubDate></item><item><title><![CDATA[Reply to Problem &amp;quot;klassenübergreifend&amp;quot; auf Variablen zuzugeifen on Wed, 31 May 2006 11:47:57 GMT]]></title><description><![CDATA[<p>mit folgendem funktionierts</p>
<pre><code>CPicToLightApp* pApp= STATIC_DOWNCAST(CPicToLightApp,AfxGetApp());
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1068722</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1068722</guid><dc:creator><![CDATA[ABeginner]]></dc:creator><pubDate>Wed, 31 May 2006 11:47:57 GMT</pubDate></item></channel></rss>