Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2056752
  • 博文数量: 454
  • 博客积分: 10921
  • 博客等级: 上将
  • 技术积分: 5396
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-15 15:20
个人简介

伪IT男

文章分类

全部博文(454)

文章存档

2016年(2)

2013年(6)

2012年(17)

2011年(29)

2010年(24)

2009年(54)

2008年(53)

2007年(202)

2006年(67)

分类: C/C++

2007-06-21 21:06:04

1。编写dll
     (1)建立一个dll 工程如 dllsample
     (2)添加一个cpp文件到dllsample工程的源文件中,如dll1.cpp
     (3)在dll1.cpp添加预定义头文件
           #include "StdAfx.h"  
     (4)在dll1.cpp添加dll函数的声明
       _declspec(dllexport) int plus(int x,int y);
     (5)在dll1.cpp添加dll函数的实现
        int plus(int x,int y)
           {
            return x+y;
            }
      (6)编译,连接,会看到在debug或release目录下有dllsample.lib和dllsample.dll两个文件
 
2.使用dll
    (1)建立一个最简单的基于对话框的exe工程,如dlluser
    (2)增加一个按钮,并为其增加代码,如void CdlluserDlg::OnButton1()
    (3)将上边得到的dllsample.lib和dllsample.dll两个文件拷贝到工程的当前目录下。
    (4)在OnButton1()所在的源文件顶部的所有函数之前,预定义和头文件之后,增加对dll函数的引用声明:
     _declspec(dllexport) int plus(int x,int y);
    (5)在OnButton1()函数中使用dll函数:
void CdlluserDlg::OnButton1()
{
 // TODO: Add your control notification handler code here
 int pp=plus(5,6);
 CString qq;
 qq.Format("%d",pp);
 MessageBox(qq);
}
   
 
 
 
阅读(1040) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~