与符号常量的名称连接

时间:2014-02-09 01:07:17

标签: c++ macros concatenation constants stringify

我正在尝试创建一个将符号常量扩展为case语句的宏,如下所示:

// #define WM_PAINT 0x000F
LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
    switch (msg) {
        BIND_MSG(WM_PAINT)
        // -> case WM_PAINT: Wnd_Main_WM_PAINT (hWnd, wParam, lParam); break;
    }

    return DefWindowProc(hWnd, msg, wParam, lParam);
}
我试了很多东西。我得到的最佳工作宏是:

#define BIND_MSG(msg) case (msg): Wnd_Main_##msg (hWnd, wParam, lParam); break;

但是这个宏不会扩展到Wnd_Main_WM_PAINT,而是扩展到Wnd_Main_0x000F。当我尝试Wnd_Main_ ## #msg代替Wnd_Main_##msg时,我不会Wnd_Main_WM_PAINT,而是Wnd_Main_。是否有可能将Wnd_Main_与符号常量WM_PAINT的名称连接起来?

Visual Studio expands the macro to <code>Wnd_Main_0x000F</code>

(抱歉,屏幕截图是德语.Visual Studio说,标识符Wnd_Main_0x000F未定义。)

0 个答案:

没有答案