DLL导出

DLL导出有两种方式:

  一、使用__declspec(dllexport);

  二、采用模块定义(.def)文件声明,(.def)文件为链接器提供了有关被链接程序的导出、属性及其他方面的信息。(模块定义.def文件);

方式一、使用__declspec(dllexport);

#ifdef DLLWRAP_EXPORTS
#define DLLWRAP_API __declspec(dllexport)
#else
#define DLLWRAP_API __declspec(dllimport)
#endif

导出变量: 

DLLWRAP_API int n;

导出函数: 

DLLWRAP_API int fndllwrap(void) { return 1; }

导出class:

class DLLWRAP_API Cdllwrap {
public:
Cdllwrap(void);
// TODO: add your methods here.
};
// This is the constructor of a class that has been exported.
Cdllwrap::Cdllwrap()
{
return;
}

方式二、采用模块定义.def文件

extern "c" {
    int add(int a, int b);
}

int add(int a, int b)
{
return a +b;
}

test.def

;导出dll函数

DEESCRIPTION

LIBRARY dlltest

EXPORTS

    add @1 PRIVATE

posted @ 2010-11-05 11:12  ybtyoyo  阅读(282)  评论(0编辑  收藏  举报