动态链接库使用

// 动态链接库测试2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>


//隐式连接:这种连接方式是由编译器自己加载DLL文件的
/*#pragma comment(lib,"动态链接库2.lib")
extern "C" _declspec(dllimport) int Add(int x,int y);
extern "C" _declspec(dllimport) int Mul(int x,int y);
extern "C" _declspec(dllimport) int Div(int x,int y);
*/


//显示连接    自己加载DLL文件

typedef int(*pAdd)(int ,int);
typedef int(*pMul)(int ,int);
typedef int(*pDiv)(int ,int);



int main(int argc, char* argv[])
{    
    pAdd plus=NULL;
    pMul mul=NULL;
    pDiv div=NULL;
    HINSTANCE hInstance=LoadLibrary("动态链接库2.dll");
    plus=(pAdd)GetProcAddress(hInstance,"Add");//这里的函数名必须是Dll文件名中的函数名
    mul=(pMul)GetProcAddress(hInstance,"Mul");
    div=(pDiv)GetProcAddress(hInstance,"Div");

    int result=plus(4,5);
    printf("%d\n",result);
//第一步加载DLL

    /*int y=Add(100,400);
    printf("Hello World\n%d!\n",y);*/


    return 0;
}

转载于:https://www.cnblogs.com/zhuh102/p/6078969.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值