Announcement

Collapse
No announcement yet.

[C++] Dll in Dll einlesen? Geht das?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • [C++] Dll in Dll einlesen? Geht das?

    Hallo,

    habe ein Programm geschrieben, das mit Plugins arbeiten soll. Das soll so funktionieren, dass es eine Dll "PluginManager" von diesem Programm geladen wird, die dann andere DLLs, also die Plugins läd. Dazu übergibt die Exe einen Dll-Namen an die PluginManager.dll und die läd dann die entsprechende Funktion aus dem Plugin.

    Hier der Code, der vom Compiler einwandfrei verbastelt wird, allerdings bekomme ich im Programm bei der ersten Funktion immer den Wert -1, der einem Fehlschlagen des Ladevorgangs der DLL entspricht.

    Code:
    #include <iostream>
    #include <windows.h>
    
    #define DLL extern "C" __declspec(dllexport)
    
    // nur unter MS VC das Symbol DLL definieren; z.B. unter Linux wird DLL ignoriert
    
    // Die Funktion, die anderen Programmen zur Verfügung gestellt werden soll
    // (in diesem Beispiel: Addieren zweier Zahlen)
    
    
    typedef wchar_t*(_stdcall *consolePointerSendPluginName)(void);
    consolePointerSendPluginName SendPluginName;
    typedef wchar_t*(_stdcall *consolePointerSendPluginAuthor)(void);
    consolePointerSendPluginAuthor SendPluginAuthor;
    typedef wchar_t*(_stdcall *consolePointerSendPluginEmail)(void);
    consolePointerSendPluginEmail SendPluginEmail;
    typedef wchar_t*(_stdcall *consolePointerSendPluginHomepage)(void);
    consolePointerSendPluginHomepage SendPluginHomepage;
    typedef wchar_t*(_stdcall *consolePointerSendPluginDescription)(void);
    consolePointerSendPluginDescription SendPluginDescription;
    typedef wchar_t*(_stdcall *consolePointerSendPluginBuildDate)(void);
    consolePointerSendPluginBuildDate SendPluginBuildDate;
    typedef wchar_t*(_stdcall *consolePointerSendPluginVersion)(void);
    consolePointerSendPluginVersion SendPluginVersion;
    typedef int (_stdcall *consolePointerInformThePlugin)(wchar_t* dReleasedEvent, wchar_t* dTitle, wchar_t* dArtist, wchar_t* dAlbum, int dLength, wchar_t* dUrl);
    consolePointerInformThePlugin InformThePlugin;
    
    
    DLL int InformPlugin(wchar_t* ReleasedEvent, wchar_t* Title, wchar_t* Artist, wchar_t* Album, int Length, wchar_t* Url, wchar_t* DllName)
    {
    	HMODULE hDLL;
    	hDLL = LoadLibrary(DllName);
    	//MessageBox(0, DllName, L"Test", MB_OK);
    	if(hDLL!=NULL)
    	{
    		InformThePlugin = (consolePointerInformThePlugin)GetProcAddress(hDLL,"InformThePlugin");
    		if(!InformThePlugin)
    	    {
    			//MessageBoxA(0, "Error loading Plugin-Function", "Error", MB_OK);
    			FreeLibrary(hDLL);
    			return -1;
    		} 
    		else
    		{
    			return InformThePlugin(ReleasedEvent, Title, Artist, Album, Length, Url);
    		}
    	}
    	else
    	{
    		//MessageBoxA(0, "Error loading Plugin-File", "Error", MB_OK);
    		return -2;
    	}
    }
    
    wchar_t* getPluginName(wchar_t* DllName){
    	HMODULE hDLL;
    	hDLL = LoadLibraryW(DllName);
    	if(hDLL!=NULL)
    	{
    		SendPluginName = (consolePointerSendPluginName)GetProcAddress(hDLL,"SendPluginName");
    		if(!SendPluginName)
    	    {
    			//MessageBoxA(0, "Error loading Plugin-Function", "Error", MB_OK);
    			FreeLibrary(hDLL);
    			return L"error_loading_plugin_function";
    		} 
    		else
    		{
    			return SendPluginName();
    		}
    	}
    	else
    	{
    		//MessageBoxA(0, "Error loading Plugin-File", "Error", MB_OK);
    		return L"error_loading_plugin";
    	}
    
    }
    
    
    
    
    
    wchar_t* getPluginAuthor(wchar_t* DllName){
    	HMODULE hDLL;
    	hDLL = LoadLibraryW(DllName);
    	if(hDLL!=NULL)
    	{
    		SendPluginAuthor = (consolePointerSendPluginAuthor)GetProcAddress(hDLL,"SendPluginAuthor");
    		if(!SendPluginAuthor)
    	    {
    			//MessageBoxA(0, "Error loading Plugin-Function", "Error", MB_OK);
    			FreeLibrary(hDLL);
    			return L"error_loading_plugin_function";
    		} 
    		else
    		{
    			return SendPluginAuthor();
    		}
    	}
    	else
    	{
    		//MessageBoxA(0, "Error loading Plugin-File", "Error", MB_OK);
    		return L"error_loading_plugin";
    	}
    }
    wchar_t* getPluginHomepage(wchar_t* DllName){
    	HMODULE hDLL;
    	hDLL = LoadLibraryW(DllName);
    	if(hDLL!=NULL)
    	{
    		SendPluginHomepage = (consolePointerSendPluginHomepage)GetProcAddress(hDLL,"SendPluginHomepage");
    		if(!SendPluginHomepage)
    	    {
    			//MessageBoxA(0, "Error loading Plugin-Function", "Error", MB_OK);
    			FreeLibrary(hDLL);
    			return L"error_loading_plugin_function";
    		} 
    		else
    		{
    			return SendPluginHomepage();
    		}
    	}
    	else
    	{
    		//MessageBoxA(0, "Error loading Plugin-File", "Error", MB_OK);
    		return L"error_loading_plugin";
    	}
    	
    }
    wchar_t* getPluginEmail(wchar_t* DllName){
    	HMODULE hDLL;
    	hDLL = LoadLibraryW(DllName);
    	if(hDLL!=NULL)
    	{
    		SendPluginEmail = (consolePointerSendPluginEmail)GetProcAddress(hDLL,"SendPluginEmail");
    		if(!SendPluginEmail)
    	    {
    			//MessageBoxA(0, "Error loading Plugin-Function", "Error", MB_OK);
    			FreeLibrary(hDLL);
    			return L"error_loading_plugin_function";
    		} 
    		else
    		{
    			return SendPluginEmail();
    		}
    	}
    	else
    	{
    		//MessageBoxA(0, "Error loading Plugin-File", "Error", MB_OK);
    		return L"error_loading_plugin";
    	}
    }
    wchar_t* getPluginDescription(wchar_t* DllName){
    	HMODULE hDLL;
    	hDLL = LoadLibraryW(DllName);
    	if(hDLL!=NULL)
    	{
    		SendPluginDescription = (consolePointerSendPluginDescription)GetProcAddress(hDLL,"SendPluginDescription");
    		if(!SendPluginDescription)
    	    {
    			//MessageBoxA(0, "Error loading Plugin-Function", "Error", MB_OK);
    			FreeLibrary(hDLL);
    			return L"error_loading_plugin_function";
    		} 
    		else
    		{
    			return SendPluginDescription();
    		}
    	}
    	else
    	{
    		//MessageBoxA(0, "Error loading Plugin-File", "Error", MB_OK);
    		return L"error_loading_plugin";
    	}
    }
    wchar_t* getPluginVersion(wchar_t* DllName){
    	HMODULE hDLL;
    	hDLL = LoadLibraryW(DllName);
    	if(hDLL!=NULL)
    	{
    		SendPluginVersion = (consolePointerSendPluginVersion)GetProcAddress(hDLL,"SendPluginVersion");
    		if(!SendPluginVersion)
    	    {
    			//MessageBoxA(0, "Error loading Plugin-Function", "Error", MB_OK);
    			FreeLibrary(hDLL);
    			return L"error_loading_plugin_function";
    		} 
    		else
    		{
    			return SendPluginVersion();
    		}
    	}
    	else
    	{
    		//MessageBoxA(0, "Error loading Plugin-File", "Error", MB_OK);
    		return L"error_loading_plugin";
    	}
    }
    wchar_t* getPluginBuildDate(wchar_t* DllName){
    	HMODULE hDLL;
    	hDLL = LoadLibraryW(DllName);
    	if(hDLL!=NULL)
    	{
    		SendPluginBuildDate = (consolePointerSendPluginBuildDate)GetProcAddress(hDLL,"SendPluginBuildDate");
    		if(!SendPluginBuildDate)
    	    {
    			//MessageBoxA(0, "Error loading Plugin-Function", "Error", MB_OK);
    			FreeLibrary(hDLL);
    			return L"error_loading_plugin_function";
    		} 
    		else
    		{
    			return SendPluginBuildDate();
    		}
    	}
    	else
    	{
    		//MessageBoxA(0, "Error loading Plugin-File", "Error", MB_OK);
    		return L"error_loading_plugin";
    	}
    }
    Versucht habe ich es schon mit dem Pluginpfad vom Anwendungsverzeichnis und vom DLL-Verzeichnis aus. Ausserdem habe ich es schon mit dem vollen Pfad "C:\blahblah...\c\d\e\f\g" versucht...

    Vielen Dank schon mal im voraus,

    WorldRacer

  • #2
    Nach deinem Code entspricht -1 nicht einem fehlgeschlagenen Laden, sondern einem fehlgeschlagenem "InformThePlugIn"
    Christian

    Comment

    Working...
    X