<?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[Klasse mit CALLVACK Funktion]]></title><description><![CDATA[<p>Guten MOrgen. Ich habe folgendes Problem :<br />
Ich habe eine Klasse von der ich eine Instanz erstelle. Ich möchte von einer anderen KLasse in bestimmte Zeitabständen zyklisch eine Funktion aufrufen. Das klappt auch schon ganz gut, ich habe diese Funktione als CALLBACK Funktion dekjlariert. Nun soll diese CALLBACK Funktion allerdings eine weitere Funktion der Klasse aufrufen. UNd gibt es bereits die ersten Probleme :</p>
<pre><code class="language-cpp">error C2352: 'UpdateAgent::ScanFolder' : illegal call of non-static member function
        f:\programmierung\filemanager\updateagent.h(27) : see declaration of 'ScanFolder'
</code></pre>
<p>Ich habe die Funktion ScanFolder als static deklariert und der Fehler ist verschwunden. Jedoch soll nun in der ScanFUnktion auf einen Zeiger zugegriffen werden, und da bekomme ich einen LInker Error :</p>
<pre><code class="language-cpp">unresolved external symbol &quot;private: static class DatabaseAgent * UpdateAgent::pDatabasAgent&quot; (?pDatabasAgent@UpdateAgent@@0PAVDatabaseAgent@@A)
Debug/FileManager.exe : fatal error LNK1120: 1 unresolved externals
</code></pre>
<p>So und hier mal der COde der kLAsse:</p>
<pre><code class="language-cpp">class UpdateAgent
{
public:
	UpdateAgent(DatabaseAgent *databasagent);
	~UpdateAgent();

	static void CALLBACK TestFunktion(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);

private:

	static void ScanFolder(string folder);
	static void WriteFileInformation(string filename);
	static string ConvertDwordToString(DWORD number);
	static string ConvertBoolToString(bool value);

	static DatabaseAgent *pDatabasAgent;
};

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

#endif
</code></pre>
<p>un die implemetiereung</p>
<pre><code class="language-cpp">void UpdateAgent::ScanFolder(string folder)
{
	WIN32_FIND_DATA FindFileData;
	HANDLE hFind; 

	// Erweitere den OrdnerNamen =&gt; Suchmaske üfr alle Dateien
	string SearchFolder = folder + &quot;\\*.*&quot;;

	// Suche die erste Datei.
	hFind = FindFirstFile(SearchFolder.c_str(),&amp;FindFileData);

	// Prüfe ob der DateiHandle gültig ist
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			// Wenn die Datei ein Ordner ist.
			if ( FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY  &amp;&amp; lstrcmp (FindFileData.cFileName, &quot;..&quot;) != 0 &amp;&amp; lstrcmp(FindFileData.cFileName,&quot;.&quot;) != 0 )
				 ScanFolder( folder + &quot;\\&quot; + FindFileData.cFileName );

			// Wenn die Datei nicht ein Ordner ist.
			if ( ! ( FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY ) )
			{

				WriteFileInformation(folder + &quot;\\&quot; + FindFileData.cFileName);	
			}

		}	while (FindNextFile(hFind,&amp;FindFileData));			
	}
	else
	{

	}

	FindClose(hFind); 
}

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

