Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hallo,

seit Langem probier ich gerade wieder mich mit DLLs anzufreunden. Ich möchte eine DLL vom Programm heraus dynamisch laden, eine Funktion aufrufen und einen Text mit der Funktion ausgeben.

DLL:

#define DLLEXPORT _declspec(dllexport)


BOOL APIENTRY DllMain( HANDLE hModule, 

                       DWORD  ul_reason_for_call, 

                       LPVOID lpReserved

					 )

{

	switch(ul_reason_for_call)

	{

	case DLL_PROCESS_ATTACH:

		break;


	case DLL_PROCESS_DETACH:

		break;


	case DLL_THREAD_ATTACH:

		break;


	case DLL_THREAD_DETACH:

		break;


	}

    return TRUE;

}


DLLEXPORT void printText(LPCTSTR text)

{

	printf("%s", text);

}
App:
typedef void (* DLLFKTP) (LPCTSTR text);


int main(int argc, char* argv[])

{

	HMODULE lib = NULL;

	DLLFKTP fkt = NULL;


	lib = LoadLibrary("dlltest.dll");


	if (lib == NULL) 

	{

		cout << "DLL failed" << endl;

		return DLL_NOT_FOUND;

	}

	fkt = (DLLFKTP) GetProcAddress(lib, "printText");

	if (fkt == NULL)

	{

		cout << "Function failed" << endl;

		return FKT_NOT_FOUND;

	}


	fkt("Hallo Welt.");


	FreeLibrary(lib);


	return ERROR_SUCCESS;

}

DLL wird gefunden. Allerdings findet er die Funktion nicht.

Was ist die Ursache?

  • Autor

hm...

Im Debug-Ordner (der DLL) ist keins.

Außerdem sagt die MSDN:

__declspec(dllexport) was added to provide an easy way to export functions from an .EXE or .DLL without using a .DEF file.
  • Autor

Problem gelößt.

#define DLLEXPORT extern "C" _declspec(dllexport)

Das verhindert das C++ die Funktionsnamen erweitert.

Memo an mich selbst:

DLLs nur noch in *.c - Dateien schreiben

  • Autor

Mit dem Dependency Walker bin ich ja erst dahinter gekommen, dass der Methodenname verändert wurde.

Wenn ich ein DEF File oder den veränderten Methodenname nehme, ist aber nicht sichergestellt, dass die Funktion bei Austauschen der DLL genauso heißt (oder doch?).

Ich will eigentlich nur die Funktionsaufrufe in der exe haben und via DLL-Switching zu anderen Ergebnissen kommen.

Wenn ich dann immerwieder eine neue Exe erstellen müsste (neue .lib/.def), würde das meiner Idee widersprechen.

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.