FAQ

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.
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

Why should I post here when all the devs are on the lists?

Generally you'll want to post here - but if you have a question about one of the more obscure parts of wxWidgets or your question was not answered here after a couple of days, you should try either the wx-users or wx-dev lists.

Note that if you use wxPython you may want to stick with the python mailing lists - it can be hit-or-miss here with wxPython questions.

Don't forget to use the tracker if you have bugs/patches also...
Last edited by Ryan Norton on Thu Apr 21, 2005 9:58 am, edited 3 times in total.
[Mostly retired moderator, still check in to clean up some stuff]
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

How do I embed/compile stuff like images into my application? How do I use embedded XRC?

To embed/compile stuff into your application you need to use Embedded XRC, part of the resource system wxWidgets uses. Embedded XRC is not documented very well, though.

Here's what you need to do for MSVC and wxMSW:
  1. The first thing you will need to do is compile XRC. If you are using CVS HEAD, XRC is already part of the core library. However, if you are not using CVS HEAD you need to compile XRC seperately in contrib/xrc.
  2. Next, you will need to build WXRC. Note that you may need to apply https://sourceforge.net/tracker/?func=d ... tid=109863.
  3. After XRC and WXRC are built, it's time to create your XRC script. It looks like this:
    resources.xrc

    Code: Select all

    <?xml version="1.0"?>
    <resource version="2.3.0.1">
    
    <object class="wxBitmap" name="FIRST_IMG">first.gif</object>
    <object class="wxBitmap" name="SECOND_IMG">second.jpg</object>
    
    </resource>
    
    This will produce a resources.cpp. Check it out. Those two images have been compressed and encoded so XRC can understand them and embed them in your application.
  4. Now, assuming WXRC, resources.xrc, first.gif, and second.jpg are all in the same directory, run the following from the command line: wxrc.exe /c /v resources.xrc
  5. Ok, time to put all this into VS. Add resources.cpp to your project (so the compiler will compile it). Make sure VS can find the xrc libraries (set your linking properly if needed), and add:

    Code: Select all

    #include "wx/xrc/xmlres.h"
    #include "wx/image.h"
    #include "MyResources.h"
    
    in your main.cpp file above MyApp::OnInit. MyResources.h is a file I created (yes create one). Mine looks like:

    MyResources.h

    Code: Select all

    #ifndef MYRESOURCES_H
    #define MYRESOURCES_H
    
    extern void InitXmlResource();
    
    #endif
    

    Now, within your MyApp::OnInit function, place the following three lines:

    Code: Select all

    wxInitAllImageHandlers();
    wxXmlResource::Get()->InitAllHandlers(); 
    InitXmlResource();
    
    Alright, you're almost done. You've now successfully built the XRC library, linked it into your projects, embedded your resources actually into the executable and told your application that you are going to use embedded XRC. The only thing left is to load the images.
  6. To load from your embedded resource, the following would load an image up:

    Code: Select all

    wxBitmap* myImage = new wxBitmap();
    *myImage =  wxXmlResource::Get()->LoadBitmap("FIRST_IMG");
    
Do you get it? Pretty cool huh? Notice you don't need to worry anything about the types. wxWindows is smart enough to figure out what you're working with.
[Mostly retired moderator, still check in to clean up some stuff]
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

I compile wx and there's like 1,000,000 libraries!!! What do they mean?

See http://www.wxwidgets.org/manuals/2.5.3/ ... slist.html
[Mostly retired moderator, still check in to clean up some stuff]
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

How do I convert XXX to a wxString and vice versa?

wxChar*

Just use wxString::c_str. For char*/wchar_t* see the UNICODE/ANSI section below (char* is a multibyte string and wchar_t is a unicode string - either 2 or 4 bytes to character depending on your compiler, prefixed with L"XXX" etc.).

Integers

int-->string

Code: Select all

myString << myInt;
(Note that you can use wxString::Format in place of this, but the << operator is preferred for optimization reasons, and is easier)

