<?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[Methode eines Objekts als Callbackroutine]]></title><description><![CDATA[<p>Moin.</p>
<p>Ich verwende in einem Projekt dnm Multimedia Timer. Um diesen zu starten verwende ich die Funktion timeSetEvent.</p>
<p>Diese brauch als Parameter eine Zeiger auf eine Callbackfunktion:</p>
<blockquote>
<p>[in] Pointer to a callback function that is called once on expiration of a single event or periodically on expiration of periodic events.</p>
</blockquote>
<p>Ich kann einen Zeiger auf eine static Methode eines Objects übergeben und alles funktioniert.</p>
<p>Da ich in dieser Methode auf Felder und andere Methoden sowohl von diesem als auch von anderen Objekten zugreife, müssen all diese auch static sein/werden.</p>
<p>Da mir das nicht gefällt habe ich mich gefragt, ob es eine Möglichkeit gibt, eine 'normale' nicht static Medthode als Callbackfunktion zu verwenden?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/275012/methode-eines-objekts-als-callbackroutine</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 00:24:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/275012.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 07 Oct 2010 08:10:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Methode eines Objekts als Callbackroutine on Thu, 07 Oct 2010 08:10:12 GMT]]></title><description><![CDATA[<p>Moin.</p>
<p>Ich verwende in einem Projekt dnm Multimedia Timer. Um diesen zu starten verwende ich die Funktion timeSetEvent.</p>
<p>Diese brauch als Parameter eine Zeiger auf eine Callbackfunktion:</p>
<blockquote>
<p>[in] Pointer to a callback function that is called once on expiration of a single event or periodically on expiration of periodic events.</p>
</blockquote>
<p>Ich kann einen Zeiger auf eine static Methode eines Objects übergeben und alles funktioniert.</p>
<p>Da ich in dieser Methode auf Felder und andere Methoden sowohl von diesem als auch von anderen Objekten zugreife, müssen all diese auch static sein/werden.</p>
<p>Da mir das nicht gefällt habe ich mich gefragt, ob es eine Möglichkeit gibt, eine 'normale' nicht static Medthode als Callbackfunktion zu verwenden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1962422</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1962422</guid><dc:creator><![CDATA[ViktorII]]></dc:creator><pubDate>Thu, 07 Oct 2010 08:10:12 GMT</pubDate></item><item><title><![CDATA[Reply to Methode eines Objekts als Callbackroutine on Thu, 07 Oct 2010 08:14:45 GMT]]></title><description><![CDATA[<p>Du musst eine Globale oder statische (ist vorzuziehen) Funktion als Callback verwenden.</p>
<p>Übergibt als dwUser Parameter einfach ein Zeiger auf die aufrufende Klasse, welche dir dann im Callback wieder zur Verfügung steht.</p>
<p>Hier noch die Doku:<br />
<a href="http://msdn.microsoft.com/en-us/library/aa448195.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa448195.aspx</a></p>
<p>Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1962425</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1962425</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Thu, 07 Oct 2010 08:14:45 GMT</pubDate></item><item><title><![CDATA[Reply to Methode eines Objekts als Callbackroutine on Tue, 12 Oct 2010 09:02:03 GMT]]></title><description><![CDATA[<p>Okay, so kann ich zumindest auf die Methoden meiner Klasse zugreifen.</p>
<p>Wenn ich allerdings in solch einer Methode dann auf eine nicht statische Variable meines Objekts zugreife, bekomme ich eine Zugriffsverletztung:</p>
<pre><code>....
....
private:
	int m_MyInt;
    static void CALLBACK TimerExpired(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);
	void testFkt();

....
....

void CmmTimer01Dlg::OnBnClickedButton1()
{
	MMRESULT Res;
	TIMECAPS tc;
	static int	wTimerID;

	//--- Maximale Timerauflösung abfragen (WinCE 6 -&gt; 1ms)
	Res = timeGetDevCaps(&amp;tc, sizeof(TIMECAPS));

	//--- Timer auf maximale Auflösung stellen
	if(Res == TIMERR_NOERROR)
		Res = timeBeginPeriod(tc.wPeriodMin);

	if(Res == TIMERR_NOERROR)
	{
		wTimerID = timeSetEvent(250,                                         // uDelay
								0,                                          // uResolution
								TimerExpired,                        // lpTimeProc
								(DWORD)this,                                // dwUser
								TIME_CALLBACK_FUNCTION | TIME_ONESHOT      // fuEvent
								);

		if(wTimerID != NULL)
			Res = TIMERR_NOERROR;
    }

	if(Res != TIMERR_NOERROR)
		TRACE(&quot;Error\n&quot;);
}

void CALLBACK CmmTimer01Dlg::TimerExpired(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
    TRACE(&quot;TimerExpired\n&quot;);

	((CmmTimer01Dlg *)dwUser)-&gt;testFkt();
}

void CmmTimer01Dlg::testFkt()
{
	TRACE(&quot;testFkt #1\n&quot;);
	m_MyInt = 0;
	TRACE(&quot;testFkt #2\n&quot;);
}
</code></pre>
<blockquote>
<p>Unbehandelte Ausnahme bei 0x0041306d in mmTimer01.exe: 0xC0000005: Zugriffsverletzung beim Schreiben an Position 0x00000078.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1964222</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1964222</guid><dc:creator><![CDATA[ViktorII]]></dc:creator><pubDate>Tue, 12 Oct 2010 09:02:03 GMT</pubDate></item><item><title><![CDATA[Reply to Methode eines Objekts als Callbackroutine on Thu, 14 Oct 2010 11:48:14 GMT]]></title><description><![CDATA[<p>*push*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1965506</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1965506</guid><dc:creator><![CDATA[ViktorII]]></dc:creator><pubDate>Thu, 14 Oct 2010 11:48:14 GMT</pubDate></item><item><title><![CDATA[Reply to Methode eines Objekts als Callbackroutine on Thu, 14 Oct 2010 12:01:35 GMT]]></title><description><![CDATA[<p>Wo und wie wird der Dialog instanziert?<br />
Lebt er genug lange? (Mindestens solange, bis der Timer abgelaufen ist?)</p>
<p>Simon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1965520</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1965520</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Thu, 14 Oct 2010 12:01:35 GMT</pubDate></item><item><title><![CDATA[Reply to Methode eines Objekts als Callbackroutine on Thu, 14 Oct 2010 13:00:41 GMT]]></title><description><![CDATA[<p>Der Dialog lebt die ganze Zeit.</p>
<p>Ich habe um das Problem zu isolieren eine 'Minimalprojekt' erstellt. Dabei habe ich beim Schritt Anwendungstyp des MFC-Anwendungs-Assistenten 'Auf Dialogfeldern basierend' gewählt.</p>
<p>Der Dialog ist also quasi das Hauptfenster.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1965552</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1965552</guid><dc:creator><![CDATA[ViktorII]]></dc:creator><pubDate>Thu, 14 Oct 2010 13:00:41 GMT</pubDate></item><item><title><![CDATA[Reply to Methode eines Objekts als Callbackroutine on Thu, 14 Oct 2010 14:13:55 GMT]]></title><description><![CDATA[<p>Hier mal ein minimal Bsp.<br />
Ev. hilfts Dir ja beim Fehler finden.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;stdexcept&gt;

#include &lt;windows.h&gt;

#pragma comment (lib, &quot;Winmm.lib&quot;)

class Test
{
public:
    Test(UINT delay, UINT resolution)
        : timerId_(NULL)
    {
        timerId_ = timeSetEvent(delay, resolution, &amp;Test::onTimeout, reinterpret_cast&lt;DWORD_PTR&gt;(this), TIME_ONESHOT | TIME_CALLBACK_FUNCTION);

        if (timerId_ == NULL)
        {
            throw std::runtime_error(&quot;Could not acquire timer&quot;);
        }
    }

    ~Test()
    {
        timeKillEvent(timerId_);
    }

private:
    static void CALLBACK onTimeout(UINT /*uTimerID*/, UINT /*uMsg*/, DWORD_PTR dwUser, DWORD_PTR /*dw1*/, DWORD_PTR /*dw2*/)
    {
        Test* object = reinterpret_cast&lt;Test*&gt;(dwUser);

        object-&gt;onTimeout();
    }

    void onTimeout()
    {
        std::cout &lt;&lt; &quot;Test::onTimeout&quot; &lt;&lt; std::endl;
    }

private:
    MMRESULT timerId_;
};

int _tmain(int /*argc*/, _TCHAR* /*argv*/[])
{
    Test test(2000, 0);

    std::cin.clear();
    std::cin.ignore(std::cin.rdbuf()-&gt;in_avail());
    std::cin.get();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1965609</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1965609</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Thu, 14 Oct 2010 14:13:55 GMT</pubDate></item></channel></rss>