gpt4 book ai didi

c++ - 如何禁用更改 Unicode 或 ASCII 函数名称的 MFC 宏

转载 作者:太空狗 更新时间:2023-10-29 20:26:20 27 4
gpt4 key购买 nike

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_macropop_macro是不破坏 Windows SDK header 所必需的。

在您的类的头文件和实现文件中应应用相同的方案。如果您不能更改此类的头文件,则需要将 #include 指令包装在 push/undef/pop 序列中:

#pragma push_macro("DrawText")
#undef DrawText

#include "my_header.h"

#pragma pop_macro("DrawText")

关于c++ - 如何禁用更改 Unicode 或 ASCII 函数名称的 MFC 宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20130793/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com