string-->int

Code: Select all

myInt = wxAtoi(myString);
(A more official way to do a string-->int conversion is to use wxString::ToLong or wxString::ToULong)

Floats/Doubles

double-->string

Code: Select all

myString << myDouble;
(Note that you can use wxString::Format in place of this, but the << operator is preferred for optimization reasons, and is easier)

double-->int

Code: Select all

myDouble = wxAtod(myString);
(A more official way to do a string-->double conversion is to use wxString::ToDouble)

Pascal Strings (Mac usually)

Pascal Strings are a normal ansi string with a leading character that indicates their length and without a trailing null character.

In wx/mac/carbon/private.h (include wx/mac/private.h in your file) you can use the following to convert a wxString to a pascal string (you'll want to delete the pascal string afterwards :))

Code: Select all

void wxMacStringToPascal( const wxString&from , StringPtr to ) ;
wxString wxMacMakeStringFromPascal( ConstStringPtr from ) ;
Also, somewhat related is that you can get a FSSpec directly from a wxString:

Code: Select all

wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL ) ;
OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef ) ;
wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname ) ;
Basic String (BSTR in COM)

A COM AUTOMATION Basic String is a 2-byte-per-character (wxUint16*) string that is like a pascal string, only the leading data amount that contains its length is 4 bytes.

You can use the manual MSW calls SysAllocString etc., create the string yourself (not too difficult), or use wxBasicString from wx/msw/ole/oleutils.h.

Just do something like

Code: Select all

wxBasicString(mywxstring).Get();
UNICODE/ANSI

This is fairly involved. When converting UNICODE-->ANSI the encoding you pass is the encoding you want your DESTINATION string to be in - when converting from ANSI-->UNICODE, the encoding you pass in is the encoding of the multibyte SOURCE string.

Now, with that out of the way the general way to convert from UNICODE to ANSI and vice versa is to use the wxMBConv classes. These are pretty involved and are in wx/strconv.h, these classes contain the encoding within them - so there is no need to specify which encoding you want - just use the appropriate wxMBConv instance.

For better or worse, there are several -->GLOBAL<-- wxMBConv instances. Note that these are probably not thread-safe in any way!!!

wxConvLocal is the global wxMBConv instance that you'll want to use 99% of the time, its the encoding that wxWidgets uses. All of the examples here will use this.

wxConvLibc is the encoding the c library uses - rather than using optimized native calls it uses the mbtowc c library routines, which may not be implemented on your platform/compiler.

wxConvFile is the encoding the file system uses. There's A LOT of debate over this - essentially you're supposed to use it to wxFopen, but beyond that its quite involved. Try avoiding it if you can.

To convert from UNICODE or ANSI:

Code: Select all

//wx doesn't have a wxWXCharBuffer etc. yet so make our own
#ifdef UNICODE
#define wxMYCharBuffer wxWCharBuffer
#else
#define wxMYCharBuffer wxCharBuffer
#endif

//WX-->MultiByte 
//for wxChar*
wxCharBuffer mbc = wxConvLocal.WX2MB(mywxcharptr);
//for wxString
wxCharBuffer mbc = mywxString.mb_str(wxConvLocal);

//MultiByte-->WX
wxMYCharBuffer buf = wxConvLocal.MB2WX(mycharptr);

//WX-->Wide Character
//for wxChar*
wxWCharBuffer wcc = wxConvLocal.WX2WC(mywxcharptr);
//for wxString
wxWCharBuffer wcc = mywxString.wc_str(wxConvLocal);

//Wide Character-->WX
wxMYCharBuffer buf = wxConvLocal.WC2WX(mywcharptr);
You're probably wondering about wc_str and mb_str. Well, these are better because they take into account embedded null characters in your string and don't have to call strlen.
Last edited by Ryan Norton on Tue Mar 22, 2005 2:08 am, edited 3 times in total.
[Mostly retired moderator, still check in to clean up some stuff]
eco
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 203
Joined: Tue Aug 31, 2004 7:06 pm
Location: Behind a can of Mountain Dew
Contact:

