Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a legacy application written in C, using the raw Win32 API. The general level of abstraction is low and raw dependency on <windows.h> is common.

I would like to port this application to GTK+. There are any kind of guidelines or best practices on how to do this? I've previously ported a MFC application to Qt, but the application was very abstracted - it draw it's own set of widgets, for example - and initial porting was very straightforward.

I've been thinking at first using Winelib to build a native Linux executable and then trying to slowly refactor it into a GTK+ app.

Does some one have best practices or previous experiences to share about this?

share|improve this question
Wine doesn't build native Linux executables. – alternative Feb 15 '11 at 23:26
@mathepic I thought one could link with winelib to get a native binary. Thanks for the correction. – Vitor Py Feb 15 '11 at 23:35
Braga You're right, Winelib does that. – alternative Feb 15 '11 at 23:58
up vote 2 down vote accepted

Do not mix the two things. You want to port your application to GTK+, and you want to port it to Linux. Leave the Linux part for later, it'll be easier in the end.

Just sharing my personal experience on a C++ MFC application where iterative refactoring proved to be a nightmare due to entangled Win32 specific code and core application behaviour.

First, we didn't try to build a Linux application. In our first refactor step we attempted to trim class declarations from their Win32 specific code. When not possible, we created abstraction classes. For instance, if a class was keeping a HWND handle to a window, we created a MyWindow class to encapsulate the HWND.

Then we started redesigning all the interface parts using Glade (targeting GtkBuilder instead of libglade which I believe is deprecated) without writing a single line of code.

Finally we rewrote the application itself, by copy-pasting class members and implementations whenever possible. In this step, MyWindow would contain a GtkWindow, and eventually become a GtkWindow whenever possible.

It was painful but we could not think of a better way to do it at the time. Still can't.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.