Zugriff auf Methoden abgeleiteter Klassen die allerdings nicht in der Basisklasse definiert sind mit Basisklassenzeiger
-
Sorry ..... hier ist er (hoffe is net zu viel...):
#ifndef INTERFACE_H #define INTERFACE_H typedef struct XColor { float fl_red; float fl_green; float fl_blue; }; typedef struct XGuiPrefences { char* ptr_name; //name displayed in the window names area char* ptr_register; //name of window with which window is registered int posx; //first coordinate of upper left corner int posy; //second coordinate of upper left corner int width; //windows width int height; //widnows height XColor fl_brcol; //window background float fl_Alpha; //alpha channel }; class XComBase { public: virtual unsigned long executeCommand (void) = 0; virtual unsigned long registerPlugin (void) = 0; virtual unsigned long unregisterPlugin (void) = 0; virtual void* getPluginMethods (void) = 0; private: protected: }; class XComGuiBase : virtual public XComBase { public: virtual int xCreate (XGuiPrefences* ptr_render, int menu) = 0; virtual int xMain (XGuiPrefences* ptr_render) = 0; virtual bool showConsole (bool is_shown) = 0; virtual void InfoBox (char* message, char* title) = 0; virtual void ErrorBox (char* message, char* title) = 0; virtual int addButton (int x, int y, int cx, int cy, int id, char* name) = 0; virtual void setKey (int key, bool state) = 0; virtual bool InitCommonControls (void) = 0; virtual bool CreateTreeview (int x, int y, int cx, int cy, int id) = 0; virtual int AddElementToTreeview (int nLocation, char* elem, bool sorted) = 0; private: protected: }; class XGuiMessageSystem { public: virtual int Event_WindowCreate (void) {return 0;} virtual int Event_MouseMoved (void) { return 0; } virtual int Event_Repaint (void) { return 0; } virtual int Event_Resize (void) {return 0; } virtual int Event_MouseClicked (int x, int y) {return 0; } virtual int Event_MouseClickedRight (int x, int y) { return 0; } virtual int Event_Clicked (int widget) { return 0; } virtual int Event_MouseClickedSecundary (int x, int y) { return 0;} virtual int Event_Create (void) { return 0; } virtual int Event_KeyPressed (int key) { return 0; } virtual int Event_KeyUnpressed (int key) { return 0; } virtual int Event_Background (void) { return 0; } private: protected: }; #endif #ifndef X_COM_MANAGER #define X_COM_MANAGER #include <vector> #include <iostream> #include "XInterface.h" #include "XGen.h" #include <log.h> #include <windows.h> #include <vector> #include <map> #include <direct.h> using namespace std; class XComManager { public: XComManager (XGuiPrefences* ptr_pref); virtual ~XComManager (void); virtual unsigned long registerPlugin (unsigned long plgID, XComGuiBase* ptr_base, XGuiMessageSystem* ptr_message); virtual unsigned long startPlugin (void); virtual unsigned long stopPlugin (void); virtual unsigned long releasePlugin (void); virtual XComGuiBase* GetPlugin (int pos); private: std::map<int, XComBase*> plgStack; LOG* mglog; XGuiPrefences* ptr_pref; protected: }; /* function pointers */ extern "C" typedef unsigned long (*GUI_PLG) (HINSTANCE hdll, XComGuiBase**, XGuiMessageSystem*); #endif unsigned long XComManager::registerPlugin (unsigned long plgID, XComGuiBase* ptr_base, XGuiMessageSystem* ptr_message) { HMODULE hDll = (HMODULE) NULL; char* dllname = new char [100]; static int counter = 0; // GUI - Plugin laden if (plgID == PLG_GUI) { *mglog << "Plugin erkannt auf PLG_GUI" << endl; #ifdef WIN32 strcpy ((char*)dllname, (char*)"dll"); strcat ((char*)dllname, (char*)"\\XWin32.dll"); *mglog << "Betriebsystem erkannt auf >>WINDOWS<<" << endl; if (!(hDll = LoadLibraryEx (dllname, NULL, 0))) { *mglog << "Error binding Dll to application's address space" << endl; } /* Zeiger auf die richtige Klasse initialisieren und dann im Pluginvektor abspeichern, damit die Anwendung darauf zugreifen kann */ GUI_PLG gplg = NULL; gplg = (GUI_PLG) GetProcAddress (hDll, "XExport"); gplg (hDll, &ptr_base, ptr_message); //plgStack[counter] = ptr_base; plgStack.insert (std::pair<int, XComGuiBase*>(counter, ptr_base)); *mglog << "Neues Element in map eingefügt mit ID " << counter << endl; counter++; #else //Lade Linuxpluigin #endif } // Render - Plugin laden else if (plgID == PLG_RENDER) { } return 0; }
-
fluxy schrieb:
Sorry ..... hier ist er (hoffe is net zu viel...):
zeig mir wie du XComManager benutzst, wie du "registerPlugin" rufst und noch die folgenden Methoden:
XComManager::XComManager (XGuiPrefences* ptr_pref);
XComManager::~XComManager();
-
XComManager::XComManager (XGuiPrefences* ptr_pref) { this->ptr_pref = (XGuiPrefences*)NULL; /* Logfile erstellen */ char* path = new char [1024]; strcpy ((char*)path, (char*)""); path = _getdcwd (_getdrive (), (char*)path, 400); strcat ((char*)path, (char*)"\\log\\"); mglog = new LOG (path, "GuiHandler.txt"); this->ptr_pref = ptr_pref; } XComManager::~XComManager (void) { } /* aus der Beispielanwendung die den Manager nutzt */ void Engine::CreateSurface (void) { ptr_manager = new XComManager (&wpref); ptr_manager->registerPlugin (PLG_GUI, ptr_surface, this); ptr_surface = ptr_manager->GetPlugin (0); ptr_surface->xCreate (&wpref, 0); ptr_surface->xMain (&wpref); } int main (void) { Engine* engine = new Engine (); engine->CreateSurface (); return 0; }
-
du sollst "operator delete" und "operator delete[]" benutzen, oder wie ich schon geschrieben habe std::auto_ptr oder boost::shared_ptr, weil deine Code viele "memory leaks" hat. Keine andere Proplemen hab ich nicht gefunden und bei mir geht dein Beispiel...
-
bei dir geht das?
WARUM?!
Ja ums aufräumen kümmer ich mich später das ist im Moment nicht so das Problem.... Kann bei den Pointern eigentlich bleiben.... aber warum geht das bei mir und bei dir nicht?
-
fluxy schrieb:
bei dir geht das?
WARUM?!
Ja ums aufräumen kümmer ich mich später das ist im Moment nicht so das Problem.... Kann bei den Pointern eigentlich bleiben.... aber warum geht das bei mir und bei dir nicht?
geht bei dir das folgende:
class XComGuiBaseImpl : public XComGuiBase { //XComBase virtual unsigned long executeCommand (void) {return 0;}; virtual unsigned long registerPlugin (void) {return 0;}; virtual unsigned long unregisterPlugin (void) {return 0;}; virtual void* getPluginMethods (void){return 0;}; //XComGuiBase virtual int xCreate (XGuiPrefences* ptr_render, int menu) {return 0;}; virtual int xMain (XGuiPrefences* ptr_render) {return 0;}; virtual bool showConsole (bool is_shown) {return true;}; virtual void InfoBox (char* message, char* title) {}; virtual void ErrorBox (char* message, char* title) {}; virtual int addButton (int x, int y, int cx, int cy, int id, char* name) {return 0;}; virtual void setKey (int key, bool state) {}; virtual bool InitCommonControls (void) {return true;}; virtual bool CreateTreeview (int x, int y, int cx, int cy, int id) {return true;}; virtual int AddElementToTreeview (int nLocation, char* elem, bool sorted) {return 0;}; }; int main (void) { std::auto_ptr<XComManager> manager(new XComManager(0)); std::auto_ptr<Engine> engine(new Engine()); std::auto_ptr<XComGuiBase> guiBase(new XComGuiBaseImpl()) manager->registerPlugin(PLG_GUI, guiBase, engine); }
?
-
hmm hast an den klassen was geändert?
-
fluxy schrieb:
hmm hast an den klassen was geändert?
no
geht auch nicht?
-
nein es geht nicht....
was mich nicht weiter verwundert....
denn alle 3 pointer sind auch ohn deine erweiterung gültig.... von daher kann es daran nicht liegen,
-
fluxy schrieb:
nein es geht nicht....
was mich nicht weiter verwundert....
denn alle 3 pointer sind auch ohn deine erweiterung gültig.... von daher kann es daran nicht liegen,
du kannst mir dein vollständiges Project an ssyabr@yahoo.com schicken, vielleicht kann ich so den Fehler finden.