void UpdateAgent::WriteFileInformation(string filename)
{
		// Lese alle Datei - Informationen zur Datei

	WIN32_FIND_DATA FindFileData;
	HANDLE hFind; 

	// Sucht nach der Datei
	hFind = FindFirstFile(filename.c_str(),&amp;FindFileData);

	// Prüfe ob der DateiHandle gültig ist
	if (hFind != INVALID_HANDLE_VALUE)
	{
		// Entfernt alle überflüssigen Zeichen aus dem Dateinamen.
		//file = RemoveCharacterFromString(&quot;'&quot;,file);

		// Erzeugt das Datum 
		SYSTEMTIME  t_Creation, t_LastAccess, t_LastWriteTime;

		FileTimeToSystemTime(&amp;FindFileData.ftCreationTime,&amp;t_Creation);
		FileTimeToSystemTime(&amp;FindFileData.ftLastAccessTime,&amp;t_LastAccess);
		FileTimeToSystemTime(&amp;FindFileData.ftLastWriteTime,&amp;t_LastWriteTime);

		// Erzeugt den SQL - String
		string sql = &quot;INSERT INTO SearchResult (FileName,FileSize,FileType,CreationTime,LastAccessTime, LastWriteTime,FlieAttributeArchiv,FlieAttributeDirectory,FlieAttributeHidden,FlieAttributeReadOnly,FlieAttributeSystem, FileContent) VALUES &quot;;
		sql += &quot;('&quot;;
		sql += filename;
		sql += &quot;',&quot;;
		sql += ConvertDwordToString(FindFileData.nFileSizeLow);
		sql += &quot;,'&quot;;
		sql += filename.substr(filename.find_last_of(&quot;.&quot;) + 1);
		sql += &quot;','&quot;;
		sql += ConvertDwordToString(t_Creation.wDay);
		sql += &quot;.&quot;;
		sql += ConvertDwordToString(t_Creation.wMonth);
		sql += &quot;.&quot;;
		sql += ConvertDwordToString(t_Creation.wYear);
		sql += &quot; &quot;;
		sql += ConvertDwordToString(t_Creation.wHour);
		sql += &quot;:&quot;;
		sql += ConvertDwordToString(t_Creation.wMinute);
		sql += &quot;:&quot;;
		sql += ConvertDwordToString(t_Creation.wSecond);
		sql += &quot;','&quot;;
		sql += ConvertDwordToString(t_LastAccess.wDay);
		sql += &quot;.&quot;;
		sql += ConvertDwordToString(t_LastAccess.wMonth);
		sql += &quot;.&quot;;
		sql += ConvertDwordToString(t_LastAccess.wYear);
		sql += &quot; &quot;;
		sql += ConvertDwordToString(t_LastAccess.wHour);
		sql += &quot;:&quot;;
		sql += ConvertDwordToString(t_LastAccess.wMinute);
		sql += &quot;:&quot;;
		sql += ConvertDwordToString(t_LastAccess.wSecond);
		sql += &quot;','&quot;;
		sql += ConvertDwordToString(t_LastWriteTime.wDay);
		sql += &quot;.&quot;;
		sql += ConvertDwordToString(t_LastWriteTime.wMonth);
		sql += &quot;.&quot;;
		sql += ConvertDwordToString(t_LastWriteTime.wYear);
		sql += &quot; &quot;;
		sql += ConvertDwordToString(t_LastWriteTime.wHour);
		sql += &quot;:&quot;;
		sql += ConvertDwordToString(t_LastWriteTime.wMinute);
		sql += &quot;:&quot;;
		sql += ConvertDwordToString(t_LastWriteTime.wSecond);
		sql += &quot;',&quot;;
		sql += ConvertBoolToString(FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_ARCHIVE);
		sql += &quot;,&quot;;
		sql += ConvertBoolToString(FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY);
		sql += &quot;,&quot;;
		sql += ConvertBoolToString(FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_HIDDEN);
		sql += &quot;,&quot;;
		sql += ConvertBoolToString(FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_READONLY);
		sql += &quot;,&quot;;
		sql += ConvertBoolToString(FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_SYSTEM);
		sql += &quot;,'&quot;;

		pDatabasAgent-&gt;ExcecuteSQLCommand(sql);

		FindClose(hFind); 
	}	
}

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

string UpdateAgent::ConvertDwordToString(DWORD number)
{
	// Wandelt eine DWORD - Variable in einen String um.

	char buffer[10];
	return ultoa(number,buffer,10);
}

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

string UpdateAgent::ConvertBoolToString(bool value)
{
	// Wandelt eine BOOL - Variable in einen String um.

	if (value)
		return &quot;true&quot;;
	return &quot;false&quot;;
}

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

void CALLBACK UpdateAgent::TestFunktion(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
	 ScanFolder(&quot;D:&quot;);

	cout &lt;&lt; &quot;Test\n&quot;;

}

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
</code></pre>
<p>Kann mir da jemand helfen . Eine erklärung bezüglich der CALLBACk und static funktionen wäre schön. Vielen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/248449/klasse-mit-callvack-funktion</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 23:46:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/248449.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 25 Aug 2009 08:07:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Klasse mit CALLVACK Funktion on Tue, 25 Aug 2009 08:07:11 GMT]]></title><description><![CDATA[<p>Guten MOrgen. Ich habe folgendes Problem :<br />
Ich habe eine Klasse von der ich eine Instanz erstelle. Ich möchte von einer anderen KLasse in bestimmte Zeitabständen zyklisch eine Funktion aufrufen. Das klappt auch schon ganz gut, ich habe diese Funktione als CALLBACK Funktion dekjlariert. Nun soll diese CALLBACK Funktion allerdings eine weitere Funktion der Klasse aufrufen. UNd gibt es bereits die ersten Probleme :</p>
<pre><code class="language-cpp">error C2352: 'UpdateAgent::ScanFolder' : illegal call of non-static member function
        f:\programmierung\filemanager\updateagent.h(27) : see declaration of 'ScanFolder'
</code></pre>
<p>Ich habe die Funktion ScanFolder als static deklariert und der Fehler ist verschwunden. Jedoch soll nun in der ScanFUnktion auf einen Zeiger zugegriffen werden, und da bekomme ich einen LInker Error :</p>
<pre><code class="language-cpp">unresolved external symbol &quot;private: static class DatabaseAgent * UpdateAgent::pDatabasAgent&quot; (?pDatabasAgent@UpdateAgent@@0PAVDatabaseAgent@@A)
Debug/FileManager.exe : fatal error LNK1120: 1 unresolved externals
</code></pre>
<p>So und hier mal der COde der kLAsse:</p>
<pre><code class="language-cpp">class UpdateAgent
{
public:
	UpdateAgent(DatabaseAgent *databasagent);
	~UpdateAgent();

	static void CALLBACK TestFunktion(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2);

private:

	static void ScanFolder(string folder);
	static void WriteFileInformation(string filename);
	static string ConvertDwordToString(DWORD number);
	static string ConvertBoolToString(bool value);

	static DatabaseAgent *pDatabasAgent;
};

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

#endif
</code></pre>
<p>un die implemetiereung</p>
<pre><code class="language-cpp">void UpdateAgent::ScanFolder(string folder)
{
	WIN32_FIND_DATA FindFileData;
	HANDLE hFind; 

	// Erweitere den OrdnerNamen =&gt; Suchmaske üfr alle Dateien
	string SearchFolder = folder + &quot;\\*.*&quot;;

	// Suche die erste Datei.
	hFind = FindFirstFile(SearchFolder.c_str(),&amp;FindFileData);

	// Prüfe ob der DateiHandle gültig ist
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			// Wenn die Datei ein Ordner ist.
			if ( FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY  &amp;&amp; lstrcmp (FindFileData.cFileName, &quot;..&quot;) != 0 &amp;&amp; lstrcmp(FindFileData.cFileName,&quot;.&quot;) != 0 )
				 ScanFolder( folder + &quot;\\&quot; + FindFileData.cFileName );

			// Wenn die Datei nicht ein Ordner ist.
			if ( ! ( FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY ) )
			{

				WriteFileInformation(folder + &quot;\\&quot; + FindFileData.cFileName);	
			}

		}	while (FindNextFile(hFind,&amp;FindFileData));			
	}
	else
	{

	}

	FindClose(hFind); 
}

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

