【问题标题】:TThemeServices::DrawText unresolved link errorTThemeServices::DrawText 未解决的链接错误
【发布时间】:2011-06-01 17:05:57
【问题描述】:

我正在创建一个自定义组件(从 TCustomCategoryPanelGroup 派生)并执行一些自定义绘制操作。我想处理何时启用主题并适当地绘制文本。

这是我在绘图函数中的一些代码的 sn-p:

int theBaseDrawFlags = DT_EXPANDTABS | DT_SINGLELINE | DT_VCENTER | DT_LEFT;
theBaseDrawFlags = DrawTextBiDiModeFlags( theBaseDrawFlags );

if ( TCustomCategoryPanelGroup::hsThemed == PanelGroup->HeaderStyle && ThemeServices()->ThemesEnabled )
{
    ThemeServices()->DrawText( ACanvas->Handle, ThemeServices()->GetElementDetails( tebNormalGroupHead ), m_CaptionTopLeft, m_TextRect, theBaseDrawFlags, 0 );
}
else
{
    // Draw without themes
}

当我尝试构建它时,我收到错误:

Unresolved external __fastcall Themes::TThemeServices::DrawTextA(HDC__ *, Themes::TThemedElementDetails&, const System::WideString, Types::TRect&, unsigned int, unsigned int)' referenced from  ....

如您所见,它正在寻找DrawTextA。我查看了 Themes.hpp 标头,只定义了一个 ThemeServices::DrawText 函数。

我不确定这里发生了什么。我想也许我缺少一个导入库,但我使用的所有其他 ThemeServices 函数都没有出现链接错误。

有人知道这里发生了什么吗?

【问题讨论】:

  • 忘了说我使用的是 C++Builder XE。

标签: c++builder vcl


【解决方案1】:

我猜你有 #included 一些标题(windows.h?),其中包含类似这样的内容

#ifdef UNICODE
#define DrawText DrawTextW
#else
#define DrawText DrawTextA
#endif

您可以在文件中添加#undef DrawText 来解决此问题。 (另见Conflict with DrawText function。)

【讨论】:

  • ThemeServices::DrawText() 不是我的代码,它是 Embarcadero 的。我尝试了您的建议(和链接的问题)的不同变体,只是为了探索这个想法。我不相信这是那种类型的问题。似乎是 Themes.hpp 标头(包含 ThemeServices 类)的生成方式存在问题,以及它与链接到的库有何不同。
  • 但是您在上面发布的代码是您的代码,不是吗?如果在它上面 DrawText 是 #defined 表示 DrawTextA 那么你的调用 ThemeServices()->DrawText 将被预处理器转换为 ThemeServices()->DrawTextA - 这将解释你得到的编译器错误。
  • @Ulrich,该错误表明DrawText 在声明TThemeServices 之前被定义为DrawTextA,而不仅仅是在Scott 调用之前。否则,错误将与调用站点上未声明的标识符有关。但是 Scott 看到了一个链接器错误,所以在编译器看到这个调用的时候,它认为它是一个有效的函数,这意味着头文件中的声明也受到了影响。 Scott,在包含 windows.h 之后,但在包含 Themes.hpp 之前,请使用 Ulrich 的建议取消定义 DrawText。
  • 是的,这是我的代码。我认为这里的假设是ThemeServices 导出了名为DrawTextA 和DrawTextW 的函数。如果是这种情况,预处理器技巧就会起作用。如果我转储具有 ThemeServices (vcl150.bpl) 的二进制文件,我只会看到 DrawText。而如果您转储 User32.dll 之类的内容,您会看到预期的 DrawTextA 和 DrawTextW。这有意义还是我还没有看到什么? (顺便说一句,感谢您的帮助)。
  • @Rob-Kennedy,如果我在文件范围内取消定义 DrawText,我对 DrawText 的其他调用(非 ThemeServices 调用)将会搞砸。我想知道 Embarcadero 是否在这里有问题,他们应该实际创建函数 DrawTextA 和 DrawTextW,但他们没有这样做?好像他们没有遵守这个约定?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-01
  • 1970-01-01
相关资源
最近更新 更多