Problem with wxMessageBox 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
liquidfire
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sun Apr 09, 2006 12:33 pm

Problem with wxMessageBox

Post by liquidfire » Tue Apr 11, 2006 8:48 pm

ok this is my code that I have:

Code: Select all

int32 WINAPI WinMain( HINSTANCE application_instance, HINSTANCE previous_application_instance, LPSTR command_line, int show_command )
{
	wxInitializer initializer; 
	if (!initializer)
	{ 
		fprintf(stderr, "failed to init wxWidgets\n"); 
		return 1; 
	} 

	wxMessageBox( "Test" );

}
I have including windows.h, wx.h and init.h. Know the code compiles and all the setting are but but when I run the code I can a access error at this piece of code:

int ans = dialog.ShowModal();

which is line 959 in the utilscmn.cpp. anyone know why I would be getting this error?[/code]

phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 » Wed Apr 12, 2006 7:24 am

Hm, dunno, but since your using your own main(),
wxMessageBox probably can't get the right HWND.
Maybe you should use a wxApp derived class.

micros
Super wx Problem Solver
Super wx Problem Solver
Posts: 317
Joined: Sat Mar 18, 2006 10:41 am
Location: Ustek, Bohemia

Post by micros » Wed Apr 12, 2006 7:26 am

If you step into the ShowModal, then there' line 50 in msgdlg.cpp

Code: Select all

    if ( !wxTheApp->GetTopWindow() ) {
       ...
    }
wxTheApp being an uninitialized pointer? My first idea (I thought it was NULL),

Code: Select all

    if ( wxTheApp && !wxTheApp->GetTopWindow() ) {
is not a solution, because (1) I found out there's a wxDummyConsoleApp in play to supplement an app object. But it's not a descendant of wxApp, so it doesn't have GetTopWindow in its vtable! That's the crash. (2) Even if you repaired this, later on FindSuitableParent is called, which requires some hashtable mapping hwnd's to wxWindows, which also doesn't exist if there is no wxApp. And even if you made that call safe somehow, then there it is accessed again in the dialog's destructor.

So why do you want a WinMain at all? I think it's much more comfortable to have a MyApp which has initialization and cleanup separated. You can always override OnRun if you need some special kind of operation.

DavidHart
Site Admin
Site Admin
Posts: 4008
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Post by DavidHart » Wed Apr 12, 2006 10:13 am

Hi,

If a MessageBox is all you need, you could try [url<a href=http://www.wxwindows.org/manuals/2.6.3/ ... Message</a>[/url].

Regards,

David

cpp
I live to help wx-kind
I live to help wx-kind
Posts: 195
Joined: Wed Sep 28, 2005 9:42 pm

Post by cpp » Wed Apr 12, 2006 6:41 pm

or, since youre using W32 code directly, use the W32 API function MessageBox directly. eg.

MessageBox(NULL, "test message", "test caption", MB_OK);
Hier Kommt die Sonne...

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4535
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Post by ONEEYEMAN » Wed Apr 12, 2006 8:52 pm

Hi, liquidfire,
Since you are not using the wx directly, you should call the Windows API MessageBox() function.
If you prefer to use the wx, then you shoul look at the proper DLL initialization, in the FAQ of this forum. This way as micros points out you will have an application object to which you will set the message box to.

Thank you.

liquidfire
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sun Apr 09, 2006 12:33 pm

Post by liquidfire » Thu Apr 13, 2006 2:43 am

well the thing is the the application is is not going to be a dll. and honestly my team member might just do something else becuase it might not be owrth the trouble of create a dll file for displaying wxwidgets. maybe you did not understand what i meant by using a dll. I don't mean I want to use wxWidgets form a dll file, i mena that I am using the wxWidgets dll file. I now have everything setup with linking to the dll file and not the static lib build now when i build I am getting a linking error:

main.obj : error LNK2001: unresolved external symbol "public: static unsigned int const wxStringBase::npos" ([email protected]@@2IB)
../../../../bin/win/x86-32/application_test.exe : fatal error LNK1120: 1 unresolved externals

I am usign the same code as before, just linking through the dll instead of the static library. with the static library everything compiled just have runtime error, now with the dll linking i get this linking error. any help on this one?

also we want to use wxwidgets becuase it is cross platform and feel it would me agood fit for some of our tools that will support the game engine we are building.

liquidfire
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sun Apr 09, 2006 12:33 pm

Post by liquidfire » Thu Apr 13, 2006 2:59 am

I am also getting this error:

main.obj : error LNK2001: unresolved external symbol "char const * const wxMessageBoxCaptionStr" ([email protected]@3PBDB)

any help with would be great.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4535
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Post by ONEEYEMAN » Thu Apr 13, 2006 6:27 am

Hi, liquidfire,
Do you getting this on your code or when compiling the wxWidgets library?

Also, can you post some code? It is basically a good idea to start the development from one of the samples of wxWidgets. That's how I started, anyway...

Thank you.

micros
Super wx Problem Solver
Super wx Problem Solver
Posts: 317
Joined: Sat Mar 18, 2006 10:41 am
Location: Ustek, Bohemia

Post by micros » Thu Apr 13, 2006 6:54 am

You need to have WXUSINGDLL defined when compiling the app if you want it to use wxWidgets DLL. That way all wx exported symbols are __declare(dllimport). Hope it makes sense to you.

liquidfire
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sun Apr 09, 2006 12:33 pm

Post by liquidfire » Thu Apr 13, 2006 11:07 am

ok that solves the linking error but still have problem with the same code and is my first post here. I am using IMPLEMENT_APP_NO_MAIN() which I though meant i did not need to make a wxApp derived class but it is still asking for one, is there a way I can us wxWhich without it being in a dll or creating a wxApp?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4535
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Post by ONEEYEMAN » Thu Apr 13, 2006 6:31 pm

Hi, liquidfire,
Apparently, you misread the docs. This macro is mostly used for the DLL/.so files, and indicates that the main() function will not be required, or if it's used in the executable, says that wx initialization will be bypassed. However, you need to initialize your program somehow. Are you using the native WinMain() for that? In this case you application will not be portable, and you are beter with he MFC/Native Windows API :)

Thank you.

liquidfire
Earned a small fee
Earned a small fee
Posts: 10
Joined: Sun Apr 09, 2006 12:33 pm

Post by liquidfire » Fri Apr 14, 2006 12:13 am

the reasonf or it is so that the major part of the code it portible weather I use WinMain or main() or whatever linux has or whatver Mac has or whatever PS2 has or etc... si the point of doing it the way i want to know?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4535
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Post by ONEEYEMAN » Fri Apr 14, 2006 4:56 pm

liquidfire,
But you won't be able to run your program. That's the whole purpose of using the wx - it hides the OS/compiler differences inside, and user/developer don't have to care about such differences.
You just will to have to re-invent the wheel.

Again, IMPLEMENT_APP_NO_MAIN() is used if you want to write the initialization code yourself, or writing the DLL.

Thank you.

Post Reply