zoukankan      html  css  js  c++  java
  • 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查看不到依赖函数,但编程较繁琐。

  • 相关阅读:
    MySQL之存储引擎
    MySQL之基础功能
    MySQL之正则表达式
    MySQL之数据类型
    MySQL之多表查询
    MySQL之单表查询
    linux命令useradd添加用户详解
    MySQL之数据操作
    MySQL之表操作
    MySQL之库操作
  • 原文地址:https://www.cnblogs.com/wucg/p/1950261.html
Copyright © 2011-2022 走看看