trouble with wxDynamicLibrary Topic is solved
trouble with wxDynamicLibrary
hi all,
i'm new in this forum and hope somebody can help me. my problem is, that i can call a function in a dll from my application. but just after calling the dll the application does not refresh and does not stop by clicking finish (the button is just overpainted and you can't click it again). here are some code snips:
the call of the dll from the application cpp:
void TextFrame::OnClickButtonDLL(wxCommandEvent &event)
{
wxDynamicLibrary dll(wxT("Plugin_sourceforge.dll"));
if(dll.IsLoaded())
{
wxDYNLIB_FUNCTION(CreatePlugin_function,CreatePlugin,dll);
if(pfnCreatePlugin)
{
dll.Detach();
IEditorPlugin* plugin = pfnCreatePlugin();
plugin->EditNode();
}
}
dll.Unload();
}
the dll cpp:
extern "C" __declspec(dllexport) IEditorPlugin* CreatePlugin(){return new MyPlugin; }
IMPLEMENT_APP_NO_MAIN(PluginDLLApp)
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved )
{ switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH: { wxSetInstance((HINSTANCE)hModule);
int argc = 0;
char **argv = NULL;
wxEntryStart(argc, argv);
}
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH: wxEntryCleanup();
break;
}
return TRUE; }
void MyPlugin::EditNode()
{
wxMessageBox(wxT("Hallo."));
}
i'm new in this forum and hope somebody can help me. my problem is, that i can call a function in a dll from my application. but just after calling the dll the application does not refresh and does not stop by clicking finish (the button is just overpainted and you can't click it again). here are some code snips:
the call of the dll from the application cpp:
void TextFrame::OnClickButtonDLL(wxCommandEvent &event)
{
wxDynamicLibrary dll(wxT("Plugin_sourceforge.dll"));
if(dll.IsLoaded())
{
wxDYNLIB_FUNCTION(CreatePlugin_function,CreatePlugin,dll);
if(pfnCreatePlugin)
{
dll.Detach();
IEditorPlugin* plugin = pfnCreatePlugin();
plugin->EditNode();
}
}
dll.Unload();
}
the dll cpp:
extern "C" __declspec(dllexport) IEditorPlugin* CreatePlugin(){return new MyPlugin; }
IMPLEMENT_APP_NO_MAIN(PluginDLLApp)
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved )
{ switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH: { wxSetInstance((HINSTANCE)hModule);
int argc = 0;
char **argv = NULL;
wxEntryStart(argc, argv);
}
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH: wxEntryCleanup();
break;
}
return TRUE; }
void MyPlugin::EditNode()
{
wxMessageBox(wxT("Hallo."));
}
i use MS VC++ 2005 Express, windows xp, wxWidgets 2.8.7
If you haven't found it already look at UpCase's wxPlugin
http://forums.wxwidgets.org/viewtopic.php?t=13178
http://forums.wxwidgets.org/viewtopic.php?t=13178
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
MSVC Express 2019/2022
wxWidgets 3.2.2
I've just started using the example code myself quite recently , but I have not seen the problem of not repainting etc, so I can't comment on that. OTOH, everything I've tried so far, including moving and resizing has worked without any problems at all.
The only possibility I can think of is the matter of linking or using wxWidgets. I've seen a lot of comments about the need to go for dynamic linking to wxWidgets and in fact to use this code for my needs I have switched from statically linked libraries to DLLs.
The only possibility I can think of is the matter of linking or using wxWidgets. I've seen a lot of comments about the need to go for dynamic linking to wxWidgets and in fact to use this code for my needs I have switched from statically linked libraries to DLLs.
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
MSVC Express 2019/2022
wxWidgets 3.2.2
it works for you? hm, widgets, could you do me a favour plaese? maybe you can test my, to the basics, reduced code. i just want to know if it works for you. thank you very much.
main_app.h:
main_app.cpp:
plugin.h:
plugin.cpp:
DLLanfang.h:
main_app.h:
Code: Select all
#include "wx.h"
class TextEditorApp : public wxApp {
public: virtual bool OnInit();
};
DECLARE_APP(TextEditorApp)
class TextFrame : public wxFrame {
public:
TextFrame( const wxChar *title, int xpos, int ypos,
int width, int height );
~TextFrame();
void OnClose(wxCloseEvent &event);
void OnClickButtonDLL(wxCommandEvent &event);
protected:
DECLARE_EVENT_TABLE()
private:
wxButton* button;
enum {
wxBT_DLL
};
};
Code: Select all
#include "main_app.h"
#include "dynlib.h"
#include "DLLanfang.h"
#include "string.h"
#define wxUSE_DYNLIB_CLASS 1
IMPLEMENT_APP(TextEditorApp)
bool TextEditorApp::OnInit() {
TextFrame *frame = new TextFrame(
wxT("Basisanwendung"), 100, 100, 400, 300);
frame->Show(TRUE);
SetTopWindow(frame);
return true;
}
TextFrame::TextFrame( const wxChar *title,
int xpos, int ypos, int width, int height )
: wxFrame( (wxFrame *) NULL, -1, title,
wxPoint(xpos, ypos), wxSize(width, height))
{
button = new wxButton(this,wxBT_DLL,wxT("DLL Aufruf"));
}
TextFrame::~TextFrame() { }
BEGIN_EVENT_TABLE(TextFrame, wxFrame)
EVT_CLOSE(TextFrame::OnClose)
EVT_BUTTON(wxBT_DLL, TextFrame::OnClickButtonDLL)
END_EVENT_TABLE()
void TextFrame::OnClose(wxCloseEvent& event) {
Destroy();
}
void TextFrame::OnClickButtonDLL(wxCommandEvent &event)
{
wxDynamicLibrary dll(wxT("Plugin.dll"));
if(dll.IsLoaded())
{
wxDYNLIB_FUNCTION(CreatePlugin_function,CreatePlugin,dll);
if(pfnCreatePlugin)
{
dll.Detach();
IEditorPlugin* plugin = pfnCreatePlugin();
plugin->EditNode();
}
}
dll.Unload();}
Code: Select all
#include "DLLanfang.h"
class MyPlugin : public IEditorPlugin
{
public:
virtual void EditNode();
};
class PluginDLLApp : public wxApp
{
bool OnInit() {return true;}
};
Code: Select all
#include "plugin.h"
extern "C" __declspec(dllexport) IEditorPlugin* CreatePlugin(){return new MyPlugin; }
IMPLEMENT_APP_NO_MAIN(PluginDLLApp)
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{ wxSetInstance((HINSTANCE)hModule);
int argc = 0;
char **argv = NULL;
wxEntryStart(argc, argv);
}
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
wxEntryCleanup();
break;
}
return TRUE;
}
void MyPlugin::EditNode()
{
wxMessageBox(wxT("Hallo."));
}
Code: Select all
#include "wx.h"
class IEditorPlugin : public wxEvtHandler
{
public:
virtual void EditNode()=0;
};
typedef IEditorPlugin* ( *CreatePlugin_function)();
i use MS VC++ 2005 Express, windows xp, wxWidgets 2.8.7
I compiled the whole thing with my VS 2005 setup and I can't see any problems with it at all.
I can move, resize or minimize and restore the main window, before or after I make the Hallo box pop up.
I'll attach my zipped up 'solution'
If I missed anything, let me know.
I can move, resize or minimize and restore the main window, before or after I make the Hallo box pop up.
I'll attach my zipped up 'solution'
If I missed anything, let me know.
- Attachments
-
- fischi.zip
- (4.99 KiB) Downloaded 91 times
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
MSVC Express 2019/2022
wxWidgets 3.2.2
Interesting; mine shows no such problems.
Actually I hadn't tied what your picture shows, but I have just run it again and I can move (both main frame and) the dialog pop-up all over the screen, including the application frame and it always redraws things as they should be.
When run under the debugger it does produce some memory leaks, which I have not tried to investigate.
The only thing remotely suspicious was that I had to fix some of the header includes, which in your code were different from the convention I saw used in the general wxWidgets code I've seen.
Actually I hadn't tied what your picture shows, but I have just run it again and I can move (both main frame and) the dialog pop-up all over the screen, including the application frame and it always redraws things as they should be.
When run under the debugger it does produce some memory leaks, which I have not tried to investigate.
The only thing remotely suspicious was that I had to fix some of the header includes, which in your code were different from the convention I saw used in the general wxWidgets code I've seen.
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
MSVC Express 2019/2022
wxWidgets 3.2.2
My Visual Express says: 8.0.50727.42,
the .Net Framework:2.0.50727 SP1.
I rather doubt that that difference will account for the problem.
Did you try to compile the code using the solution file from the zip file I attached previously>
the .Net Framework:2.0.50727 SP1.
I rather doubt that that difference will account for the problem.
Did you try to compile the code using the solution file from the zip file I attached previously>
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
MSVC Express 2019/2022
wxWidgets 3.2.2
I have had problems with deprecated functions such as strdup etc because the compiler warns about the possibility of buffer overruns when they are used. MS has some replacement functions they recommend and if you're not concerned about portability to *nix, you may as well use them.
You can avoid the warnings by adding /wd4996 to the compiler command line ( or with an equivalent pragma directive)
As for the basic problem, I have no real idea what might be the cause
If you care to, zip up the whole basic project including the .sln & project files and I'll try to run them here.
Another 'silly' question: You have compiled both the main app and the plugin as using wxWidgets as a DLL??
What it looks like to me is that somehow the event handlers in the two parts seem to get disconnected, so that the main app no longer gets a chance to do its thing in updating the screen while the dialog is up.
You can avoid the warnings by adding /wd4996 to the compiler command line ( or with an equivalent pragma directive)
As for the basic problem, I have no real idea what might be the cause
If you care to, zip up the whole basic project including the .sln & project files and I'll try to run them here.
Another 'silly' question: You have compiled both the main app and the plugin as using wxWidgets as a DLL??
What it looks like to me is that somehow the event handlers in the two parts seem to get disconnected, so that the main app no longer gets a chance to do its thing in updating the screen while the dialog is up.
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
MSVC Express 2019/2022
wxWidgets 3.2.2