`
- 浏览:
12066 次
- 性别:
- 来自:
北京
-
_declspec(dllexport)修饰符的用法
在要输出的函数、类、数据的声明前加上_declspec(dllexport)的修饰符,表示输出。__declspec(dllexport)在C调用约定、C编译情况下可以去掉输出函数名的下划线前缀。extern"C"使得在C++中使用C编译方式成为可能。在“C++”下定义“C”函数,需要加extern“C”关键词。用extern"C"来指明该函数使用C编译方式。输出的“C”函数可以从“C”代码里调用。例如,在一个C++文件中,有如下函数:extern"C"{void__declspec(dllexport)__cdeclTest(intvar);}其输出函数名为:TestMFC提供了一些宏,就有这样的作用。AFX_CLASS_IMPORT:__declspec(dllexport)AFX_API_IMPORT:__declspec(dllexport)AFX_DATA_IMPORT:__declspec(dllexport)AFX_CLASS_EXPORT:__declspec(dllexport)AFX_API_EXPORT:__declspec(dllexport)AFX_DATA_EXPORT:__declspec(dllexport)AFX_EXT_CLASS:#ifdef_AFXEXTAFX_CLASS_EXPORT#elseAFX_CLASS_IMPORTAFX_EXT_API:#ifdef_AFXEXTAFX_API_EXPORT#elseAFX_API_IMPORTAFX_EXT_DATA:#ifdef_AFXEXTAFX_DATA_EXPORT#elseAFX_DATA_IMPORT像AFX_EXT_CLASS这样的宏,如果用于DLL应用程序的实现中,则表示输出(因为_AFX_EXT被定义,通常是在编译器的标识参数中指定该选项/D_AFX_EXT);如果用于使用DLL的应用程序中,则表示输入(_AFX_EXT没有定义)。要输出整个的类,对类使用_declspec(_dllexpot);要输出类的成员函数,则对该函数使用_declspec(_dllexport)。如:classAFX_EXT_CLASSCTextDoc:publicCDocument{…}extern"C"AFX_EXT_APIvoidWINAPIInitMYDLL();这几种方法中,最好采用第三种,方便好用;其次是第一种,如果按顺序号输出,调用效率会高些;最次是第二种。
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
__declspec(dllexport)和__declspec(dllimport)的区别是什么
在win32sdk / c 命令行下用__declspec(dllexport)导出函数名字和全局变量.
摘要:VC/C++源码,其它分类,关键字 VC++使用关键字_declspec (dllexport)导出函数,编译后将生成Test.dll文件。
VC 利用关键字_declspec (dllexport)导出函数,编译后将生成Test.dll文件。。。参考价值更大于使用价值。欢迎下载。没有截图哦,因为只有一个DLL。
extern "C" __declspec(dllexport) bool TifOpen(char* filename,char* model); extern "C" __declspec(dllexport) bool TifClose(); extern "C" __declspec(dllexport) int GetTifWidth(); extern "C" __declspec...
declspec(dllexport)与_declspec(dllimport)的区别
C++__declspec关键字详细用法
C++__declspec关键字详细用法[文].pdf
扩展修饰符: 1:align(#) 用__declspec(align(#))精确控制用户自定数据的对齐方式 ,#是对齐值。 e.g __declspec(align(32)) struct Str1{ int a, b, c, d, e; }; 它与#pragma pack()是一对兄弟,前者规定了对齐...
c++中__declspec的用法.pdf
摸索了两天了,终于解决了所有问题,在此跟大家分享。...#define DLL_DEMO extern "C" __declspec(dllexport) #else #define DLL_DEMO extern "C" __declspec(dllimport) #endif DLL_DEMO int __stdcall Add(int a, int
__declspec(dllexport) windows到linux的转换: windows下: #include #include #include #include using namespace std; #define FF(a,b) for(a=0;a<b;a++) extern C { __declspec(dllexport) void ...
一步一步学习Visual Studio 2015 Community创建DLL,整体来看和Visual ...#define VSAPI _declspec(dllexport) #else #define VSAPI _declspec(dllimport) #endif #define EVSAPI extern "C" VSAPI #endif