Post by eco »

wxWidgets is making my application leak memory! Help?

Before you go accusing wxWidgets of having a memory leak, make sure you are using the correct tools to detect a memory leak (Windows Task Manager is not such a tool).

Tools for Windows:
  • Visual C++ - .NET 2003 has simple yet effective memory leak detection built in (as does Visual C++ 6 I believe).
  • BoundsChecker - Famous, featurefull tool by CompuWare.
  • Purify - IBM Rational memory leak detector.
Tools for Linux: For other platforms, just ask around and see what you fellow developers prefer. There are many more tools than what I've listed there.

If there is a leak in your application it is important to differentiate between the leak being caused by wxWidgets or being caused by your misuse of wxWidgets. For the most part, wxWidgets cleans up memory for you but there are cases where you are obligated to clean up. Read the documentation carefully to ensure you handle cases where you are responsible for deallocation of memory. If you do find an actual memory leak within wxWidgets please report it as a bug or, even better, submit a patch fixing the issue.

Sidenote by upCASE:
Using VC++ this tip might be valuable when hunting memory leaks:
http://www.litwindow.com/Knowhow/wxHowt ... ebug_alloc
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

How does the documentation system work? How do I regenerate the docs?

No, it doesn't use doxygen unfortunately. It uses a form of latex. You can edit the docs by editing the .tex files in docs/latex/wx.

What you need to do is build a tool called tex2rtf that comes with wxWidgets, and then run it with the following command line:

tex2rtf manual.tex ../../html/wx/wx.htm -checkcurleybraces -checksyntax -html -macros tex2rtf_css.ini


because that is long and annoying and you probably don't have tex2rtf in your PATH or whatever, you might use a shell script/.bat like

# !/bin/sh
tex2rtf manual.tex ../../html/wx/wx.htm -checkcurleybraces -checksyntax -html -macros tex2rtf_css.ini
[Mostly retired moderator, still check in to clean up some stuff]
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

How do I make a dll for use with wxWidgets?

The following sample shows how to implement a DLL using wxWidgets. When called it will initialize wxWidgets and clean it on unload. The DLL exports two functions "DLLFunction" and "TestReport". DLLFunction displays a simple dialog with a button and handles the button event. "TestReport" shows a small dialog with a wxHTML page.

wxDLL.h

Code: Select all

// wxDLL is a simple DLL which demonstrates how to use
// wxWindows in a DLL which is called from another
// application (not using wxWindows)
//
//
// Tony Edgecombe
// (C) 2004 Frogmore Computer Services
// www.frogmorecs.com
// Edited by upCASE

#pragma once

#include "wx/wx.h"

#include "windows.h"


#ifdef DLLFUNCTIONS_EXPORTS
#define DLLFUNCTIONS_API __declspec(dllexport)
#else
#define DLLFUNCTIONS_API __declspec(dllimport)
#endif

extern "C" DLLFUNCTIONS_API void DLLFunction(HWND);
extern "C" DLLFUNCTIONS_API void TestReport(HWND handle);

class wxDLLApp : public wxApp
{
	bool OnInit();
	void OnButton(wxCommandEvent& evt);
	DECLARE_EVENT_TABLE()
};
wxDLL.cpp

Code: Select all

// wxDLL is a simple DLL which demonstrates how to use
// wxWindows in a DLL which is called from another
// application (not using wxWindows)

// Edited by upCASE

#include "wx/wx.h"

#include "wxDLL.h"
#include "wx/wxhtml.h"

// We use IMPLEMENT_APP_NO_MAIN so we can start the app from DllMain
// as we don't have a WinMain or main entry point
//
BEGIN_EVENT_TABLE(wxDLLApp, wxApp)
	EVT_BUTTON(123,wxDLLApp::OnButton)
END_EVENT_TABLE()

