• VS2010创建动态链接库并且使用动态链接库DLL


    1.编写动态链接库文件 dll和lib文件

    例子:

    在新建VS工程时选择DLL 空项目

    ----------hello.h--------

    #include <stdio.h>
    #pragma once;

    #ifdef DLL_IMPLEMENT

    #define DLL_API __declspec(dllexport)

    #else

    #define DLL_API __declspec(dllimport)

    #endif

    namespace dayinga
    {

    //导出类

    class DLL_API SimpleDll

    {
    public:

    SimpleDll();

    ~SimpleDll();

    void daying(); //简单方法

    };
    }

    ---------hello.cpp--------------

    #define DLL_IMPLEMENT
    #include "hello.h"
    namespace dayinga
    {

    SimpleDll::SimpleDll()
    {
    }

    SimpleDll::~SimpleDll()
    {
    }
    void SimpleDll::daying()
    {
    printf("hello,world");
    }

    }

    生成以上工程时 会得到 hello.dll和hello.lib两个文件。

    2.调用

    新建一个win32工程

    我们需要三个文件 需要hello.h这个头文件和hello.dll和hello.lib文件。

    在工程属性里包含 hello.dll和hello.lib文件。

    在链接器输入里设置lib

    ------------------usedll.cpp------------------------

    #include "stdafx.h"
    #include "hello.h"
    using namespace dayinga;//使用命名空间

    int _tmain(int argc, _TCHAR* argv[])
    {
    SimpleDll sd;//对象
    sd.daying();
    return 0;
    }

    以上。

  • 相关阅读:
    (六)目标文件目录探测
    (五)物理路径探测
    (四)目标后台的探测
    小妙招
    MFC的一些常用操作
    UNICODE,GBK,UTF-8区别
    c++编程的字符集及其转换
    windows消息的循环机制
    c++ mfc和win32项目
    c++ 一些注意事项
  • 原文地址:https://www.cnblogs.com/xuandi/p/5362476.html
Copyright © 2020-2023  润新知