<?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[DLL einbinden]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe eine eigene DLL mit 2 Funktionen und einer Variablen geschrieben:</p>
<pre><code class="language-cpp">DLL_EXPORT int iDllVar=2; //exportierte Variable
DLL_EXPORT int DllFuncPlus(int i) { //exportierte Funktion.
	char buf[256]; 
	int j = i+iDllVar;
	wsprintf( buf, &quot;i+iDllVar=%d&quot;, j );
	MessageBox(0,buf,TEXT(&quot;Ergebnis&quot;),MB_OK);
	return j;
}

DLL_EXPORT int DllFuncMinus(int i) { //exportierte Funktion.
	char buf[256]; 
	int j = i-iDllVar;
	wsprintf( buf, &quot;i-iDllVar=%d&quot;, j );
	MessageBox(0,buf,TEXT(&quot;Ergebnis&quot;),MB_OK);
	return j;
}
</code></pre>
<p>Die passende Header-Datei liegt natürlich auch vor.</p>
<p>Wenn ich die DLL implizit einbinde, also über eine Projektabhängigkeit zwischen DLL und Applikation und einer .lib-Bibliotheksdatei, funktioniert auch alles ohne Probleme. Jetzt möchte ich aber auch eine explizite Einbindung testen.</p>
<p>Auszug aus der Window-Prozedur der Applikation:</p>
<pre><code class="language-cpp">LRESULT CALLBACK WndProc(HWND hWnd, UINT uiMessage, WPARAM wParam, LPARAM lParam) {

	static HWND hwndButtonPlus;
	static HWND hwndButtonMinus;
	typedef int ( * DLLFUNC) (int);
	HINSTANCE hLib;

	switch (uiMessage) 
	{
	case WM_CREATE:

		hwndButtonPlus=CreateWindow (TEXT(&quot;button&quot;), TEXT(&quot;Addieren&quot;), 
			WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 10, 10, 150, 30, hWnd, 
			(HMENU)ID_BTN_PLUS, ((LPCREATESTRUCT) lParam)-&gt;hInstance , NULL);
		hwndButtonMinus=CreateWindow (TEXT(&quot;button&quot;), TEXT(&quot;Subtrahieren&quot;), 
			WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 10, 50, 150, 30, hWnd, 
			(HMENU)ID_BTN_MINUS, ((LPCREATESTRUCT) lParam)-&gt;hInstance , NULL);

		return 0;

	case WM_COMMAND:
            switch(LOWORD(wParam))
            {

				case ID_BTN_PLUS:
					if (HIWORD(wParam)==BN_CLICKED) {

						DLLFUNC DllFuncPlus; 
						hLib = GetModuleHandle(&quot;DLLTest.dll&quot;);
						if ( hLib == NULL ) hLib = LoadLibrary(&quot;DLLTest.dll&quot;); // Load the DLL now

						DllFuncPlus = (DLLFUNC) GetProcAddress( hLib, TEXT(&quot;DllFuncPlus&quot;));
						if ( DllFuncPlus != NULL) int i= ((DllFuncPlus)(2));

						FreeLibrary(hLib); // Unload DLL from memory
					} return 0;

				case ID_BTN_MINUS:
					if (HIWORD(wParam)==BN_CLICKED) {

						DLLFUNC DllFuncMinus; 
						hLib = GetModuleHandle(&quot;DLLTest.dll&quot;);
						if ( hLib == NULL ) hLib = LoadLibrary(&quot;DLLTest.dll&quot;); // Load the DLL now

						DllFuncMinus = (DLLFUNC) GetProcAddress( hLib, MAKEINTRESOURCE(2));
						if ( DllFuncMinus != NULL) int i= ((DllFuncMinus)(2));

						FreeLibrary(hLib); // Unload DLL from memory

					} return 0;

			} return 0;
</code></pre>
<p>Das kompiliert er auch erstmal soweit.</p>
<p>Wenn ich aber die .def Datei einbinde, kommt die Meldung</p>
<p>dll.def : error LNK2001: unresolved external symbol DllFuncMinus<br />
dll.def : error LNK2001: unresolved external symbol DllFuncPlus</p>
<p>beim Linken.</p>
<p>Hier der simple Inhalt der .def-Datei:</p>
<pre><code class="language-cpp">LIBRARY DLLTest

EXPORTS
	DllFuncPlus @1
	DllFuncMinus @2
</code></pre>
<p>Habe einfach eine TXT-Datei angelegt und der dann eben den Namen dll.def gegeben, dann unter Source Files des Applikationsprojektes im VisualC++ 6 eingefügt.</p>
<p>Wo ist der Fehler?</p>
<p>Gruß</p>
<p>seventh_son</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/132766/dll-einbinden</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Jul 2026 06:21:18 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/132766.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 12 Jan 2006 20:55:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to DLL einbinden on Thu, 12 Jan 2006 21:01:23 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe eine eigene DLL mit 2 Funktionen und einer Variablen geschrieben:</p>
<pre><code class="language-cpp">DLL_EXPORT int iDllVar=2; //exportierte Variable
DLL_EXPORT int DllFuncPlus(int i) { //exportierte Funktion.
	char buf[256]; 
	int j = i+iDllVar;
	wsprintf( buf, &quot;i+iDllVar=%d&quot;, j );
	MessageBox(0,buf,TEXT(&quot;Ergebnis&quot;),MB_OK);
	return j;
}

DLL_EXPORT int DllFuncMinus(int i) { //exportierte Funktion.
	char buf[256]; 
	int j = i-iDllVar;
	wsprintf( buf, &quot;i-iDllVar=%d&quot;, j );
	MessageBox(0,buf,TEXT(&quot;Ergebnis&quot;),MB_OK);
	return j;
}
</code></pre>
<p>Die passende Header-Datei liegt natürlich auch vor.</p>
<p>Wenn ich die DLL implizit einbinde, also über eine Projektabhängigkeit zwischen DLL und Applikation und einer .lib-Bibliotheksdatei, funktioniert auch alles ohne Probleme. Jetzt möchte ich aber auch eine explizite Einbindung testen.</p>
<p>Auszug aus der Window-Prozedur der Applikation:</p>
<pre><code class="language-cpp">LRESULT CALLBACK WndProc(HWND hWnd, UINT uiMessage, WPARAM wParam, LPARAM lParam) {

	static HWND hwndButtonPlus;
	static HWND hwndButtonMinus;
	typedef int ( * DLLFUNC) (int);
	HINSTANCE hLib;

	switch (uiMessage) 
	{
	case WM_CREATE:

		hwndButtonPlus=CreateWindow (TEXT(&quot;button&quot;), TEXT(&quot;Addieren&quot;), 
			WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 10, 10, 150, 30, hWnd, 
			(HMENU)ID_BTN_PLUS, ((LPCREATESTRUCT) lParam)-&gt;hInstance , NULL);
		hwndButtonMinus=CreateWindow (TEXT(&quot;button&quot;), TEXT(&quot;Subtrahieren&quot;), 
			WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 10, 50, 150, 30, hWnd, 
			(HMENU)ID_BTN_MINUS, ((LPCREATESTRUCT) lParam)-&gt;hInstance , NULL);

		return 0;

	case WM_COMMAND:
            switch(LOWORD(wParam))
            {

				case ID_BTN_PLUS:
					if (HIWORD(wParam)==BN_CLICKED) {

						DLLFUNC DllFuncPlus; 
						hLib = GetModuleHandle(&quot;DLLTest.dll&quot;);
						if ( hLib == NULL ) hLib = LoadLibrary(&quot;DLLTest.dll&quot;); // Load the DLL now

						DllFuncPlus = (DLLFUNC) GetProcAddress( hLib, TEXT(&quot;DllFuncPlus&quot;));
						if ( DllFuncPlus != NULL) int i= ((DllFuncPlus)(2));

						FreeLibrary(hLib); // Unload DLL from memory
					} return 0;

				case ID_BTN_MINUS:
					if (HIWORD(wParam)==BN_CLICKED) {

						DLLFUNC DllFuncMinus; 
						hLib = GetModuleHandle(&quot;DLLTest.dll&quot;);
						if ( hLib == NULL ) hLib = LoadLibrary(&quot;DLLTest.dll&quot;); // Load the DLL now

						DllFuncMinus = (DLLFUNC) GetProcAddress( hLib, MAKEINTRESOURCE(2));
						if ( DllFuncMinus != NULL) int i= ((DllFuncMinus)(2));

						FreeLibrary(hLib); // Unload DLL from memory

					} return 0;

			} return 0;
</code></pre>
<p>Das kompiliert er auch erstmal soweit.</p>
<p>Wenn ich aber die .def Datei einbinde, kommt die Meldung</p>
<p>dll.def : error LNK2001: unresolved external symbol DllFuncMinus<br />
dll.def : error LNK2001: unresolved external symbol DllFuncPlus</p>
<p>beim Linken.</p>
<p>Hier der simple Inhalt der .def-Datei:</p>
<pre><code class="language-cpp">LIBRARY DLLTest

EXPORTS
	DllFuncPlus @1
	DllFuncMinus @2
</code></pre>
<p>Habe einfach eine TXT-Datei angelegt und der dann eben den Namen dll.def gegeben, dann unter Source Files des Applikationsprojektes im VisualC++ 6 eingefügt.</p>
<p>Wo ist der Fehler?</p>
<p>Gruß</p>
<p>seventh_son</p>
]]></description><link>https://www.c-plusplus.net/forum/post/964988</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/964988</guid><dc:creator><![CDATA[seventh_son]]></dc:creator><pubDate>Thu, 12 Jan 2006 21:01:23 GMT</pubDate></item><item><title><![CDATA[Reply to DLL einbinden on Thu, 12 Jan 2006 21:01:29 GMT]]></title><description><![CDATA[<p>Du musst die Funktionen entweder mit extern &quot;C&quot; markieren oder ins .def-File die C++-dekorierten Namen reinschreiben, wie es z.B. bei der MFC gemacht ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/964994</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/964994</guid><dc:creator><![CDATA[Ringding]]></dc:creator><pubDate>Thu, 12 Jan 2006 21:01:29 GMT</pubDate></item><item><title><![CDATA[Reply to DLL einbinden on Thu, 12 Jan 2006 21:04:06 GMT]]></title><description><![CDATA[<p>Wo muß ich extern C einfügen? Im Header?</p>
<p>Kannst du mir mal Code-Beispiele für beide Lösungen geben?</p>
<p>Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/964996</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/964996</guid><dc:creator><![CDATA[seventh_son]]></dc:creator><pubDate>Thu, 12 Jan 2006 21:04:06 GMT</pubDate></item><item><title><![CDATA[Reply to DLL einbinden on Thu, 12 Jan 2006 21:06:08 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">extern &quot;C&quot; int iDllVar;
extern &quot;C&quot; int DllFuncPlus(int i) 
extern &quot;C&quot; int DllFuncMinus(int i)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/964997</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/964997</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Thu, 12 Jan 2006 21:06:08 GMT</pubDate></item><item><title><![CDATA[Reply to DLL einbinden on Thu, 12 Jan 2006 21:12:33 GMT]]></title><description><![CDATA[<p>Ich habe jetzt &quot;DLL_EXPORT&quot; rausgenommen und 'extern &quot;C&quot;' reingenommen, der Fehler bleibt aber der gleiche.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/965003</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/965003</guid><dc:creator><![CDATA[seventh_son]]></dc:creator><pubDate>Thu, 12 Jan 2006 21:12:33 GMT</pubDate></item><item><title><![CDATA[Reply to DLL einbinden on Thu, 12 Jan 2006 21:18:42 GMT]]></title><description><![CDATA[<p>Hier die dll.h:</p>
<pre><code class="language-cpp">#ifndef DLL_H
#define DLL_H

#include &lt;windows.h&gt;

#ifdef __cplusplus //in windows.h enthalten
#define EXTERN_C extern &quot;C&quot;
#else
#define EXTERN_C extern
#endif
EXTERN_C int DllFuncPlus( int i );
EXTERN_C int DllFuncMinus( int i );

///////////////////
#endif DLL_H
///////////////////
</code></pre>
<p>und die dll.cpp:</p>
<pre><code class="language-cpp">#define _DLL
#include &quot;dll.h&quot;
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
	switch (ul_reason_for_call) {
		case DLL_PROCESS_ATTACH:
		// DLL wird in den Adressraum des Prozesses eingeblendet.
		// Bei einem Fehler return FALSE
		case DLL_THREAD_ATTACH:
		// Ein Thread wird erstellt.
		// Hier können notwendige Initialisierungen durchgeführt werden
		// Serialisieren:
		// DisableThreadLibraryCalls( hModule );
		// hThread = CreateThread( NULL, 0, SomeFunc, NULL, 0, &amp;dwThreadId );
		// WaitForSingleObject( hThread, INFINITE );
		// CloseHandle ( hThread );
		case DLL_THREAD_DETACH:
		// Ein Thread wird ordnungsgemäss verlassen.
		// Hier können notwendige Aufräumarbeiten durchgeführt werden
		case DLL_PROCESS_DETACH:
		// Die DLL wird aus dem Prozess-Adressraum ausgeblendet
		// Hier können notwendige Aufräumarbeiten durchgeführt werden
		// Auctung!
		// TerminateProzess() führt NICHT immer DLL_PROCESS_DETACH aus!
		// if ( pHeap != NULL ) HeapFree( GetProcessHeap(), 0, pHeap );
	break;
	}
	return TRUE;
}

EXTERN_C int iDllVar=2; //exportierte Variable
EXTERN_C int DllFuncPlus(int i) { //exportierte Funktion.
	char buf[256]; 
	int j = i+iDllVar;
	wsprintf( buf, &quot;i+iDllVar=%d&quot;, j );
	MessageBox(0,buf,TEXT(&quot;Ergebnis&quot;),MB_OK);
	return j;
}
EXTERN_C int DllFuncMinus(int i) { //exportierte Funktion.
	char buf[256]; 
	int j = i-iDllVar;
	wsprintf( buf, &quot;i-iDllVar=%d&quot;, j );
	MessageBox(0,buf,TEXT(&quot;Ergebnis&quot;),MB_OK);
	return j;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/965009</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/965009</guid><dc:creator><![CDATA[seventh_son]]></dc:creator><pubDate>Thu, 12 Jan 2006 21:18:42 GMT</pubDate></item><item><title><![CDATA[Reply to DLL einbinden on Thu, 12 Jan 2006 22:08:46 GMT]]></title><description><![CDATA[<p>Niemand mehr einen Tip? Ich bin hier fast am Verzweifeln <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/965056</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/965056</guid><dc:creator><![CDATA[seventh_son]]></dc:creator><pubDate>Thu, 12 Jan 2006 22:08:46 GMT</pubDate></item><item><title><![CDATA[Reply to DLL einbinden on Thu, 12 Jan 2006 22:16:59 GMT]]></title><description><![CDATA[<p>Ich vermute eher mal, dass Du vergessen hast Deine DEF-Datei in den Linker-Settings einzutragen! (Project|Properties|Linker|Input|Module Definition File)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/965061</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/965061</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Thu, 12 Jan 2006 22:16:59 GMT</pubDate></item><item><title><![CDATA[Reply to DLL einbinden on Fri, 13 Jan 2006 04:48:50 GMT]]></title><description><![CDATA[<p>Nein, die wurde automatisch eingetragen.</p>
<p>Wenn Du Dir die Fehler anschaust, entstehen die ja auch in der def.-File.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/965110</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/965110</guid><dc:creator><![CDATA[seventh_son]]></dc:creator><pubDate>Fri, 13 Jan 2006 04:48:50 GMT</pubDate></item><item><title><![CDATA[Reply to DLL einbinden on Fri, 13 Jan 2006 06:33:36 GMT]]></title><description><![CDATA[<p>Ich habe genau Deinen Source und die DEF-Datei in ein neues DLL-Projekt getan und es klappt wunderbar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/965126</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/965126</guid><dc:creator><![CDATA[Jochen Kalmbach]]></dc:creator><pubDate>Fri, 13 Jan 2006 06:33:36 GMT</pubDate></item><item><title><![CDATA[Reply to DLL einbinden on Fri, 13 Jan 2006 09:08:06 GMT]]></title><description><![CDATA[<p>Wie gehst du genau vor?</p>
<p>Ich habe ja zwei Projekte, einmal das DLL-Projekt, welches die .dll erstellt, und einmal das Applikations-Projekt. für die .exe Datei. Beide gehören zu einem Arbeitsbereich.</p>
<p>Die .def-Datei habe ich in den Source-Files des Applikationsprojektes eingefügt. Muß sie ins DLL-Projekt? Oder gar in beide Projekte?</p>
<p>Gruß</p>
<p>seventh_son</p>
]]></description><link>https://www.c-plusplus.net/forum/post/965220</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/965220</guid><dc:creator><![CDATA[seventh_son]]></dc:creator><pubDate>Fri, 13 Jan 2006 09:08:06 GMT</pubDate></item><item><title><![CDATA[Reply to DLL einbinden on Fri, 13 Jan 2006 09:17:01 GMT]]></title><description><![CDATA[<p>Ins DLL-Projekt gehört sie.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/965231</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/965231</guid><dc:creator><![CDATA[Ringding]]></dc:creator><pubDate>Fri, 13 Jan 2006 09:17:01 GMT</pubDate></item><item><title><![CDATA[Reply to DLL einbinden on Fri, 13 Jan 2006 09:52:06 GMT]]></title><description><![CDATA[<p>Danke euch! Das war der Fehler.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/965256</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/965256</guid><dc:creator><![CDATA[seventh_son]]></dc:creator><pubDate>Fri, 13 Jan 2006 09:52:06 GMT</pubDate></item></channel></rss>