IMPLEMENT_APP_NO_MAIN(wxDLLApp) 

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
		{	//use wxInitialize() if you don't want GUI instead of the following 12 lines
                        wxSetInstance((HINSTANCE)hModule);
			int argc = 0;
			char **argv = NULL;
			wxEntryStart(argc, argv);
			if ( !wxTheApp || !wxTheApp->CallOnInit() )
				return FALSE; 
		}
		break;

		case DLL_THREAD_ATTACH:
		break;

		case DLL_THREAD_DETACH:
		break;

		case DLL_PROCESS_DETACH:
		 wxEntryCleanup(); //use wxUninitialize() if you don't want GUI
		break;
	}
    return TRUE;
}

// extern "C" so we don't need a DEF file

// This is the function to be called from the host app
extern "C" DLLFUNCTIONS_API void DLLFunction(HWND handle)
{
// Create a dummy wxWindow so we can use the HWND passed from the
// host application

	wxWindow win;
	win.SetHWND((WXHWND)handle);
	win.Enable(false);

	wxDialog dlg(&win, -1, "wxDialog in DLL", wxDefaultPosition, wxSize(150,150));
	wxButton b(&dlg, 123,"Press me please");
	dlg.ShowModal();

// Clean up else the caller can't use its window
	win.Enable(true);
	win.SetHWND(0);
}

extern "C" DLLFUNCTIONS_API void TestReport(HWND handle)
{
	wxWindow win;

	win.SetHWND((WXHWND)handle);
	win.Enable(false);

	wxDialog dlg(&win, wxID_ANY, wxString(_("About")), wxDefaultPosition, wxSize(400,180));
	
	wxHtmlWindow html1(&dlg,wxID_ANY, wxDefaultPosition, wxSize(380, 160), wxHW_SCROLLBAR_NEVER);
	html1.SetPage("<html><body>"
                     "<h1>Error</h1>"
					"Some error occurred :-))"
					"</body></hmtl>");

	dlg.ShowModal();

	// Clean up else the caller can't use its window
	win.Enable(true);
	win.SetHWND(0);
}

bool wxDLLApp::OnInit()
{
	return true;
}
void wxDLLApp::OnButton(wxCommandEvent& evt)
{
	wxMessageBox("You really did it.... I don't believe it!");
}
Note that the above is for 2.5.4 and up. For lower versions try

Code: Select all

BOOL APIENTRY DllMain( HINSTANCE hModule, 
                       DWORD  fdwReason, 
                       LPVOID lpReserved 
                                        ) 
{ 
   switch (fdwReason) 
   { 
   case DLL_PROCESS_ATTACH: 
       { 
           wxEntry(hModule, 0, NULL, 0, false);
       } 
       break; 

   case DLL_PROCESS_DETACH: 
       { 
           wxTheApp->OnExit();
           wxApp::CleanUp(); 
       } 
   } 

    return TRUE; 
}
The following snippet is a simple "loader" for the DLL that does NOT use wxWidgets.
DLLCaller.cpp

Code: Select all

// This is a simple Windows app which loads and calls our DLL on request
//
// Tony Edgecombe
// (C) 2004 Frogmore Computer Services Ltd
// www.frogmorecs.com
// Edited by upCASE

#pragma once

#include "windows.h"

int APIENTRY WinMain(HINSTANCE hInstance,
					   HINSTANCE hPrevInstance,
					   LPTSTR    lpCmdLine,
					   int       nCmdShow);

// Just a test app no real need for seperate .h file
// #include "DLLTestApp.h"

#include "assert.h"

typedef void (*DLLFunctionPtr) (HWND);
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM); 

