zoukankan      html  css  js  c++  java
  • DLL文件的引用

      首先我们先要写一个DLL文件:

        我先创建一个win32的DLL工程,在工程中添加了Math.h和Math.cpp文件,具体内容如下:

    Math.h:

    #pragma once
    #include "stdafx.h"
    
    #ifdef API_EXPORT
    #define DLL_EXPORT _declspec(dllexport)
    #else
    #define DLL_EXPORT _declspec(dllimport)
    #endif
    
    DLL_EXPORT int Add(int x, int y);
    
    class DLL_EXPORT CMath {
    public:
        int Sub(int x, int y);
    };

    Math.cpp:

    #include "StdAfx.h"
    #define API_EXPORT
    #include "Math.h"
    
    int Add(int x, int y) {
        return x+y;
    }
    
    int CMath::Sub(int x, int y) {
        return x-y;
    }

    简单的解释:

              

                  

      现在我们创建一个win32工程,接着引用我们写好的DLL文件:

    使用示例:

    #include "stdafx.h"
    #include "..\DllUsageMath.h"
    #pragma comment(lib, "..\DllTest.lib")
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        CMath math;
        int a = math.Sub(7, 3);
        int sum = Add(4, 5);
        printf("%d %d
    ", sum, a);
        getchar();
        return 0;
    }

      必须注意的是下面几点:

      1.引入文件

              

      2.放置好你的DLL位置

        进入Debug文件夹中放置好你的DLL文件

              

                

  • 相关阅读:
    并发编程-操作系统简史,多道技术
    python下的excel表格处理 内含面试题
    epoll模型的探索与实践
    nginx搭建静态网站
    面向对象基础
    python+Django 下JWT的使用
    linux的history命令
    携程apollo配置中心Quick Start
    redis哨兵
    redis的主从复制
  • 原文地址:https://www.cnblogs.com/rayguo/p/3651979.html
Copyright © 2011-2022 走看看