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查看不到依赖函数,但编程较繁琐。

  • 相关阅读:
    爬虫简介
    MongoDb安装pymongo和mongoengine使用
    简单使用WebSocket实现聊天室
    DBUtils
    FLASK 的Session和MoudelForm插件
    第十一篇 CBV和闪现
    HDOJ 4699 Editor 对顶栈
    [NOI1999]内存分配
    横截面图
    STL List Set
  • 原文地址:https://www.cnblogs.com/wucg/p/1950261.html
Copyright © 2011-2022 走看看