// Entry point
int APIENTRY WinMain(HINSTANCE hInstance,
					   HINSTANCE hPrevInstance,
					   LPTSTR    lpCmdLine,
					   int       nCmdShow)
{
	WNDCLASSEX wcx; 

	wcx.cbSize = sizeof(wcx);
	wcx.style = CS_HREDRAW | CS_VREDRAW;
	wcx.lpfnWndProc = MainWndProc;
	wcx.cbClsExtra = 0;
	wcx.cbWndExtra = 0;
	wcx.hInstance = hInstance;
	wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcx.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
	wcx.lpszMenuName =  "MainMenu";
	wcx.lpszClassName = "MainWClass";
	wcx.hIconSm = NULL;

	ATOM a = RegisterClassEx(&wcx); 
	assert(a);

	HWND hwnd = CreateWindow("MainWClass",
							"Test DLL",
							WS_OVERLAPPEDWINDOW,
							CW_USEDEFAULT,
							CW_USEDEFAULT,
							CW_USEDEFAULT,
							CW_USEDEFAULT,
							(HWND) NULL,
							(HMENU) NULL,
							hInstance,
							(LPVOID) NULL);
	assert(hwnd);

	ShowWindow(hwnd, nCmdShow); 
	UpdateWindow(hwnd); 

	long bRet;
	MSG msg;
	while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0 ) 
	{
		if (bRet != -1)
		{
			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}
	}

	return 0;
}

// Windows Callback Procedure
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hDC;

	switch( msg ) {
	  case WM_PAINT:
		  hDC = BeginPaint( hWnd, &ps );
		  TextOut( hDC, 10, 10, "Left Click on this form to launch function: DLLFunction", 55 );
		  TextOut( hDC, 10, 30, "Right Click on this form to launch function: TestReport", 55 );
		  EndPaint( hWnd, &ps );
		  break;

	  case WM_DESTROY:
		  PostQuitMessage( 0 );
		  break;

	  case WM_LBUTTONUP:
		  {
			  // Load up the DLL and call DLLFunction(
				HMODULE hModule = LoadLibrary("Test.dll");
				assert(hModule);
				DLLFunctionPtr pProc = (DLLFunctionPtr)GetProcAddress(hModule, "DLLFunction");
				assert(pProc);
				(pProc)(hWnd);
				FreeLibrary(hModule);
		  }
		  break;

	  case WM_RBUTTONUP:
		  {
			  // Load up the DLL and call DLLFunction(
				HMODULE hModule = LoadLibrary("Test.dll");
				assert(hModule);
				DLLFunctionPtr pProc = (DLLFunctionPtr)GetProcAddress(hModule, "TestReport");
				assert(pProc);
				(pProc)(hWnd);
				FreeLibrary(hModule);
		  }
		  break;

	  default:
		  return( DefWindowProc( hWnd, msg, wParam, lParam ));
	}
	return 0;
}
Edited by upCASE: Added new code sample and description.

You may download the sources and a VC 7 project file here:
http://www.upcase.de/stuff/wxDLL_App.zip
Last edited by Ryan Norton on Tue Jul 12, 2005 9:56 pm, edited 8 times in total.
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

How do I use wxThread/wxTimer? Is there an example using wxThread that's easy to understand? What's the difference Between wxThread and wxTimer?

First off, the difference between wxThread and wxTimer is that wxTimer generally runs over and over again easily and usually gets executed in the same thread using the OS's event loop (GUI calls are generally safe with a wxTimer, not so with a wxThread on non-msw platforms).

There is an example using wxThread in the wx lib, but its kind of bulky if you just want a basic understanding of it, plus it doesn't point out the likely problems you'll have with it...

Basically for wxThread all you need to do is dynamically create (via new) a wxThread derived class, call Create then Run (no params usually)- and in your derived class overload

Code: Select all

virtual ExitCode Entry();
And do all you want in Entry. Just make sure you call TestDestroy in there over and over again and return if TestDestroy returns true.

Deleting a running thread is iffy, but you can sorta do it by Delete() of wxThread.

wxTimer is much easier - you still should either dynamically allocate it or make sure it doesn't destruct when you don't want it to - but it isn't as dangerous as a wxThread. To use a wxTimer all you need to do is override Notify

Code: Select all

virtual void Notify();
then call Start in your code with the time you want the timer to be called and whether or not you want it to be called more than once (you can always call Stop() later to end the repeating behaviour).

