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可以看作一种仓库,仓库中包含了可以直接使用的变量,函数或类. 仓库的发展史经历了"无库" ---& ...
随机推荐
- Vagrant 手册之 Vagrantfile - 配置版本
原文地址 配置版本是 Vagrant 1.1+(引入了大量新功能和配置选项) 能够与 Vagrant 1.0.x Vagrantfiles 保持向后兼容的机制. 现在运行 vagrant init 时 ...
- poj2431Expedition
A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Being rather poo ...
- hdu6699Block Breaker
Problem Description Given a rectangle frame of size n×m. Initially, the frame is strewn with n×m squ ...
- ICPC2019上海区域赛 部分题解(正在更新)
K. Color Graph 题意: 给定一个简单图,点个数<=16,删去部分边后,使得该图中无边数为奇数得环,问剩下的边数最大为多少? 思路: 如果一个图中无奇数边的环,那么这个图一定是个二分 ...
- c#Cache的用法
public class Cache { /// <summary> /// 获取数据缓存 /// </summary> /// <param name="ca ...
- jvm 这我就能会了 擦
最近老有人问jvm,恕我直言,完蛋了,不会,慢慢学吧,开始第一个学习,后续补充,走起... 我看的他的https://www.cnblogs.com/dingyingsi/p/3760447.html ...
- 凸包模板——Graham扫描法
凸包模板--Graham扫描法 First 标签: 数学方法--计算几何 题目:洛谷P2742[模板]二维凸包/[USACO5.1]圈奶牛Fencing the Cows yyb的讲解:https:/ ...
- break和continue能否跳出函数
int func() { printf("In func, before continue.\n"); // continue; break; printf("In fu ...
- c# 获取 Apk ,Aar 文件包名
最近项目有个需求,需要拿到前端上传的Apk或者Aar文件里面的包名. 在这里贡献出来,方便有需求的小伙伴. 项目是 asp.net core 2.2 需要安装 nuget : AndroidXml S ...
- NGUI的拖拽和放下功能的制作,简易背包系统功能(drag and drop item)
一我们添加sprite,给sprite添加背景图片和添加box collider,但是drag and drop item在attach中是找不到的只能在add component中查找添加,如下图: ...