zoukankan      html  css  js  c++  java
  • 动态链接库DLL

    静态链接库的使用方法

    示例代码:http://pan.baidu.com/s/1i303qZV

    1.创建工程

    image

    2.向工程中添加.cpp 和.h

    3.头文件代码

    #ifdef  MyDLL_API 
    
    #else
    #define  MyDLL_API _declspec(dllexport)
    
    #endif
    MyDLL_API int Add(int a,int b);
    MyDLL_API int Sub(int a,int b);
    4.CPP中的代码
    #define  MyDLL_API _declspec(dllexport)
    #include "DLL.h"
    int Add(int a,int b)
    {
    	return a+b;
    }	
    
    int Sub(int a,int b)
    {
    	return a-b;
    } 
    静态链接库的调用:
    1.讲.DLL .LIB  .H 复制到工程目录下
    2.工程--设置--链接  将.lib文件添加到链接中 多个用空格隔开
    3.添加头文件
    4.直接使用方法
     
    动态链接库的创建:http://pan.baidu.com/s/1qWJlVBm

    1.创建工程

    image

    2.向工程中添加.cpp 和.def

    3.cpp代码

     int _stdcall Add(int a,int b)
    {
    
    	return a+b;
    }	
    
    int  _stdcall Sub(int a,int b)
    {
    	return a-b;
    } 

    3.  .def代码

    LIBRARY DLL
    
    EXPORTS
    Add
    Sub
    动态链接库的使用:
    1.将DLL复制到工程目录下
    2.添加以下代码
    void CTestDllDlg::OnBtAdd() 
    {
    	// TODO: Add your control notification handler code here
    	CString str;
    	HINSTANCE hInst;
    	hInst=LoadLibrary("DLL.dll");
    	typedef int (_stdcall *ADDPROC)(int a,int b);
    	ADDPROC Add=(ADDPROC)GetProcAddress(hInst,"Add");
    	if(!Add)
    	{
    		MessageBox("获取函数地址失败!");
    		return;
    	}
    	str.Format("5+3=%d",Add(5,3));
    	MessageBox(str);
    }
    
    void CTestDllDlg::OnBtSub() 
    {
    	// TODO: Add your control notification handler code here
    	CString str;
    	HINSTANCE hInst;
    	hInst=LoadLibrary("DLL.dll");
    	typedef int (_stdcall *SUBPROC)(int a,int b);
    	SUBPROC Sub=(SUBPROC)GetProcAddress(hInst,"Sub");
    	if(!Sub)
    	{
    		MessageBox("获取函数地址失败!");
    		return;
    	}
    	str.Format("5-3=%d",Sub(5,3));
    	MessageBox(str);
    }
    
     
  • 相关阅读:
    1,巡检脚本pexpect
    Cisco胖AP配置上网
    阿里云服务器更换密钥后,无论以何种远程连接方式都连接不上
    [PAT乙级题解]——A+B和C
    研究ThreadLocal类
    Java的反射机制
    volatile浅析
    Java 对称数据加密AES
    Java使用非对称数据加密RSA
    练习-登陆接口
  • 原文地址:https://www.cnblogs.com/yuqilihualuo/p/4198977.html
Copyright © 2011-2022 走看看