dll 二次封装

需要用到二次封装,其实很简单,不过在第二个dll调用第一个dll的方法而已。
笔记下以免忘了。
//dll1.h:

#ifndef _dll1_h
#define _dll1_h
#define MYDLL extern "C" _declspec (dllexport)
MYDLL int add(int x,int y);
#endif //_dll1_h

//dll1.cpp

#include "dll1.h"

int add(int x,int y)
{
    return x+y; 
}

//dll2.h

#include "dll1.h"
#pragma comment(lib,"dll1.lib")
#ifndef _dll2_h
#define _dll2_h
#define MYDLL extern "C" _declspec (dllexport)
MYDLL int add_10(int x,int y);
#endif //_dll2_h

//dll2.cpp

#include "dll2.h"
int add_10(int x,int y)
{
    return add(x+y)+10; 
}

//usedll

#include "stdafx.h"

#include "dll1.h"
#pragma comment(lib,"dll1.lib")
#include "dll2.h"
#pragma comment(lib,"dll2.lib")

int main()
{
    cout<<"dll1_add:"<<add(3+6)<<endl;
    cout<<"dll2_add:"<<add_10(3+6)<<endl;
    getchar();
}

Dll的显式链接调用。

typedef int (CALLBACK* LPFun)(int,int);

void callDll()
{ 
    HINSTANCE hDLL; // Handle to DLL
    LPFun pFun;     // Function pointer
    int nParam1,nParam2, nReturnVal;

    hDLL = LoadLibrary("MyDLL");
    if (hDLL != NULL)
    {
       pFun = (LPFun)GetProcAddress(hDLL,"DLLFunc1");
       if (!pFun){
          // handle the error
          FreeLibrary(hDLL);
          return;
       }else{
          // call the function
          nReturnVal = pFun(nParam1, nParam2);
       }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值