#ifdef __cplusplus extern "C" 笔记
来源:互联网 发布:gta5a卡优化 编辑:程序博客网 时间:2024/05/21 10:53
#ifdef __cplusplus //c++编译环境中才会定义__cplusplus (plus就是"+"的意思)
extern "C" { //告诉编译器下面的函数是c语言函数(因为c++和c语言对函数的编译转换不一样,主要是c++中存在重载)
了解更多可以在MSDN上搜索dllimport dllexport关键字。
extern "C" { //告诉编译器下面的函数是c语言函数(因为c++和c语言对函数的编译转换不一样,主要是c++中存在重载)
#endif
C++编译器编译时生成函数名称的规则和C编译器不一样,如果是在C++中使用用C语言编译器编译生成的库文件,就需要用这个,防止C++编译器链接不到函数。
以下来自MSDN:
使用 __declspec(dllimport) 导入到应用程序中
如果一个程序使用 DLL 定义的公共符号,就说该程序是在导入公共符号。 为使用 DLL 生成的应用程序创建头文件时,在公共符号的声明上使用 __declspec(dllimport)。 不论是用 .def 文件导出还是用__declspec(dllexport) 关键字导出,__declspec(dllimport) 关键字均有效。
若要提高代码的可读性,请为 __declspec(dllimport) 定义一个宏,然后使用此宏声明每个导入的符号:
#define DllImport __declspec( dllimport )DllImport int j;DllImport void func();
在函数声明上使用 __declspec(dllimport) 是可选操作,但如果使用此关键字,编译器将生成更有效的代码。 但是,为使导入的可执行文件能够访问 DLL 的公共数据符号和对象,必须使用 __declspec(dllimport)。 请注意,DLL 的用户仍然需要与导入库链接。
对 DLL 和客户端应用程序可以使用相同的头文件。 为此,请使用特殊的预处理器符号来指示是生成 DLL 还是生成客户端应用程序。 例如:
#ifdef _EXPORTING #define CLASS_DECLSPEC __declspec(dllexport)#else #define CLASS_DECLSPEC __declspec(dllimport)#endifclass CLASS_DECLSPEC CExampleA : public CObject{ ... class definition ... };
0 0
- #ifdef __cplusplus extern "C" 笔记
- #ifdef __cplusplus extern "C" {
- #ifdef __cplusplus extern "C"
- #ifdef __cplusplus extern "C"
- #ifdef __cplusplus extern "C"
- #ifdef __cplusplus extern "C"
- #ifdef __cplusplus extern "C"
- #ifdef __cplusplus extern “C”
- #ifdef __cplusplus extern “C” #endif
- 关于#ifdef __cplusplus extern C
- #ifdef __cplusplus extern "c" { #endif
- #ifdef __cplusplus extern "C" { #endif
- #ifdef __cplusplus extern "C" { #endif
- extern “C"和#ifdef __cplusplus
- //#ifdef __cplusplus extern "C" 含义
- #ifdef __cplusplus extern "C" { #endif /* __cplusplus */
- #ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } #endif
- #ifdef __cplusplus extern "C" { #endif //一段代码 #ifdef __cplusplus } #endif
- 视频编码的基本知识
- 正则获取 某段 DIV 中 的内容
- 第一课 なぜ「辞書」は「引く」のでしょう
- 完成端口(CompletionPort)详解 - 手把手教你玩转网络编程系列之三
- 使用反射机制获取 蓝牙BluetoothDevice API
- #ifdef __cplusplus extern "C" 笔记
- SYSTEM BUS 与APIC BUS 的比较
- Auto Complete -- Typeahead 和DateRangePicker
- Jbpm笔记之二 -- 流程实例-任务
- myeclipse中deploy按钮以及manage deployments按钮无效
- Java线程:线程的调度-让步
- 初创团队的技术选择
- extern声明外部变量
- 【程序设计】CreateThread()与_beginthreadex()的区别