使用宏扩展进行函数声明时出错

时间:2014-08-14 12:44:01

标签: c++ windows dll macros loadlibrary

我正在尝试为延迟加载共享库创建代理类。

该库的API函数之一是:

int AttachCWnd(CWnd* pControl);

因此,我创建了一个宏来轻松声明并将代理类的调用路由到库中:

class CLibProxy {
public:
  typedef int  (*tAttachCWnd)(CWnd*);
  tAttachCWnd m_fAttachCWnd;
};

#define DECL_ROUTE(name, ret, args) \
  ret CLibProxy::name args \
  { \
    if (m_hDLL) \
      return m_f##name (args); \
    return ret(); \
  }

DECL_ROUTE(AttachCWnd, int, (CWnd* pControl));

但VS2010上的编译失败了:

error C2275: 'CWnd' : illegal use of this type as an expression

任何人都可以解释原因吗?

1 个答案:

答案 0 :(得分:0)

嗯,明显的错误。调用m_fAttachCWnd不应包含类型声明,只应包含参数:

return m_fAttachCWnd (CWnd* pControl);

应该成为

return m_fAttachCWnd (pControl);

谢谢@chris。