VC中调用动态库文件Dll

     对于没有这样编程的友友们,这是一个简单的实例,可能有一定的帮助:

一、创建动态链接库(MFC规则DLL)

       1. New--projects--MFC AppWizard(dll)--Regular DLL using shared MFC DLL //取名为MFC_dll

  2. def文件中添加:函数名(Add_new)

  3. h文件中添加:外部函数声明//求和函数,函数名为Add_new

  extern "C" __declspec(dllexport) int __stdcall Add_new(int a,int b);

  4. cpp文件中添加: 外部函数实现

  

    extern "C" __declspec(dllexport) int __stdcall Add_new(int a,int b)

  {

      return a+b;

  }

      

       5. build--set active configuration--win32 release--ok

  6. 生成

  7. 根目录下release文件夹中dll,lib与根目录下h文件即为所需

 二、调用动态链接库(把MFC_dll.dll和MFC_dll.lib拷到工程所在目录)

       1. new--projects--win32 console application--an empty project

  2. 添加h文件:(test000.h)

  #pragma comment(lib,"MFC_dll.lib") //告诉编译器DLL相对应的lib文件所在路径和文件名

  extern "C" _declspec(dllimport) int _stdcall Add_new(int a,int b);//声明导入函数

 

  3. 添加cpp文件:(main.cpp)

  

#include "test000.h" 
#include <iostream>
using namespace std;

int main()   
{   
	cout<<Add_new(5,6);   
	return 0;   
}


 

      4.编译、链接、运行,结果如图所示:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值