• dll动态调用


    dll项目:

    //MyDll2.dll
    #include "windows.h"
    #include "stdio.h"
    
    int _stdcall add(int a,int b){
    	return a+b;
    }
    
    int _stdcall substract(int a,int b){
    	return a-b;
    }
    //////////////////////////////////////////////////////////////////
    //MyDll2.def--模块定义文件
    
    LIBRARY MyDll2
    EXPORTS
    add
    substract
    

    Client项目:

    //Client.cpp
    //...
    void CMyDllTestDlg::OnButtonSubstract() 
    {
    /*
    	CString str;
    	str.Format("5-3=%d",substract(5,3));
    	MessageBox(str);
    	*/
    	HMODULE hIns = LoadLibrary("MyDll2.dll");
    	if(!hIns){
    		MessageBox("动态链接库加载失败");
    		return ;
    	}
    	typedef int (_stdcall * FUN_ADD)(int,int);
    	FUN_ADD add;
    	add =(FUN_ADD)GetProcAddress (hIns,"substract");
    	if(!add){
    		MessageBox("函数地址获取失败");
    		return ;
    	}
    	CString str;
    	str.Format("5+3=%d",add(5,3));
    	MessageBox(str);
    	FreeLibrary(hIns);
    }
    //...
    

    dll调用方式:动态加载,隐式链接。

    隐式链接也是用LoadLibrary去加载,故动态加载效率高,且用dumpbin -exports *.dll查看不到依赖函数,但编程较繁琐。

  • 相关阅读:
    HTML_常用标签
    介绍Html_前端
    Mysql(2)数据类型与约束
    Mysql命令
    python_高级进阶(5)协程_事件
    python_高级进阶(4)同步_异步_回调函数_阻塞
    数据类型的补充以及各类型之间的相互转换
    二次编码
    坑坑坑坑坑坑----列表
    字典
  • 原文地址:https://www.cnblogs.com/wucg/p/1950261.html
Copyright © 2020-2023  润新知