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. TortoiseSVN提交文件的时候卡死

    提交文件的时候卡死,查找很久,才发现原来是IP被修改了,郁闷

  2. 获取CPUID等

    unit CommonUnit; interface uses Windows, SysUtils, DateUtils; Const CPUVendorIDs: .. ] of string = ( ...

  3. innodb double write buffer

    两次写是innodb的一个重要特性,目的是为了保证在异常down机或者没电的情况下,保证数据的安全可靠.一次是往内存的double write buffer中写,一次是在刷共享表空间的连续128个页. ...

  4. 161115、MyBatis 通过包含的jdbcType类型

    MyBatis常用jdbcType类型 BIT         FLOAT      CHAR           TIMESTAMP       OTHER       UNDEFINEDTINYI ...

  5. windows cmd color setup

    设置颜色的话,一般可定会有foreground和background color设置:(其实color /?直接看一下就好了) Color Background Foreground Black 0 ...

  6. oracle 自动关闭 数据库连接

    数据库启动后过一会自动断开连接(大概10分钟)    方法一.直接修改资源配置文件     分三个步骤在sqlplus环境下完成.     第一步,查询资源文件,找到CONNECT_TIME所在的pr ...

  7. Linux命令学习手册-printf命令(转)

    分类: LINUX 参考资料:http://sns.linuxpk.com/space-566-do-blog-id-15819.html printf FORMAT [ARGUMENT]... pr ...

  8. C#中的属性————只谈属性

    废话少说直接一剑封喉--属性是对私有字段的保护(其实是对私有字段引用的另外一种变相公开化),属性在没有任何操作的时候是无法看出其优势来,上例子 // Field used by property.pr ...

  9. ACM题目————Robot Motion

    Description A robot has been programmed to follow the instructions in its path. Instructions for the ...

  10. Android 自定义ScrollView ListView 体验各种纵向滑动的需求

      分类: [android 进阶之路]2014-08-31 12:59 6190人阅读 评论(10) 收藏 举报 Android自定义ScrollView纵向拖动     转载请标明出处:http: ...