用dll动态链接库将函数封装

如果熟悉windows的用户就会发现windows下有很多dll文件,但很多人不知道这些文件究竟是用来干什么的,为什么要做成dll文件。现在我就windows下的systems文件夹下的user32.dll文件,利用VC++6.0的depends工具打开,截图为:

我们很容易发现,Function行都是我们开发用的API,也就是说微软通过将他们编写的函数放入一个dll文件中,而函数具体代码,我们是无法找到的,因为这是一个公司的核心竞争力所在,微软也不至于蠢到把windows开发代码给我们吧,那肯定是不现实的。

在这里我并不会对dll做详细的解析,我只想通过我的一个汉若塔程序,将我的程序进行封装,只提供相应的接口。

首先我们打开VC++6.0文件--新建--工程--Win32 Dynamic-Link Library

确定默认一个空的工程。

然后新建一个头文件hrt_t.h

包含代码:

#define INIT_STACK_SIZE 40
#define STACK_ADD 10
typedef struct
{
 int xu;             //  对应的盘子序数
 int zbj;              //  对应的纵坐标
}cun;
typedef struct     //  把位子放入栈中 线性表操作
{
  cun *top;
  cun *bottom;
 int stacksize;
} Sqstack;
再新建一个头文件hrt.h

代码为:

extern "C" void __declspec(dllexport) initstack(Sqstack &L);
extern "C" Status __declspec(dllexport) push(Sqstack&L,int xu,int zbj);
extern "C" Status __declspec(dllexport) pop(Sqstack&L,int&xu,int&zbj);
extern "C" Status __declspec(dllexport) emptystack(Sqstack L);
extern "C" Status __declspec(dllexport) gettop(Sqstack L,int&xu,int&zbj);
extern "C" void __declspec(dllexport) GotoConsoleXY(HANDLE hConsole,int x,int y);
extern "C" void __declspec(dllexport) gotoxy(int x,int y);
extern "C" void __declspec(dllexport) huatu(Sqstack&A,Sqstack&B,char(*b)[16],char(*a)[16],int e,int zbj,int l,int xu);
extern "C" void __declspec(dllexport) move(Sqstack&A,Sqstack&B,Sqstack&C,char(*b)[16],char(*a)[16],char x,char Y);
extern "C" void __declspec(dllexport) hrt(Sqstack &e,Sqstack &f,Sqstack &g,char (*b)[16],char (*a)[16],int n,char A,char B,char C);

之后新建一个资源文件hrt.cpp

代码为:

#include"t11.h"
#include"hrt_t.h"
#include"hrt.h"
#include"stdio.h"
#include"malloc.h"
#include"stdlib.h"

void initstack(Sqstack &L)            //  初始化栈操作
{
 L.bottom=(cun*)malloc(INIT_STACK_SIZE*sizeof(cun));
 if(!L.bottom)
 {
  printf("内存分配失败!!");
  exit(-1);
 }
 L.top=L.bottom;
    L.stacksize=INIT_STACK_SIZE;
}

Status push(Sqstack &L,int xu,int zbj)        // 压入位置 q表示行,p表示列
{
 if(L.top-L.bottom >&#

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值