Cautions when using widgets as a dynamic library?

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
rodrigod
I live to help wx-kind
I live to help wx-kind
Posts: 172
Joined: Thu Jun 26, 2008 8:50 pm

Cautions when using widgets as a dynamic library?

Post by rodrigod »

I was linking wxWidgets statically and was working fine, but since I decided to use wxDynamicLibrary and it said that I should use widgets dynamically for it I recompiled everything.

It is an application with many dll's, and when the first one is called it crashes with the Assert "only main thread may call wxMutexGuiLeaveOrEnter()!".

Here is some code of how I created my dll's. I copied it from the wxwiki page.

Code: Select all

HANDLE ThreadId;
 
class CACTIONRESApp : public wxApp
{
};

IMPLEMENT_APP_NO_MAIN(CACTIONRESApp) 

DWORD WINAPI ThreadProc(LPVOID lpParameter)
 {
     wxApp::SetInstance(new CACTIONRESApp());
     wxEntry(GetModuleHandle(NULL),NULL,NULL,SW_SHOW);
     return true;
 }
 
 #ifdef __WXMSW__
 BOOL APIENTRY DllMain(HANDLE hModule,
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
                       ) 
 {
     switch (ul_reason_for_call)
     { 
     case DLL_PROCESS_ATTACH:
         ThreadId = CreateThread(NULL,0,ThreadProc,NULL,0,NULL);
         break;
     case DLL_THREAD_ATTACH: break;
     case DLL_THREAD_DETACH: break;
     case DLL_PROCESS_DETACH:
         wxEntryCleanup();
         break; 
     }
 
     return TRUE;
 }
 #endif
A code like this is on my every dll, it crashed when the first dll was loaded. Here is the call stack when it crashed:

ntdll.dll!7c90120e()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
wxbase28d_vc_custom.dll!wxTrap() Line 678 C++
wxbase28d_vc_custom.dll!ShowAssertDialog(const char * szFile=0x00b229e4, int nLine=1359, const char * szFunc=0x01672034, const char * szCond=0x00b229b8, const char * szMsg=0x00b22984, wxAppTraits * traits=0x016303c8) Line 825 C++
wxbase28d_vc_custom.dll!wxAppConsole::OnAssertFailure(const char * file=0x00b229e4, int line=1359, const char * func=0x01672034, const char * cond=0x00b229b8, const char * msg=0x00b22984) Line 445 + 0x22 bytes C++
wxbase28d_vc_custom.dll!wxOnAssert(const char * szFile=0x00b229e4, int nLine=1359, const char * szFunc=0x00b229cc, const char * szCond=0x00b229b8, const char * szMsg=0x00b22984) Line 713 C++
> wxbase28d_vc_custom.dll!wxMutexGuiLeaveOrEnter() Line 1359 + 0x2c bytes C++
wxmsw28d_core_vc_custom.dll!wxEventLoop::OnNextIteration() Line 203 C++
wxmsw28d_core_vc_custom.dll!wxEventLoopManual::Run() Line 99 C++
wxmsw28d_core_vc_custom.dll!wxAppBase::MainLoop() Line 312 + 0x15 bytes C++
wxmsw28d_core_vc_custom.dll!wxAppBase::OnRun() Line 368 C++
wxbase28d_vc_custom.dll!wxEntryReal(int & argc=2, char * * argv=0x0162a340) Line 460 + 0x1b bytes C++
wxbase28d_vc_custom.dll!wxEntry(int & argc=2, char * * argv=0x0162a340) Line 209 + 0xd bytes C++
wxmsw28d_core_vc_custom.dll!wxEntry(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * __formal=0x00000000, HINSTANCE__ * __formal=0x00000000, int nCmdShow=5) Line 386 + 0xe bytes C++
ACTIONRES.dll!ThreadProc(void * lpParameter=0x00000000) Line 77 + 0x15 bytes C++
kernel32.dll!7c80b713()
ntdll.dll!7c9276ea()

I have no idea how to fix this.

Thanks
Post Reply