void UpdateAgent::WriteFileInformation(string filename)
{
		// Lese alle Datei - Informationen zur Datei

	WIN32_FIND_DATA FindFileData;
	HANDLE hFind; 

	// Sucht nach der Datei
	hFind = FindFirstFile(filename.c_str(),&amp;FindFileData);

	// Prüfe ob der DateiHandle gültig ist
	if (hFind != INVALID_HANDLE_VALUE)
	{
		// Entfernt alle überflüssigen Zeichen aus dem Dateinamen.
		//file = RemoveCharacterFromString(&quot;'&quot;,file);

		// Erzeugt das Datum 
		SYSTEMTIME  t_Creation, t_LastAccess, t_LastWriteTime;

		FileTimeToSystemTime(&amp;FindFileData.ftCreationTime,&amp;t_Creation);
		FileTimeToSystemTime(&amp;FindFileData.ftLastAccessTime,&amp;t_LastAccess);
		FileTimeToSystemTime(&amp;FindFileData.ftLastWriteTime,&amp;t_LastWriteTime);

		// Erzeugt den SQL - String
		string sql = &quot;INSERT INTO SearchResult (FileName,FileSize,FileType,CreationTime,LastAccessTime, LastWriteTime,FlieAttributeArchiv,FlieAttributeDirectory,FlieAttributeHidden,FlieAttributeReadOnly,FlieAttributeSystem, FileContent) VALUES &quot;;
		sql += &quot;('&quot;;
		sql += filename;
		sql += &quot;',&quot;;
		sql += ConvertDwordToString(FindFileData.nFileSizeLow);
		sql += &quot;,'&quot;;
		sql += filename.substr(filename.find_last_of(&quot;.&quot;) + 1);
		sql += &quot;','&quot;;
		sql += ConvertDwordToString(t_Creation.wDay);
		sql += &quot;.&quot;;
		sql += ConvertDwordToString(t_Creation.wMonth);
		sql += &quot;.&quot;;
		sql += ConvertDwordToString(t_Creation.wYear);
		sql += &quot; &quot;;
		sql += ConvertDwordToString(t_Creation.wHour);
		sql += &quot;:&quot;;
		sql += ConvertDwordToString(t_Creation.wMinute);
		sql += &quot;:&quot;;
		sql += ConvertDwordToString(t_Creation.wSecond);
		sql += &quot;','&quot;;
		sql += ConvertDwordToString(t_LastAccess.wDay);
		sql += &quot;.&quot;;
		sql += ConvertDwordToString(t_LastAccess.wMonth);
		sql += &quot;.&quot;;
		sql += ConvertDwordToString(t_LastAccess.wYear);
		sql += &quot; &quot;;
		sql += ConvertDwordToString(t_LastAccess.wHour);
		sql += &quot;:&quot;;
		sql += ConvertDwordToString(t_LastAccess.wMinute);
		sql += &quot;:&quot;;
		sql += ConvertDwordToString(t_LastAccess.wSecond);
		sql += &quot;','&quot;;
		sql += ConvertDwordToString(t_LastWriteTime.wDay);
		sql += &quot;.&quot;;
		sql += ConvertDwordToString(t_LastWriteTime.wMonth);
		sql += &quot;.&quot;;
		sql += ConvertDwordToString(t_LastWriteTime.wYear);
		sql += &quot; &quot;;
		sql += ConvertDwordToString(t_LastWriteTime.wHour);
		sql += &quot;:&quot;;
		sql += ConvertDwordToString(t_LastWriteTime.wMinute);
		sql += &quot;:&quot;;
		sql += ConvertDwordToString(t_LastWriteTime.wSecond);
		sql += &quot;',&quot;;
		sql += ConvertBoolToString(FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_ARCHIVE);
		sql += &quot;,&quot;;
		sql += ConvertBoolToString(FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY);
		sql += &quot;,&quot;;
		sql += ConvertBoolToString(FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_HIDDEN);
		sql += &quot;,&quot;;
		sql += ConvertBoolToString(FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_READONLY);
		sql += &quot;,&quot;;
		sql += ConvertBoolToString(FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_SYSTEM);
		sql += &quot;,'&quot;;

		pDatabasAgent-&gt;ExcecuteSQLCommand(sql);

		FindClose(hFind); 
	}	
}

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

string UpdateAgent::ConvertDwordToString(DWORD number)
{
	// Wandelt eine DWORD - Variable in einen String um.

	char buffer[10];
	return ultoa(number,buffer,10);
}

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

string UpdateAgent::ConvertBoolToString(bool value)
{
	// Wandelt eine BOOL - Variable in einen String um.

	if (value)
		return &quot;true&quot;;
	return &quot;false&quot;;
}

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

void CALLBACK UpdateAgent::TestFunktion(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
	 ScanFolder(&quot;D:&quot;);

	cout &lt;&lt; &quot;Test\n&quot;;

}

// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
</code></pre>
<p>Kann mir da jemand helfen . Eine erklärung bezüglich der CALLBACk und static funktionen wäre schön. Vielen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1766209</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1766209</guid><dc:creator><![CDATA[dercooleauswandere]]></dc:creator><pubDate>Tue, 25 Aug 2009 08:07:11 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse mit CALLVACK Funktion on Tue, 25 Aug 2009 08:23:32 GMT]]></title><description><![CDATA[<p>Das ist eine Falle, in die man durch die strikte Trennung von Deklaration und Definition in C++ tritt.<br />
Du brauchst einfach noch eine Definition für die static-Variable. In die cpp-Datei folgendes eintragen:</p>
<pre><code class="language-cpp">DatabaseAgent* DatabaseAgent::pDatabasAgent;
</code></pre>
<p>Die Callbackfunktion muss statisch sein, weil sie keinen this-Pointer vom Aufrufer erhält.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1766215</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1766215</guid><dc:creator><![CDATA[Registrierter Troll]]></dc:creator><pubDate>Tue, 25 Aug 2009 08:23:32 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse mit CALLVACK Funktion on Tue, 25 Aug 2009 08:29:41 GMT]]></title><description><![CDATA[<p>Danke für deine Antwort ich werde es gleich ausprobiere</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1766219</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1766219</guid><dc:creator><![CDATA[dercooleauswandere]]></dc:creator><pubDate>Tue, 25 Aug 2009 08:29:41 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse mit CALLVACK Funktion on Tue, 25 Aug 2009 08:32:05 GMT]]></title><description><![CDATA[<p>Danke es hat geklappt. Aber warum das habe cih noch nicht verstanden. Ich habe doch im KOnstruktor einen Zeiger auf das DatbasAGent Objekt mitgegeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1766222</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1766222</guid><dc:creator><![CDATA[dercooleauswandere]]></dc:creator><pubDate>Tue, 25 Aug 2009 08:32:05 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse mit CALLVACK Funktion on Tue, 25 Aug 2009 09:27:41 GMT]]></title><description><![CDATA[<p>Ja, aber beim Augruf einer statischen Methode wird wohl kaum der Konstruktor der Klasse aufgerufen, stimmt's? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1766266</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1766266</guid><dc:creator><![CDATA[Ad aCTa]]></dc:creator><pubDate>Tue, 25 Aug 2009 09:27:41 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse mit CALLVACK Funktion on Tue, 25 Aug 2009 18:15:30 GMT]]></title><description><![CDATA[<p>Nein das stimmt aber so habe ich das auch nicht gemeint. Wenn ich ein Objekt dieser KLasse Erzuege rufe ich doch den Konstrutor auf. Und dem gebe ich einen Zeiger mit. So und nun die Frage warum ich den nicht so einfach verwenden kann ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1766600</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1766600</guid><dc:creator><![CDATA[dercooleauswandere]]></dc:creator><pubDate>Tue, 25 Aug 2009 18:15:30 GMT</pubDate></item><item><title><![CDATA[Reply to Klasse mit CALLVACK Funktion on Wed, 26 Aug 2009 05:25:19 GMT]]></title><description><![CDATA[<p>Du kannst den übergebenen Zeiger benutzen. Du machst aber eine Kopie davon, die du in <code>pDatabasAgent</code> aufbewahren möchtest. Für diese statische Variable muss Speicherplatz zur Verfügung stehen. Die reine Deklaration wie bei nicht-statischen Membern reicht dazu blöderweise nicht, man muss den Compiler explizit anweisen, die Variable zu instanzieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1766777</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1766777</guid><dc:creator><![CDATA[Registrierter Troll]]></dc:creator><pubDate>Wed, 26 Aug 2009 05:25:19 GMT</pubDate></item></channel></rss>