zoukankan      html  css  js  c++  java
  • (转载)VC 动态链接库

    新建一个Win32 Dynamic-Link library工程,取名DLL,选择“An empty DLL project”选项,即创建了一个空的动态链接库工程。为工程添加一个C++源文件:DLL.cpp。举个例子写入两个函数:   

    #define dll _declspec(dllexport)  //导出

    #include "DLL.H"
     int add(int a,int b)
    {
     return a+b;
    }
     int subtract(int a,int b)
    {
     return a-b;
    }

    为工程添加一个C++头文件:DLL.H:

    #ifdef dll
    #else
    #define dll _declspec(dllimport)  //导入
    #endif

    dll int add(int a,int b);
    dll int subtract(int a,int b);

    利用Build命令,生成动态链接库DLL,debug文件夹下有两个文件“*.dll","*.lib"这两个文件就是我们调用动态链接库的所用文件。

       创建一个关于对话框的工程dlltest。将“*.dll","*.lib"两个文件粘贴在工程dlltest的目录下。在工程dlltest中project->setting->Link->object\library modules:下添加"*.lib"。完成动态链接库的链接。

       将工程dlltest包含头文件"DLL.H",创建两个按钮,编辑函数分别调用动态链接库的加减2个函数,编译,连接,使用。

       将程序打包是要注意将“*.dll"文件复制到打包文件夹的目录下。

  • 相关阅读:
    小程序解析html(使用wxParse)
    error: the HTTP rewrite module requires the PCRE library
    CMake Error at cmake/boost.cmake:76 (MESSAGE)
    Centos7安装mysql后无法启动,提示 Unit mysql.service failed to load:No such file or directory
    mysql的三种安装方式
    epel源
    cmake
    yum
    wget
    tar指令
  • 原文地址:https://www.cnblogs.com/ccmfc/p/1844825.html
Copyright © 2011-2022 走看看