使用mingw制作dll文件
使用mingw制作dll文件
准备math.c文件
//math.c
#include<stdio.h>
int add(int a,int b){
return a+b;
}
int sub(int a,int b){
return a-b;
}
int mul(int a,int b){
return a*b;
}
int div(int a,int b){
return a/b;
}
制作dll
gcc math.c -shared -o math.dll -Wl,--out-implib,math.lib
生成 math.dll、math.lib
验证dll
编写加载dll文件的代码
#include<stdio.h>
#include <windows.h>
typedef int (*AddFunc)(int ,int);
typedef int (*SubFunc)(int ,int);
typedef int (*MulFunc)(int ,int);
typedef int (*DivFunc)(int ,int);
int main(void)
{
int a=10,b=2;
HMODULE hDll = LoadLibrary("math.dll");
if (hDll != NULL)
{
AddFunc add = (AddFunc)GetProcAddress(hDll, "add");
SubFunc sub = (SubFunc)GetProcAddress(hDll, "sub");
MulFunc mul = (MulFunc)GetProcAddress(hDll, "mul");
DivFunc div = (DivFunc)GetProcAddress(hDll, "div"); if (add != NULL)
printf("a+b=%d\n",add(a,b));
if (sub != NULL)
printf("a-b=%d\n",sub(a,b));
if (mul != NULL)
printf("a*b=%d\n",mul(a,b));
if (div != NULL)
printf("a/b=%d\n",div(a,b)); FreeLibrary(hDll);
}
}
编译
gcc loaddll_dynamic_show.c -o loaddll_dynamic_show.exe运行
loaddll_dynamic_show.exe结果
a+b=12
a-b=8
a*b=20
a/b=5
使用mingw制作dll文件的更多相关文章
- Visual C# 制作DLL文件
一.制作.dll1.首先创建一个新类库工程文件 文件->新建->项目->Visual C#->类库.填入工程文件名称,并且选择文件要存放的目录. 2.工程文件 将Class1 ...
- 制作和unity调用动态链接库dll文件
首先用vc建立一个dll工程 然后在里面建立一个testunity.h文件.内容如下 1 extern "C" int _declspec(dllexport)testunity( ...
- c# 制作自定义控件并生成dll文件旷展到其他项目使用
1.新建项目,同时添加一个类库,然后在类库里面定义自己的控件:完毕生成项目,然后在类库的bin目录下就自动生成了这个自定义控件的dll文件. 2.在需要使用这个自定义控件的项目里,直接ctrl+c,c ...
- MSVC vs. MinGW 之dll玩转攻略手记【转
一份粗糙的研究记录,有待补完和整理. MinGW:c -> o gcc -c a.cc -> exe gcc a.c libs.o -o a.exe ( ...
- 制作dll自动注册工具
记录一个简单的dll自动注册工具制作:主要用到的是DllRegisterServer()方法,其实我们平常注册dll文件内部都会调用这个方法. 这里我就直接写在主程序里面了,需要注意的地方也直接在代码 ...
- NSIS使用教程(安装包制作安装文件教程,如何封装打包文件) 中文版
nsis中文版(Nullsoft Scriptable Install System)是一个专业的开源的可以用来封闭Windows程序的实用工具,是一个开源的 Windows 系统下安装程序制作程序. ...
- Delphi 使用之dll文件生成与调用
DLL是Dynamic-Link Libraries(动态链接库)的缩写,库里面是一些可执行的模块以及资源(如位图.图标等).可以认为DLL和EXE基本上是一回事,只是DLL不能直接执行,而必须由应用 ...
- Delphi制作DLL
一.开使你的第一个DLL专案 1.File->Close all->File->New﹝DLL﹞ 代码: //自动产生Code如下 library Project2; //这有段废话 ...
- 用C#制作PDF文件全攻略
用C#制作PDF文件全攻略 目 录 前 言... 3 第一部分 iText的简单应用... 4 第一章 创建一个Document 4 第一步 创建一个Document实例:... 5 第二步 ...
随机推荐
- PatentTips - Device virtualization and assignment of interconnect devices
BACKGROUND Standard computer interconnects, particularly for personal computers or workstations, may ...
- UVA 558 Wormholes 【SPFA 判负环】
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- PAT-中国大学MOOC-陈越、何钦铭-数据结构基础习题集 00-自測4. Have Fun with Numbers (20) 【二星级】
题目链接:http://www.patest.cn/contests/mooc-ds/00-%E8%87%AA%E6%B5%8B4 题面: 00-自測4. Have Fun with Numbers ...
- Bmob移动后端云服务平台--Android从零開始--(一)何为Bmob
Bmob移动后端云服务平台--Android从零開始--(一)何为Bmob 在正式的项目开发中,单client不能满足我们的需求,须要实现client与服务端的连接. 而在编写Android服务端代码 ...
- java 链接server上的 mongodb 出现 connect time out 问题
异常信息 十二月 22, 2014 5:27:58 下午 com.mongodb.DBTCPConnector initDirectConnection 警告: Exception executing ...
- Exercise : Self-Taught Learning
First, you will train your sparse autoencoder on an "unlabeled" training dataset of handwr ...
- 经典的横线中间文字css布局---flex布局
html: <div class="title"> <div class="line"></div> <div cla ...
- 【Codeforces Round #427 (Div. 2) B】The number on the board
[Link]:http://codeforces.com/contest/835 [Description] 原本有一个数字x,它的各个数码的和原本是>=k的; 现在这个数字x,在不改变位数的情 ...
- [置顶]
Docker学习总结(1)——Docker实战之入门以及Dockerfile(一)
一.Docker是什么? 首先Docker是软件工业上的集装箱技术 回顾,在没有集装箱出现以前,传统运输行业中,会存在这些问题: 在运输过程中,货物损坏 装卸.运输货物,效率低下 运输手续繁多及运输环 ...
- Word Ladder II [leetcode]
本题有几个注意点: 1. 回溯找路径时.依据路径的最大长度控制回溯深度 2. BFS时,在找到end单词后,给当前层做标记find=true,遍历完当前层后结束.不须要遍历下一层了. 3. 能够将字典 ...