wxFrame kills app from inside DLL 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
jazz
Experienced Solver
Experienced Solver
Posts: 73
Joined: Thu Jun 09, 2005 12:37 am
Contact:

wxFrame kills app from inside DLL

Post by jazz »

Ok, i'm new to windows programming but am pretty competant and so I decided the next thing to learn is how to create and use DLLs. So i decided to take an existing app and move my logging class to a DLL. The DLL itself works and I can load it up in my app fine, but when I run a function inside the DLL that creates a wxFrame my app crashes in flames.

The offending line is:

Code: Select all

FrmLog = new wxDialog(&win, wxID_ANY, "Log Window", wxPoint(0,0), wxSize(800,400));
If i comment it out, everything works fine but I can't see what's being logged.

I'm asuming it doesn't like the fact that I'm trying to create a window without an application? maybe? Anyone that can point me in the right direction? I'm kinda unsure where to start looking to solve this one.

TIA
[INSERT LAME SIG HERE]
protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol »

Umm... Are you instantiating the wxApp?

There are more questions I can ask, but that is the most important one to me.
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!
sarat
Knows some wx things
Knows some wx things
Posts: 43
Joined: Wed Feb 08, 2006 1:59 pm
Location: Bangalore
Contact:

umm!! ur not constrcting the frame object properly

Post by sarat »

umm!! ur not constrcting the frame object properly :lol:

here u go.. and do like this

MyFrame::MyFrame(wxChar *title, int Xpos, int Ypos, int width, int height )
: wxFrame( (wxFrame *) NULL,
-1,
title,
wxPoint(Xpos, Ypos),
wxSize(width, height),
wxDEFAULT_FRAME_STYLE,
"sarat"
)
{

// ur code

}
protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Re: umm!! ur not constrcting the frame object properly

Post by protocol »

I think what sarat is saying; is that you should instantiate from a wxDialog class that you inherit, not from a standard class. I guess

Code: Select all

 wxDialog(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE, const wxString& name = "dialogBox")
But as you can see, you are using the wxDialog (wxWindow) correctly.

But I digress.
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!
jazz
Experienced Solver
Experienced Solver
Posts: 73
Joined: Thu Jun 09, 2005 12:37 am
Contact:

Re: umm!! ur not constrcting the frame object properly

Post by jazz »

protocol wrote:I think what sarat is saying; is that you should instantiate from a wxDialog class that you inherit, not from a standard class. I guess

Code: Select all

 wxDialog(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE, const wxString& name = "dialogBox")
But as you can see, you are using the wxDialog (wxWindow) correctly.

But I digress.
I thought it was something like that too. The original version used wxFrame (before it was in the DLL) but after reading some examples i got the impression i was suppose to use wxDialog. But, regardless, neither way works and whenever it get's to execute a line that creates a window, it crashes.
[INSERT LAME SIG HERE]
protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol »

Do you instantiate a wxApp?
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!
jazz
Experienced Solver
Experienced Solver
Posts: 73
Joined: Thu Jun 09, 2005 12:37 am
Contact:

Post by jazz »

protocol wrote:Do you instantiate a wxApp?
Of course. My logger class actually inherits wxApp.

Solved tho. It was sort of to do with how i was loading the DLL. I was linking the library instead of calling LoadLibary(), so dllmain was not was not being called. Which meant this part:

Code: Select all

wxSetInstance((HINSTANCE)hInst);
int argc = 0;
char **argv = NULL;
wxEntryStart(argc, argv);
if ( !wxTheApp || !wxTheApp->CallOnInit() )
      return FALSE;
was not executing either. So i put that at the top of my logger::Initialise member function and threw in a HINSTANCE argument. To initialise it from my app now all i have to change is one line to:

Code: Select all

Log.Initialise(wxGetInstance())
and everything now works perfectly. Thanks for the help.
[INSERT LAME SIG HERE]
fgleich
Earned a small fee
Earned a small fee
Posts: 11
Joined: Fri Jan 07, 2005 4:57 pm
Location: NM USA
Contact:

Post by fgleich »

Hi:)
Was this dll written with wxWidgets only and no MS code ? If so, can you post it for a tutorial for others ? Also, the compile and link commands ( on linux if possible )
Thanks in advance :)
Post Reply