一、_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的更多相关文章

  1. VC++创建、调用dll的方法步骤

    文章来源:http://www.cnblogs.com/houkai/archive/2013/06/05/3119513.html 代码复用是提高软件开发效率的重要途径.一般而言,只要某部分代码具有 ...

  2. VC++:创建,调用Win32动态链接库

    VC++:创建,调用Win32动态链接库 概述 DLL(Dynamic Linkable Library)动态链接库,Dll可以看作一种仓库,仓库中包含了可以直接使用的变量,函数或类.仓库的发展史经历 ...

  3. 在VC中创建并调用DLL

    转自:http://express.ruanko.com/ruanko-express_45/technologyexchange6.html 一.DLL简介 1.什么是DLL? 动态链接库英文为DL ...

  4. C++在VS下创建、调用dll

    转自:http://www.cnblogs.com/houkai/archive/2013/06/05/3119513.html 目录 1.dll的优点 代码复用是提高软件开发效率的重要途径.一般而言 ...

  5. C++ Builder创建和调用dll中的资源

    程序开发中经常会用到一些图标.图片.光标.声音等,我们称它们为资源(Resource).当多个窗口用到同样的资源时,可以将这些公共的资源放到一个dll文件里调用,这样,由于定位资源比在磁盘中定位文件花 ...

  6. QT创建与调用Dll方法(包括类成员)--显式调用

    看网上的好多关于QT调用Dll的方法,大部分都是调用函数的,并没有调用C++类成员的情况,即使是有,比如说: 使用Qt编写模块化插件式应用程序 Qt 一步一步实现dll调用(附源码)---(这一篇里没 ...

  7. VC++:创建,调用MFC动态链接库(扩展DLL)

    概述 DLL(Dynamic Linkable Library)动态链接库,Dll可以看作一种仓库,仓库中包含了可以直接使用的变量,函数或类. 仓库的发展史经历了"无库" ---& ...

  8. DLL模块:C++在VS下创建、调用dll

    1.dll的优点 代码复用是提高软件开发效率的重要途径.一般而言,只要某部分代码具有通用性,就可将它构造成相对独立的功能模块并在之后的项目中重复使用.比较常见的例子是各种应用程序框架,ATL.MFC等 ...

  9. VC++:创建,调用Win32静态链接库

    概述 DLL(Dynamic Linkable Library)动态链接库,Dll可以看作一种仓库,仓库中包含了可以直接使用的变量,函数或类. 仓库的发展史经历了"无库" ---& ...

随机推荐

  1. Python web自动化测试框架搭建(功能&接口)——unittest介绍

    Python UnitTest测试框架介绍 1)         TestCase:所有测试用例类继承的基本类, TestCase的实例就是测试用例 2)         TestSuite:测试套件 ...

  2. (appium+python)UI自动化_10_adb常用命令

    前言 adb(Android Debug Bridge)工具是android-sdk里的一个工具,是一个命令行窗口,用于通过电脑端与模拟器或者真实设备交互.在app自动化测试过程中,有时要用到adb命 ...

  3. 10.jmeter jsr223 javascript 深度比对json object

    function sortJSON(data, key, way) { //log.info(" " + key + " ------------------- &quo ...

  4. jQuery基础--jQuery特殊属性操作

    1.index() 会返回当前元素在所有兄弟元素里面的索引. <!DOCTYPE html> <html lang="zh-CN"> <head> ...

  5. javaweb的Filter过滤器设置全站编码

    FIlter配置全站编码有一种方法是重写getParameter方法,也就是继承HttpServletRequestWrapper在重写getParameter方法,还有一种就是如下: public ...

  6. linux下shell显示git当前分支

    function git-branch-name { git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3 } functio ...

  7. [Bzoj1047][HAOI2007]理想的正方形(ST表)

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1047 题目虽然有一个n的限制,但求二维区间最值首先想到的还是RMQ,但是如果按照往常RM ...

  8. python第一部分小结

       1.python的种类                                                                              Cpython: ...

  9. 【接口工具】接口抓包工具之Charles

    上篇我们讲了Fiddler,Fiddler是用C#开发的,所以Fiddler不能在Mac系统中运行,没办法直接用Fiddler来截获MAC系统中的HTTP/HTTPS, Mac 用户怎么办呢? 1.F ...

  10. shell --08 例子

    目录 1.按照时间生成文件2018-05-22.log将每天的磁盘使用状态写入到对应日期的文件 [root@web01 ceshi]# cat 1.sh #!/bin/bash Date=`date ...