dll中函数定义的关键词
2004-07-08 11:20
232 查看
1、extern "C" 是用来告诉编译器,以C的方式来命名,而不要以C++ 的命名法,因为C++ 的命名法会在函式名称後加上参数型态等装饰字,如此会造成其他程式如VC++,VB等无法使用的困扰。
2、__declspec关键字,它可以传入dllimport及dllexport两个参数,用来分别代表输入函数及输出函数。输出函数,必须使用 __declspec(dllexport) 来定义该函数,反之若你要使用输入函数,则你必须使用 __declspec(dllimport) 来定义该函数。
3、Calling Convention
The calling convention options determine the order in which arguments passed to functions are pushed onto the stack; which function, calling or called, removes the arguments from the stack; and the name-decorating convention that the compiler uses to identify individual functions。
_stdcall将参数压栈是按C语言的顺序(从右到左),但与C 语言不同的是它是由被调用者将参数从栈中清除的,所以它的编译文件比_cdecl小。_stdcall是Windows API函数中默认的调用约定,VB、VFP等也采用这个约定。
_cdecl是C语言采用的默认调用方法,它的优点是支持printf这样的可变参数调用。
另外,VC++对于两种调用方法的名称转换方法也不同
例子:
声明函数
extern "C" __declspec(dllexport) 函数类型 __cdecl 函数名(函数参数);
实现函数:
__declspec(dllexport) 函数类型 __cdecl 函数名(函数参数)
2、__declspec关键字,它可以传入dllimport及dllexport两个参数,用来分别代表输入函数及输出函数。输出函数,必须使用 __declspec(dllexport) 来定义该函数,反之若你要使用输入函数,则你必须使用 __declspec(dllimport) 来定义该函数。
3、Calling Convention
The calling convention options determine the order in which arguments passed to functions are pushed onto the stack; which function, calling or called, removes the arguments from the stack; and the name-decorating convention that the compiler uses to identify individual functions。
/Gd | __cdecl | Specifies the C calling convention for all functions that are not C++ member functions or are not marked as __stdcall or __fastcall. This is the default setting. |
/Gr | __fastcall | Specifies the __fastcall calling convention for all functions that are not C++ member functions or are not marked as __cdecl or __stdcall. All __fastcall functions must have prototypes. |
/Gz | __stdcall | Specifies the __stdcall calling convention for all prototyped C functions that do not take a variable number of arguments and are not marked as __cdecl or __fastcall. All __stdcall functions must have prototypes. |
_cdecl是C语言采用的默认调用方法,它的优点是支持printf这样的可变参数调用。
另外,VC++对于两种调用方法的名称转换方法也不同
例子:
声明函数
extern "C" __declspec(dllexport) 函数类型 __cdecl 函数名(函数参数);
实现函数:
__declspec(dllexport) 函数类型 __cdecl 函数名(函数参数)
相关文章推荐
- DLL导出函数和类的定义区别 __declspec(dllexport)
- C#调用C++ DLL 中定义的函数
- DLL中__declspec(dllexport)和.def(模块定义文件)定义导出函数的一点区别
- 导出dll的函数定义
- 将DLL中的导出函数表导出到一定义(.DEF)文件
- 《Composing Programs》学习笔记(1.3)定义新函数(关键词:软件工程/函数)
- 使用 DEF (模块定义) 文件从 DLL 导出函数和类
- python 调用dll中参数为BYTE的函数(注意接口定义的格式)
- 常规dll 的接口函数定义+客户端程序接口函数导入
- dll导出函数定义规范
- DLL中__declspec(dllexport)和.def(模块定义文件)定义导出函数的一点区别
- DllEntryPoint函数在哪里定义
- DLL函数定义和函数实现写函数类型的不同, 引起不能使用Dll中的函数
- Windows_dll的含义和Dependency Walker使用说明( 查找函数定义 )
- wpf 透明效果 需要DwmApi.dll文件,然后定义一个函数去画Aero区域,从而实现整个窗口的Aero化。
- 使用ajax.dll时js脚本错误-XXX未定义
- 袖珍电子书:一元实函数的导数定义
- C++中自己定义函数对象
- Effective C++ Item 36 绝不又一次定义继承而来的 non-virtual 函数
- DLL导出函数方法以及动态调用