1.VC++2010中新建win32项目,命名为“win32dll”,在应用程序类型中选择dll,在附加选项中选择导出符号,
2.Win32dll项目中自动生成的头文件有stdafx.h,targetver.h,win32dll.h,自动生成的源文件有dllmain.cpp,stdafx.cpp,win32dll.cpp
在win32dll.h中加入以下函数声明:
_declspect(dllexport) int test(int x);
在win32dll.cpp中定义这个函数
int test(int x)
{
return x*x*x;
}
3.编译这个工程,会生成win32dll.dll和win32dll.lib两个文件,这两个文件在下面调用时会用到。
4.调用dll
新建一个win32控制台应用程序,dlltest,把刚才生成的win32dll.dll和win32dll.lib以及win32dll.h放入dlltest目录下面,然后,在dlltest.cpp中写入
# include <windows.h>
# include <iostream>
using namespace std;
# include “win32dll.h”
# pragma comment(lib,”win32dll.dll”)
int main()
{
int a=f(4);
cout<<”the result is ”<<a<<endl;
return 0;
}
原文:http://blog.csdn.net/u011608357/article/details/18862621