您的位置:首页 > 其它

Windows简易动态库制作方式

2016-02-01 15:20 309 查看
(初步,建立两个空工程)

第一步:

新建 Window32 控制台应用程序,选择空项目。添加文件 DyTest.cpp。

添加测试内容:

#include <stdio.h>
int main()
{
printf("DyTest \n");
}
输出内容 DyTest。

第一步:
新建 Window32 控制台应用程序,选择空项目。添加文件 UseDy.cpp。
添加测试内容:

#include <stdio.h>
int main()
{
printf("UseDy \n");
}
输出内容 UseDy。

(变换,DyTest 为动态库,UseDy 为执行库)
第一步:DyTest 为动态库制作
1) 设置 DyTest 项目,配置类型 dll 动态库
2) 添加输出 def 文件
{

LIBRARY
Run

}
3)提供头接口 DyTest.h
int __declspec(dllexport) Fun();

4) 修改DyTest.cpp 内容为

#include <stdio.h>

void RunTest();

int __declspec(dllexport) Fun()
{
RunTest();
return 0;
}

void RunTest()
{
printf("DyTest\n");
}
第二步:UseDy 为执行库执行
1) 项目添加 DyTest.h 文件
2) 在UseDy.cpp 中添加

#include <stdio.h>
#include "DyTest.h"
#pragma comment(lib,"DyTest.lib")

int main()
{
Fun();
getchar();
}

第三步:
设置编译时连接地址
VC++ 目录, 1) 可执行文件目录,为 E:\MyPro\DyTest\Debug;$(ExecutablePath)
2) 库目录,为 E:\MyPro\DyTest\Debug;$(LibraryPath)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: