If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
I want to allow plugin development for my project (a Level-Editor for a game engine). Here is Generally the way how i want to implement Plugin-Programming:
//myprog
HANDLE fHandle;
WIN32_FIND_DATA wfd;
fHandle = FindFirstFile((char*)folder),&wfd);
if(fHandle == 0) { return(-1); }
FindNextFile(fHandle,&wfd);
//search through all files and if a dll is found in a specific plugins subdir:
HMODULE m_mod = LoadLibrary((char*)wfd.cFileName));
if(m_mod)
{
WIP_Plugin* m_plug = new WIP_Plugin;
if(m_plug->Init(m_mod) == false)
{
delete m_plug;
FreeLibrary(m_mod);
}
}
//In WIP_Plugin->Init i search for the existance of a DLL-Function which is executed every frame of the Game-Engine
//dll
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved )
{
engine_bind(); //bind game engine
return TRUE;
}
DLLFUNC int GED_RunPlugin(DLL_RunMode m_data,GED_ExportStruct* data)
{
switch(m_data)
{
case DLL_INIT:
//init
GED_DLLInit(data);
GED_ConnectMouseEvent(MouseEvent);
break;
case DLL_ENGINE_RUN:
//run in engine thread
break;
case DLL_EXIT:
wxMessageBox("Exit","Exit",wxOK); //crash
break;
}
return 0;
}
The Problem: How can i bind wxWidgets to the DLL, with the current data of the Level Editor?
For example a wxMessageBox call crashs - ofc- as any parameter like wxTheApp is unknown to the caller DLL.
Is there any way to bind the App of the Level-Editor to the external DLL?
The main problem is, that i do not only want to use wxWidgets in a DLL but as an addentum want to have "full" access to the wxWidgets Initalization of the Caller.
E.g. i want to directly access a Menu-Item defined in the Caller of the DLL (without the need of a function in the exe). Or get full access to active Windows etc.
Hello,
i'm not sure whether it might help you, but the following example adds menu- and toolbaritems to the main window. The function which is called is located in the plugin.
to do what you want, you need to pass a reference to your plugins. maybe you could have a plugin_init routine that you call after you load the dll, and you pass a pointer to the app. the same for any windows you want the plugin to access.
I have only briefly looked through guenni81's link, and it looks like he started with a post from 'scorcher24' in the German c-plusplus.de forum (search plugin here and you will find a lot of information, including the reference above), but I've been playing with it and it can do what you are looking for with some modifications.