DLL代码:

// TestDynamic.cpp: implementation of the TestDynamic class.
//
////////////////////////////////////////////////////////////////////// #include "TestDynamic.h"
#include <windows.h> //////////////////////////////////////////////////////////////////////
// Construction/Destruction
////////////////////////////////////////////////////////////////////// BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
} __stdcall int Plus(int x, int y)
{
return x + y;
} __stdcall int Sub(int x, int y)
{
return x - y;
} __stdcall int Mul(int x, int y)
{
return x * y;
} __stdcall int Div(int x, int y)
{
return x / y;
}
// TestDynamic.h: interface for the TestDynamic class.
//
////////////////////////////////////////////////////////////////////// #if !defined(AFX_TESTDYNAMIC_H__5BBAD36E_608D_4D94_B6D6_19404806F6AE__INCLUDED_)
#define AFX_TESTDYNAMIC_H__5BBAD36E_608D_4D94_B6D6_19404806F6AE__INCLUDED_ #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000 extern "C" __declspec(dllexport) __stdcall int Plus(int x, int y); extern "C" __declspec(dllexport) __stdcall int Sub(int x, int y); extern "C" __declspec(dllexport) __stdcall int Mul(int x, int y); extern "C" __declspec(dllexport) __stdcall int Div(int x, int y); #endif // !defined(AFX_TESTDYNAMIC_H__5BBAD36E_608D_4D94_B6D6_19404806F6AE__INCLUDED_)

调用程序主代码:

// TestDll.cpp : Defines the entry point for the console application.
// 隐式调用 #include "stdafx.h" #pragma comment(lib,"testDynamic.lib"); extern "C" __declspec(dllimport) __stdcall int Plus(int x, int y);
extern "C" __declspec(dllimport) __stdcall int Sub(int x, int y);
extern "C" __declspec(dllimport) __stdcall int Mul(int x, int y);
extern "C" __declspec(dllimport) __stdcall int Miv(int x, int y); int main(int argc, char* argv[])
{
int t = Plus(,);
printf("%d\n",t);
return ;
}
// TestDll.cpp : Defines the entry point for the console application.
// 显式调用 #include "stdafx.h"
#include <windows.h> typedef int (__stdcall *lpPlus)(int, int);
typedef int (__stdcall *lpSub)(int, int);
typedef int (__stdcall *lpMul)(int, int);
typedef int (__stdcall *lpDiv)(int, int); int main(int argc, char* argv[])
{
lpPlus myPlus;
lpSub mySub;
lpMul myMul;
lpDiv myDiv; HINSTANCE hModule = LoadLibrary("testDynamic.dll");
myPlus = (lpPlus)GetProcAddress(hModule, "Plus"); int x = myPlus(,);
printf("%d\n",x); return ;
}

PS:注意__stdcall如果DLL中没有定义为__stdcall在调用时就不要用

windows c dll的创建与调用的更多相关文章

  1. C#中调用c++的dll具体创建与调用步骤,亲测有效~

    使用的工具是VS2010哦~其他工具暂时还没试过 我新建的工程名是my21dll,所以会生成2个同名文件.接下来需要改动的只有画横线的部分 下面是my21dll.h里面的... 下面的1是自动生成的不 ...

  2. C#中调用c++的dll具体创建与调用步骤,亲测有效~ (待验证)

    使用的工具是VS2010哦~其他工具暂时还没试过 我新建的工程名是my21dll,所以会生成2个同名文件.接下来需要改动的只有画横线的部分 下面是my21dll.h里面的... 下面的1是自动生成的不 ...

  3. 在VC中创建并调用DLL

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

  4. 关于DLL的创建与使用简单描述(C++、C#)

    前言 前一段时间在学关于DLL的创建与调用,结果发现网络上一大堆别人分享的经验都有点问题.现在整理分享一下自己的方法. 工具 Microsoft Visual Studio 2017 depends ...

  5. Delphi DLL的创建、静态及动态调用

    转载:http://blog.csdn.net/welcome000yy/article/details/7905463 结合这篇博客:http://www.cnblogs.com/xumenger/ ...

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

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

  7. Python调用windows下DLL详解

    Python调用windows下DLL详解 - ctypes库的使用 2014年09月05日 16:05:44 阅读数:6942 在python中某些时候需要C做效率上的补充,在实际应用中,需要做部分 ...

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

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

  9. Windows下静态库、动态库的创建和调用过程

    静态库和动态库的使用包括两个方面,1是使用已有的库(调用过程),2是编写一个库供别人使用(创建过程).这里不讲述过多的原理,只说明如何编写,以及不正确编写时会遇见的问题. //注:本文先从简单到复杂, ...

随机推荐

  1. OpenStack 计算节点删除

    前提 计算节点中一个僵尸计算节点存在,而里面的CPU数目在总物理CPU中,导致认为当前能创建实例.而实际没有这么多资源. 其中node-11为僵尸节点. 原因 删除计算节点不能直接格式化该服务器,否则 ...

  2. Android 二维码扫描框 加四个角及中间横线自动下滑

    红色为加四个角  黄色为扫描线自动下滑 /* * Copyright (C) 2008 ZXing authors * * Licensed under the Apache License, Ver ...

  3. UIView属性及方法

    @property(nonatomic) CGFloat alpha //设置视图的透明度 //透明度的设置从最小0.0到1.0 ,1.0为完全不透明, //其中这个属性只影响当前视图,并不会影响其子 ...

  4. 为 Macbook 增加锁屏热键技巧

    第一步,找到“系统偏好设置”下的“安全性与隐私”,在“通用”页里勾上“进入睡眠或开始屏幕保护程序后立即要求输入密码”. 第二步,要用快捷键启动屏幕保护程序,相对复杂一点.在“应用程序”里找到“Auto ...

  5. 2015.01.15(android AsyncTask)

    参考网址:http://www.cnblogs.com/devinzhang/archive/2012/02/13/2350070.html /* * Params 启动任务执行的输入参数,比如HTT ...

  6. lz: linux ls 变种 只显示大小和名称(包括目录)

    本次输入法使用: 手心输入法 for Mac 1.0版 测试环境为:Ubuntu 14.14.2 LTS updates 测试时间为:2015年5月28日,感觉死亡将至的夜晚,独自一人坐在一个角落,戴 ...

  7. Length of Last Word

    class Solution { public: int lengthOfLastWord(string s) { ; ; while(s[i]&&s[i]==' ') i++; // ...

  8. Microsoft Office 2013 Product Key

    Microsoft Office 2013 Product Key ( Professional Plus ) PGD67-JN23K-JGVWW-KTHP4-GXR9G B9GN2-DXXQC-9D ...

  9. JavaEE基础(十五)/集合

    1.集合框架(对象数组的概述和使用) A:案例演示 需求:我有5个学生,请把这个5个学生的信息存储到数组中,并遍历数组,获取得到每一个学生信息. Student[] arr = new Student ...

  10. PHP gmdate() 函数

    定义和用法 gmdate() 函数格式化 GMT/UTC 日期/时间. 同 date() 函数 类似,不同的是返回的时间是格林威治标准时(GMT). 语法 gmdate(format,timestam ...