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. NOIP201405生活大爆炸版石头剪刀布

    NOIP201405生活大爆炸版石头剪刀布 试题描述 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一 样,则不分胜负.在<生活大爆炸>第二季第 8 集中出现了 ...

  2. 【转】C#访问权限修饰符

    C#访问权限修饰符 C#中类及类型成员修饰符有以下四类:public,private,protected,internal. public        类及类型成员的修饰符 private 类型成员 ...

  3. DirectX 绘制

    先上图.后面会描写 ,细节

  4. PHP学习当中遗漏的知识点

    一, 当双引号中包含变量时,变量会与双引号中的内容连接在一起: 当单引号中包含变量时,变量会被当做字符串输出. <?php $love = "I love you!"; $s ...

  5. C++:FMC 错误

    1.generated debug assertion -- File: docsingl.cpp Line: 215 MFC程序vs2008编译通过,运行时出错,无法打开,提示f:\dd\xxxx的 ...

  6. YTU 2297: KMP模式匹配 三(串)

    2297: KMP模式匹配 三(串) 时间限制: 1 Sec  内存限制: 128 MB 提交: 25  解决: 16 [提交][状态][讨论版] [Edit] [TestData] 题目描述 输入一 ...

  7. Linux内存模型

    http://blog.csdn.net/sunyubo458/article/details/6090946 了解linux的内存模型,或许不能让你大幅度提高编程能力,但是作为一个基本知识点应该熟悉 ...

  8. eclipse字体推荐

    首先大家可以看看这里面推荐的最佳十款字体,http://www.iteye.com/news/11102-10-great-programming-font 但是经过测试发现,排名第一的字体在ecli ...

  9. An error occurred while filtering resources-----maven项目报错

    解决办法 需要在pom中设定jdk的版本 <plugins> <!-- compiler插件, 设定JDK版本 --> <plugin> <groupId&g ...

  10. 为Python添加默认模块搜索路径

    方法一:函数添加1 import sys2 查看sys.path3 添加sys.path.append("c:\\") 方法二:修改环境变量w用户可以修改系统环境变量PYTHONP ...