1.编写dll函数实现源代码hello.c
#include
int say_hello(char* name)
{
printf( "hello %s\n ", name)
return 1
}
2.编写dll函数输出定义文件hello.def.
LIBRARY hello
EXPORTS
say_hello @1
3.编译dll源码,生成dll,lib文件.
3.1 新建命令行窗口
3.2 设置PATH ?? INCLUDE ?? LIB 3个环境变量.
SET PATH=K:\vcnet\vc7\bin%PATH%
SET INCLUDE=K:\vcnet\vc7\include%INCLUDE%
SET LIB=K:\vsnet\Vc7\lib%LIB%
3.3 编译hello.c
cd K:\Source\dllsample (hello.c和hello.def所在目录)
cl /c hello.c
3.4 链接hello.obj,生成hello.dll,hello.lib两个文件.
link /def:hello.def /dll hello.obj
4.测试dll函数.
4.1 编写测试代码 test.c
extern int say_hello(char* name)
int main(int argc,char** argv)
{
say_hello( "robbie ")
return 0
}
4.2 编译测试代码test.c
cl /c test.c
4.3 链接test.obj和 hello.lib,生成可执行文件test.exe
link test.obj hello.lib
4.4 运行test.exe,屏幕输出:
hello robbie
至此,一个dll构造完毕.
dll制作步骤: 1.编写dll函数实现源代码hello.c #include int say_hello(char* name) { printf( "hello %s\n ", name)return 1} 2.编写dll函数输出定义文件hello.def. LIBRARY hello EXPORTS say_hello @1 3.编译dll源码,生成dll,lib文件. 3....欢迎分享,转载请注明来源:内存溢出
评论列表(0条)