Also see http://lists.wxwidgets.org/cgi-bin/ezml ... jggjimdhha.
[Mostly retired moderator, still check in to clean up some stuff]
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

When I call wxWindow::Destroy() it isn't closing and I'm getting a ton of events!

You're probably doing something funky with one of the wx events. In particular you ABSOLUTELY HAVE TO USE A wxPaintDC IN A PAINT EVENT! If you do not bad things will happen, especially on windows.

Just make sure to read about the particular event types and you should be OK.
[Mostly retired moderator, still check in to clean up some stuff]
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

How do I get Microsoft Office/Visual Studio-type toolbars/windows?

There is nothing really in the base of wxWidgets to help you, but there are a few contrib and third-party APIs for doing dockable and other types of windows
Last edited by Ryan Norton on Wed May 10, 2006 6:57 pm, edited 1 time in total.
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

How do I get my frame that uses sizers to resize?

Normally the window is supposed to automatically resize when using sizers... however there appears to be a rare-case bug that hits some people (including myself), normally in these cases Layout() works, but in rare cases sometimes it doesn't.

For wxMediaCtrl I use this all-purpose sizer-resizing hack that forces the parent of a control to resize itself.

Code: Select all

// ctrl is the control with a parent to have sizer sizing algorithms forcibly
// applied to it
ctrl->InvalidateBestSize();
ctrl->GetParent()->Layout();
ctrl->GetParent()->Refresh();
ctrl->GetParent()->Update();
ctrl->SetSize(ctrl->GetSize());
[Mostly retired moderator, still check in to clean up some stuff]
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

What classes in wxWidgets are thread-safe?

Basically none, not even wxString. If you use STL (wxUSE_STL) then if your stl is thread-safe then a lot of things should be thread-safe except gdi objects (they ref count but there's no spin lock so its not thread-safe)
[Mostly retired moderator, still check in to clean up some stuff]
GianT
Earned some good credits
Earned some good credits
Posts: 124
Joined: Wed Mar 16, 2005 5:44 pm
Location: Guadeloupe, French West Indies
Contact:

Post by GianT »

How do I convert a BMP/JPG/PNG/etc image into an xpm file?

You can use softs like xnview (there must be others, just search on google).
For those who don't know, xpm is a format used by wxDev-cpp and other development softs to deal with images. It converts it from an image file, but you might want to convert the images manually, instead of letting the soft doing it.
Last edited by GianT on Tue Jun 21, 2005 10:53 pm, edited 4 times in total.
User avatar
Ryan Norton
wxWorld Domination!
wxWorld Domination!
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton »

What are these things called a patch?

"Patches" are a text file generated by the "diff" program which gets the differences between two files. Developers on a project later use the program "patch" to merge in the changes from the patch file into thier repository. Some projects like wx have specific ways they want you to use patches... you can find the info here -

http://www.wxwidgets.org/technote/patches.htm

Note that if you're on windows you can use tortoisecvs's "make patch" option under "unedit" under the cvs menu in windows explorer.
[Mostly retired moderator, still check in to clean up some stuff]
Sami Hamlaoui
In need of some credit
In need of some credit
Posts: 6
Joined: Mon Jul 11, 2005 1:35 pm

Post by Sami Hamlaoui »

Why does my program crash at this line in list.cpp?

Code: Select all

 if ( key == current->m_key )
[/size][/b]

It crashes there because you compiled wxWidgets with the default structure alignment in your compiler/IDE, but then in your project set it to some fixed value (1 byte, 2byte, 4byte, etc). You must either compile wxWidgets with the same structure alignment as your app, or keep both set as default.

The options box in MSVC7.1 is at Project -> xxx Properties -> C++ -> Code Generation -> Struct Member Alignment.


If you are loading a lot of binary files directly into structures as opposed to per-variable then you will need Struct Member Alignment at 1 in both wxWidgets and your application, otherwise extra bytes are added into the struct, buggering up the loading.
Post Reply