首页 > 其他 > 详细

动态链接库使用

时间:2016-11-18 22:54:52      阅读:171      评论:0      收藏:0      [点我收藏+]

// 动态链接库测试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;
}

动态链接库使用

原文:http://www.cnblogs.com/zhuh102/p/6078969.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!