VC++ 创建及调用Dll
一、_stdcall
被这个关键字修饰的函数,其参数都是从右向左通过堆栈传递的(__fastcall 的前面部分由ecx,edx传), 函数调用在返回前要由被调用者清理堆栈。
这个关键字主要见于Microsoft Visual C、C++。GNU的C、C++是另外一种修饰方式:__attribute__((stdcall))
1.
MathFunsStd.cpp:
int _stdcall add(int a, int b)
{
return a+b;
} int _stdcall subtract(int a, int b)
{
return a-b;
} int _stdcall multiple(int a, int b)
{
return a*b;
}
MathFunsStd.def:
LIBRARY MathFunsStd EXPORTS
add
subtract
multiple
2.MathFuns.cpp
int add(int a, int b)
{
return a+b;
} int subtract(int a, int b)
{
return a-b;
} int multiple(int a, int b)
{
return a*b;
}
MathFuns.def
LIBRARY MathFuns EXPORTS
add
subtract
multiple
3.UseHeaderAPI
MathFunsUseHeader.h
#ifdef MathFunsUseHeaderAPI
#else
#define MathFunsUseHeaderAPI _declspec(dllimport)
#endif MathFunsUseHeaderAPI int add(int a,int b);
MathFunsUseHeaderAPI int subtract(int a,int b);
MathFunsUseHeaderAPI int multiple(int a, int b); #define MathFunsUseHeaderAPI _declspec(dllexport)
#include "MathFunsUseHeader.h"
MathFunsUseHeader.cpp
int add(int a, int b)
{
return a+b;
} int subtract(int a, int b)
{
return a-b;
} int multiple(int a, int b)
{
return a*b;
}
三、调用
/*加载dll函数调用方式为默认调用方式*/
HINSTANCE hInst = LoadLibrary(L"MathFuns.dll");
if(!hInst)
{
printf("加载MathFuns.dll失败!\n");
}
typedef int (*MathFunsAPI)(int a, int b);//定义函数指针变量类型
MathFunsAPI Add = (MathFunsAPI)::GetProcAddress(hInst,"add");
printf("5+3=%d\n",Add(,));
::FreeLibrary(hInst); //调用dll函数调用方式为_stdcall
HINSTANCE hInstStd = ::LoadLibrary(L"MathFunsStd.dll");
if(!hInstStd)
{
printf("加载MathFunsStd.dll失败!\n");
}
typedef int (_stdcall *MathFunsStdAPI)(int a, int b);//定义函数指针变量类型
MathFunsStdAPI AddStd = (MathFunsStdAPI)::GetProcAddress(hInstStd,"add");
printf("5+3=%d\n",AddStd(,));
::FreeLibrary(hInst); return ;
VC++ 创建及调用Dll的更多相关文章
- VC++创建、调用dll的方法步骤
文章来源:http://www.cnblogs.com/houkai/archive/2013/06/05/3119513.html 代码复用是提高软件开发效率的重要途径.一般而言,只要某部分代码具有 ...
- VC++:创建,调用Win32动态链接库
VC++:创建,调用Win32动态链接库 概述 DLL(Dynamic Linkable Library)动态链接库,Dll可以看作一种仓库,仓库中包含了可以直接使用的变量,函数或类.仓库的发展史经历 ...
- 在VC中创建并调用DLL
转自:http://express.ruanko.com/ruanko-express_45/technologyexchange6.html 一.DLL简介 1.什么是DLL? 动态链接库英文为DL ...
- C++在VS下创建、调用dll
转自:http://www.cnblogs.com/houkai/archive/2013/06/05/3119513.html 目录 1.dll的优点 代码复用是提高软件开发效率的重要途径.一般而言 ...
- C++ Builder创建和调用dll中的资源
程序开发中经常会用到一些图标.图片.光标.声音等,我们称它们为资源(Resource).当多个窗口用到同样的资源时,可以将这些公共的资源放到一个dll文件里调用,这样,由于定位资源比在磁盘中定位文件花 ...
- QT创建与调用Dll方法(包括类成员)--显式调用
看网上的好多关于QT调用Dll的方法,大部分都是调用函数的,并没有调用C++类成员的情况,即使是有,比如说: 使用Qt编写模块化插件式应用程序 Qt 一步一步实现dll调用(附源码)---(这一篇里没 ...
- VC++:创建,调用MFC动态链接库(扩展DLL)
概述 DLL(Dynamic Linkable Library)动态链接库,Dll可以看作一种仓库,仓库中包含了可以直接使用的变量,函数或类. 仓库的发展史经历了"无库" ---& ...
- DLL模块:C++在VS下创建、调用dll
1.dll的优点 代码复用是提高软件开发效率的重要途径.一般而言,只要某部分代码具有通用性,就可将它构造成相对独立的功能模块并在之后的项目中重复使用.比较常见的例子是各种应用程序框架,ATL.MFC等 ...
- VC++:创建,调用Win32静态链接库
概述 DLL(Dynamic Linkable Library)动态链接库,Dll可以看作一种仓库,仓库中包含了可以直接使用的变量,函数或类. 仓库的发展史经历了"无库" ---& ...
随机推荐
- RESTful再理解
目录 目录 前言 RESTful的目的 REST的含义 表现层 状态转化 无状态协议HTTP 最后 前言 这是在经过一段时间的积累后,对RESTFul框架的再一次更深入的理解.希望能够将零散的知识点连 ...
- ICPC2019上海区域赛 部分题解(正在更新)
K. Color Graph 题意: 给定一个简单图,点个数<=16,删去部分边后,使得该图中无边数为奇数得环,问剩下的边数最大为多少? 思路: 如果一个图中无奇数边的环,那么这个图一定是个二分 ...
- ichunqiu在线挑战--网站综合渗透实验 writeup
挑战链接:http://www.ichunqiu.com/tiaozhan/111 知识点:后台弱口令,md5破解,SQL Injection,写一句话木马,敏感信息泄露, 提权,登陆密码破解 这个挑 ...
- 为什么 Kafka 速度那么快?
来源:cnblogs.com/binyue/p/10308754.html Kafka的消息是保存或缓存在磁盘上的,一般认为在磁盘上读写数据是会降低性能的,因为寻址会比较消耗时间,但是实际上,Kafk ...
- 【洛谷p1025】数的划分
数的划分[传送门] 算法的话,dfs+剪枝: 据说是01年之前的NOIp提高组: 思路: 这道题是求把n无序的划分成k份的方案数,最直接的搜索方法是依次枚举x1,x2……xk的值,然后判断,显然这么搜 ...
- Vue对象的生命周期
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- F Find the AFei Numbers
链接:https://ac.nowcoder.com/acm/contest/338/F来源:牛客网 题目描述 AFei loves numbers. He defines the natural n ...
- 图标,空格,大小尖括号,段落,换行,标题,div白板,span白板
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 在html模板里面加python函数(simple_tag与filter)
自定义函数 simple_tag a. app下创建templatetags目录 b. 任意xxoo.py文件 c. 创建template对象 register d. @register.simple ...
- Redis和Ehcached的区别
Redis 属于独立的运行程序,需要单独安装后,使用JAVA中的Jedis来操纵.因为它是独立,所以如果你写个单元测试程序,放一些数据在Redis中,然后又写一个程序去拿数据,那么是可以拿到这个数据的 ...