Slashdot Mirror


Porting From MFC To GTK

crazney writes "Linux.com has an article up by Ryan Gorden of Loki on porting from Windows to Linux, in particular the troubles faced with Microsofts MFC API and the extensions implemented by Microsofts Visual C++ on the C++ language." Talks about porting, the gaming industry, and gives suggestions for portability from someone who should know.

9 of 210 comments (clear)

  1. Hey, now - wait a second by Col.+Panic · · Score: 5
    I see Gordon's points, but this goes to far:

    Legality aside, don't forget your end users; not only are win32 wrappers considered to be "cheating" by the Linux community, no one wants to run a native Linux application that looks like a native Windows application. After all, if we wanted to use Windows programs, we'd just run Windows in the first place and save all this hassle. Your users demand more from you. Do not cheat them out of it.

    OK - granted, it would be nice if the games had a distinctive Linux look and feel, but I really don't care about that as much as being able to play the bloody game on Linux. If this is the kind of esoteric touching up that makes it impossible to get a game ported to Linux then I am pissed!! Just put out the freaking game already and take the time to make others Linux-distinctive after you have built more of a market for games running on Linux.

    Just my $0.02

  2. No sir... by Otis_INF · · Score: 4
    From the article: Why is that? First and foremost, we can blame the Microsoft Foundation Classes. This API is a brick wall of incompatibility. Secondly, we can blame Visual C++'s extensions to the language. The MFC library is a true C++ OO wrapper around win32, which is function oriented, non-C++. In other words: if you use MFC your C++ program is _TRUE_ OO. (so no main function, nothing. everything is an object). If you don't understand the concepts or of you don't know how everything is build up, MFC looks like a mess and not workable. However, the MFC is very very handy when programming a GUI and the gui supporting layer, hell it even supplies nice thread objects and other objects for common used win32 stuff, so you can keep your C++ truely OO, instead of have to fall back to function oriented programming for some parts of your application.

    The Loki programmer clearly doesn't understand MFC. he also doesn't understand VC++'s extensions. That's ok, you can't know everything, but that's not a reason for ranting. It's a reason for investigation and to collect information about the topics he doesn't understand.

    I've done some tools in MFC and all I can say is that using it is a breeze, but you have to study it to get to that point. That takes time and effort. The Loki programmer should take more time to clearly understand how the original sourcecode is using the MFC.

    Another thing though... he's talking about the code to port to Linux. The code he's porting is from people who write tools that do what they want them to do AT THAT TIME, but not mainstream tools for every user on the planet: i.e.: the sourcecode can be cumbersome to understand. IMHO that's a much bigger reason why it's hard to port a tool from win32 to GTK+ than the MFC calls, which are clearly documented in the MSDN (which is shipped on 3 (not 2!) CD's, he must be using old MSDN's too). I mean... how hard can it be to read the clear MSDN explanation of an MFC method, understand what it does and to use an equivalent in GTK+....
    --

    --
    Never underestimate the relief of true separation of Religion and State.
  3. Re:Fuck MFC. Fuck VC++. Fuck all proprietary langs by MenTaLguY · · Score: 5

    MFC Source is completely visible

    Yes, thank God. Granted, as pointed out in the article, you're not legally allowed to compile it on non-windows platforms.

    and I believe it's intended to be portable.

    As someone who's done a fair amount of programming with MFC before, I don't really see how you could say that. Intended... maybe... but in practice it's not at all.

    MFC even has a whole bunch of (very badly designed) STL-equivalent classes that are used very pervasively. This basically means that, if you're doing a decent Model-View-Controller style program you either:

    • use STL in your "backend" (model) code, and convert to the MFC equivalent classes when you have to interact with MFC, destroying performance
    • use the MFC equivalents throughout, meaning your backend code is non-portable to any environment without the MFC container classes

    I'm not really fond of MFC in general, either. It's a really poor object-oriented design. It has a horrid set of macros that tend to obfuscate things during debugging, and it really abuses templates (much worse than STL), too.

    It's just another app framework dude. Just happens to be MS's.

    Since when is it being a Microsoft product an excuse for anything?

    --

    DNA just wants to be free...
  4. Re:MFC for what? by Jonathan · · Score: 5

    But user interface stuff is exactly the problem. Yes, you *can* write a win32 app with Visual C++ without using the MFC, but it is akin to writing an X program with raw Xlib calls. And as regard to portability, I doubt most companies give a damn -- that's why there are companies like Loki which buy the rights to do the Linux ports -- the original companies aren't interested.

  5. This sounds like a call for Java! by DeadSea · · Score: 5
    Maybe your game needs a lot of raw speed, and hardware specific stuff to run, but I doubt that your map builder does. Why not write some of these helper apps in Java?

    One of Java's biggest strengths is its cross platform GUI ability. No need to deal with MFC and GTK. Just deal with AWT (or if you are willing to ditch the mac, SWING)

    When you combine java jar files with some simple VBS scripts or some bash shell scripts, you can even make installation pretty seamless nowdays.

  6. Good Object Oriented User Interface by LionKimbro · · Score: 5

    I'm sorry, but this is nuts. MFC is the worst example of OO UI that I have ever seen.

    If you really buy into Object Oriented dogma, and you want to make an OO UI, you have two places to look for real examples:

    1. NextStep. The NextStep system, a complete Object Oriented system from the ground up, Foundation Classes, gui builders, written in Objective-C (let me guess; you've never programmed in it... tut, tut...), is truly the paragon of Object Oriented User Interface design. So modular, customers can completely reshape the UI (appearance, layout, hot-keys) without changing a single line of code. It is breathtaking.
    2. GTK+. GTK+ is the next best thing to NextStep's system, from what I have seen. I'll bet you've never used it. GTK+ has the same capability to modify the UI, provided that you use libglade (as you should, as mentioned in the article). If you don't like a GTK+ UI, you can open up glade, reshape the .glade file, and wha-lah, you have a rearranged UI. I'm not so certain that you can add new elements very easily without getting into the code (as you can with NextStep's system, but you can do quite a bit). Note that GTK+ is object oriented, even though it is not written in C++. (Guess what! There are languages out there that are not C++... Some of them are even something called "functional"... Unfortunately, functional concepts seem to be lost to the world...)

    Unfortunately, I can't speak for QT; I've never used it. {:(}=

    Now MFC..?! An object oriented system? It's the epitome of bad OO design. Good lord; when you use MFC, it generates these enormous files for you with macro blocks that say, "DO NOT TOUCH THESE!" around them. You can't add anything except through the grace of the UI builder. Is this "modular design"? This from people who mindlessly repeat the mantra "We must have type safety"?! It's nuts. Okay, now lets move beyond the macro blocks. When you are using MFC, it generates functions for you, and you are supposed to manually modify these functions. You can't register your functions; you have to manually go in and modify the code that it generates for you. And we are supposed to believe that this is "object oriented" design.

    I'm not an OO bigot. But really; If you have determined to be an OO bigot, at leastbe a good OO bigot. Pull out your SmallTalk books, Simula, Design Patterns, Objective-C. Trace your roots. Read them. Read about NextStep. Study. Look at well documented, and well implemented, OO UI designs. Please. I'm begging you. As much as I despise OO facists, at least I want to talk with quality OO facists. Please don't align yourself with MFC.

    (I generally hate writing flames, but some just have to be written...)

  7. Another approach... by kris · · Score: 4

    Of course, another approach to the problem would have been to write the program in a portable library in the first place, and simply recompile it for the intended target platform, be it Windows or Linux.

    I have seen this being done with a reasonably large project using the Qt 2.0 library. All development was done in Linux, and the project was later "ported" to Windows in the course of two days. Printing and some obscure font sizing problems required a bit of meddling, and several wrong assumptions and oversights were uncovered in the porting process, which turned out to be genuine errors in the original code. But all in all the project was easily converted from Linux to Windows with minimal effort.

    The project (producing a 4 MB binary) is still being developed, in Linux, and regular compatibility testing is being done on the Windows platform mostly using vmware. All in all the money for the Windows Qt License and the vmware was well spent, as developing in the Linux environment still is much more comfortable, and debugging is easier, despite the shortcomings of the g++ compiler pointed out in the original article.


    © Copyright 2000 Kristian Köhntopp

  8. Re:Performance by Fervent · · Score: 4
    Ryan Gordon of Loki responded to my comment first hand in an email. I thought it was good enough to share with the group:

    Hey, there.

    I saw your response to my article on Slashdot:

    (http://slashdot.org/comments.pl?sid=00/10/01/1422 222&cid=16)

    Just wanted to let you know what I think about performance:

    1) GTK+ tends to use a lot more stack space for signal handling, mostly for making more function calls. You can get a good 13-20 stack frames deep in signal handling. This is, honestly, nothing, but it makes Windows a little faster in this case. This is partially due to the fact that GTK is a little more flexible, and partially due to the more-flexible design of X. To be fair, you probably aren't going to notice a difference even on a 386, unless you are passing a LOT of signals; and unless you are using some bogus message passing scheme to transfer a file via signals or some other insanity, it isn't going to matter.

    2) Most of the programs that use MFC or GTK are NOT speed-dependent, at least not in their signal handling, so it's moot.

    3) This leaves one area, and I cover it in the article; Bitmaps verses Pixmaps. Bitmaps are faster, but that's the tradeoff you get for being able to separate the X client from the X server. I tend to think that a bitmap will also be faster than a GdkImage (which is a wrapper over an XImage), especially over a network connection. If you were to do some serious animation in GDK using GdkImages, you'll probably find an equivalent program written to use Win32 bitmaps will be a little faster, but again, this is a contrived comparison, because for this, you'd really want to use DirectDraw and/or SDL or something else.

    In short, if MFC is faster, it's not by much, and it's basically not a problem anyhow. :)

    Hope that's helpful.

    --

    - I don't care if they globalize against free speech. All my best free thoughts are done in my head.

  9. /* Commented out code? AHH! */ by soldack · · Score: 5

    "The reason for this is to give a visual hint as to what is a comment and what is actual code. The rest of the syntax highlighting is less important in this case. While porting, never delete a line of code. Comment it out and make your changes below it. If you need to, comment out whole functions. You are going to find that having an immediate reference to the original code is immensely helpful, but all that text can get very confusing. Syntax highlighting makes everything much easier. "

    I couldn't disagree more. Large amounts of commented out code make programs unreadable. Why was it commented out? Was it test code? An older version? Something that wouldn't compile but needs to be fixed? Who knows...often not even the orignal commenter after a few months. Don't think that you will go back in fix it because you will not. There is almost never time to fix badly written code that seems to work because there is always new code to write. You will net get time to look at it again until a bug pops up. And then you will be left wondering what in the world was in that commented code. Writing things the correct way the first time makes life much easier.

    Comments should be used for comments. Some text explaining code. They should be used for turning code on and off (use precompiler statments, much more flexible) and they should not be used to save old code. Try using a source repository that has version diff support like cvs. This is a much cleaner way to see what you had before without leaving your old code lying around in massive /* */ blocks.

    As for comment syntax highlighting being the only usefull part of syntax highlighting, I have to disagree again. I like to see different parts of the lanugages syntax in different colors. Hence the name "syntax" highlighting, not comment highlighting.

    --
    -- soldack