定义宏,即不定义宏

问题描述 投票:0回答:1

虽然使用第三方共享库(即DLL),但我必须通过其符号名称定义可用的功能。因此,我必须声明一些函数类型。

但是函数定义涉及调用约定,在我的情况下为__cdecl

因此,此调用约定自然仅适用于有关MSVC编译器,但是我仍然想编译我的可移植API抽象代码,该代码在Linux中使用boost :: dll,即使我不能在开发Linux机器上执行它也是如此,因此我仍然可以检查编译时的内容。因此,我的想法是将__cdecl名称定义为空白或空白,如果可以使用预处理器,则将其定义为NOP,但我无法做到这一点。

#if !BOOST_OS_WINDOWS
#define  __cdecl ( ) /* error, how can I define __cdecl as 'nothing" here? */
#endif

#include <boost/dll/import.hpp>
boost::dll::shared_library lib;

unsigned long device_count(char* pid) {
    typedef unsigned long(__cdecl func_sig)(char *pvid_id);
    return lib.get<func_sig>("DLL_Symbol")(pid);
}
c++ preprocessor
1个回答
1
投票
#define __cdecl

再简单不过了])>

© www.soinside.com 2019 - 2024. All rights reserved.