MFC有定义,如下:
#ifdef UNICODE
#define DrawText DrawTextW
#else
#define DrawText DrawTextA
#endif // !UNICODE
然而,我正在使用一个库,该库也具有DrawText()函数,我猜测MFC也定义了更改,并且我因为显然该库没有名为DrawTextW(...)的函数而收到了此调用的链接器错误。
我如何使库函数在我的MFC应用程序中正常工作?
MFC有定义,如下:
#ifdef UNICODE
#define DrawText DrawTextW
#else
#define DrawText DrawTextA
#endif // !UNICODE
然而,我正在使用一个库,该库也具有DrawText()函数,我猜测MFC也定义了更改,并且我因为显然该库没有名为DrawTextW(...)的函数而收到了此调用的链接器错误。
我如何使库函数在我的MFC应用程序中正常工作?
这不是MFC,而是Windows API。解决宏遮蔽其他符号的推荐方法是暂时禁用该宏:
// Temporarily undefine the DrawText macro
#pragma push_macro("DrawText")
#undef DrawText
// Call your version of DrawText
DrawText( ... );
// Re-enable the macro
#pragma pop_macro("DrawText")
#pragma push_macro和pop_macro是必须的,以避免破坏Windows SDK头文件。
对于您的类的头文件和实现文件,应该采用相同的方案。如果您无法更改此类的头文件,则需要将#include
指令包装在推送/未定义/弹出序列中:
#pragma push_macro("DrawText")
#undef DrawText
#include "my_header.h"
#pragma pop_macro("DrawText")
#ifdef DrawText
#undef DrawText
#endif
error C2039: 'DrawText' : is not a member of 'PoDoFo::PdfPainter'
的错误。我想也许我应该将其取消定义,然后重新定义为自身,如#define DrawText DrawText
,但是这样仍然会出现相同的错误。 - zar