wxWidgets doesn't work with MFC well 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
waterj
Earned a small fee
Earned a small fee
Posts: 21
Joined: Mon Nov 07, 2005 8:39 am

wxWidgets doesn't work with MFC well

Post by waterj » Thu Nov 17, 2005 3:43 am

I am porting a pretty large MFC project to wxWidgets. I read the sample code named "mfc" and found that wxWidgets can someway work together with MFC. This is good for me to devide the porting effort into two parts: UI and GDI. But i encountered compiling problem later because wxWidgets undefined some windows API declarations(in Defs.h) like DrawText, StartDoc and so on, and the undefining also affect MFC classes with the same name of these APIs.
now i am confused, why wxWidgets need to do this?

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Re: wxWidgets doesn't work with MFC well

Post by upCASE » Thu Nov 17, 2005 8:10 am

waterj wrote:now i am confused, why wxWidgets need to do this?
Although I can't answer this specific question and I don't have the time to dig through the code (which I would, as this is an interesting question), I think the solution might be to include winundef.h located in include\wx\msw. It should undef the defines by windows.h and add the correct function prototypes for each build.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Thu Nov 17, 2005 8:17 am

AFAIK (i read it somewhere) its because some of the win32 API function names conflict with the wx ones (hint hint, namespaces :P) so winundef.h would undefine them so it wont conflict with the wxwidgets ones

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Thu Nov 17, 2005 8:19 am

then again, i think namespaces wont help because to "undefine" something it would be a macro...

waterj
Earned a small fee
Earned a small fee
Posts: 21
Joined: Mon Nov 07, 2005 8:39 am

Post by waterj » Fri Nov 18, 2005 2:20 am

Thanks for replys. The undef not only undefined the API macro, but also made some MFC classes' member functions can not be used. Like this:

#define TestF TestFA

class A{
void TestF(){};
};

#undef TestF

void main()
{
A a;
a.TestF(); //compiling error: 'TestF' : is not a member of 'A'
}

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Fri Nov 18, 2005 2:23 am

how about you reorder the MFC includes to come later than the wx includes? I dunno if its possible coz i dont use MFC

waterj
Earned a small fee
Earned a small fee
Posts: 21
Joined: Mon Nov 07, 2005 8:39 am

Post by waterj » Fri Nov 18, 2005 6:00 am

lowjoel wrote:how about you reorder the MFC includes to come later than the wx includes? I dunno if its possible coz i dont use MFC
It won't work. Because wx.h includes windows.h, and MFC doesn't allow windows.h being included before mfc header files.

Post Reply