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 »

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
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Re: wxWidgets doesn't work with MFC well

Post by upCASE »

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
Part Of The Furniture
Part Of The Furniture
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel »

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
Part Of The Furniture
Part Of The Furniture
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel »

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 »

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
Part Of The Furniture
Part Of The Furniture
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel »

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 »

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