首页 > 其他 > 详细

DLL文件的引用

时间:2015-05-04 23:58:10      阅读:514      评论:0      收藏:0      [点我收藏+]

  首先我们先要写一个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 "..\\DllUsage\Math.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\n", sum, a);
    getchar();
    return 0;
}

  必须注意的是下面几点:

  1.引入文件

          技术分享

  2.放置好你的DLL位置

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

          技术分享

            技术分享

DLL文件的引用

原文:http://www.cnblogs.com/rayguo/p/3651979.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!