Plugin Development Topic is solved

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.
Post Reply
Tech-Muc
Earned a small fee
Earned a small fee
Posts: 13
Joined: Sun Feb 08, 2009 1:57 pm

Plugin Development

Post by Tech-Muc »

Hey,

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:

Code: Select all

//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?

Thanks for any help,
TechMuc
spectrum
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Sat Jul 21, 2007 12:17 pm

Post by spectrum »

hello Tech-Muc

i would try a wxDll, take a look here.

http://wiki.wxwidgets.org/Creating_A_DL ... pplication

There is also a kinf of wxPlugin under development, but i don't know the state.

greetings,
spectrum
spectrum
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

Tech-Muc
Earned a small fee
Earned a small fee
Posts: 13
Joined: Sun Feb 08, 2009 1:57 pm

Post by Tech-Muc »

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.

Code: Select all

//dll
wxWindow* m_wnd = ::wxGetActiveWindow(); //wont work in a dll as it is not binded to the exe application.
guenni81
Earned a small fee
Earned a small fee
Posts: 10
Joined: Wed Dec 31, 2008 4:58 pm

Post by guenni81 »

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.

http://github.com/guenni81/wxpluginexample
best regards,
Günni
isNot
In need of some credit
In need of some credit
Posts: 1
Joined: Wed Jul 23, 2008 10:29 am

Post by isNot »

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.
Post Reply