VS2017——C语言dll编译并调用

 

VS2017——C语言dll编译并调用

标签: VS2017 C语言 DLL编译
4789人阅读  评论(0)  收藏  举报
  分类:
C语言

目录(?)[+]

1.生成dll

1.1文件——新建——项目,选择如下图





1.2新建头文件test.h和源文件test.c

[cpp]  view plain  copy
  1. //test.h  
  2. __declspec(dllexportint sum(int a, int b);  


[cpp]  view plain  copy
  1. //test.c  
  2. #include "test.h"  
  3. #include <stdio.h>  
  4.   
  5. int sum(int a, int b) {  
  6.     return a + b;  
  7. }  



1.3右击项目选择生成,在debug中会产生多个文件,我们只需要dllgen.dll和dllgen.lib


2.调用dll

2.1文件——新建——项目——空项目


2.2将dllgen工程中的test.h、dllgen.dll、dllgen.lib拷贝到当前工程下



2.3在工程中添加test.h,同时新建main.c



[cpp]  view plain  copy
  1. //main.c  
  2. #include "test.h"  
  3. #include<stdio.h>  
  4. #include<stdlib.h>  
  5.   
  6. #pragma comment(lib,"dllgen.lib")  
  7.   
  8. void main() {  
  9.     int n;  
  10.     n = sum(10, 6);  
  11.     printf("10 + 6 = %d\n",n);  
  12.     system("pause");  
  13. }  
2.4运行项目,查看测试结果

  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值