| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付赛孚耐:软件保护加密专家
身份认证令牌USB KEY   
共有 507 人关注过本帖
标题:DLL编程的优点
收藏  订阅  推荐  打印 
vfdff
Rank: 6Rank: 6
等级:金牌会员
威望:6
帖子:1342
积分:14898
注册:2005-7-15
DLL编程的优点

现在好多程序都是使用.dll来实现一个特定的功能函数,但是现在看了下DLL编程,感觉这个和以前的编写普通的子程序好像没有多大改变,反而有的复杂了,所以她一定有什么优点,希望哪位大侠介绍下为什么我们选择.dll?
搜索更多相关主题的帖子: DLL  优点  dll  子程序  函数  
2007-11-18 16:10
Janlex
Rank: 3Rank: 3
等级:中级会员
威望:6
帖子:303
积分:3198
注册:2006-9-12

1, 你只想接供接口给别人调用,而不想共享源代码给别人.就要用dll

2, 进程间数据共享,也可以用到dll

...很多进程间操作方面都要用到


★★★★★欢迎光临我的博客 ★★★★★
http://www.ozd.cn
2007-11-18 16:49
vfdff
Rank: 6Rank: 6
等级:金牌会员
威望:6
帖子:1342
积分:14898
注册:2005-7-15

#include<stdio.h>
#include<windows.h>
#include<string.h>

__declspec(dllexport) void demo()
{
#define PASSWORD_SIZE 100
#define PASSWORD "myGOODpassword\n"

int count = 0;
char buff[PASSWORD_SIZE]="";

for(;;)
{
// 提示用户输入密码并且读取他
printf("enter password: ");
fgets(&buff[0],PASSWORD_SIZE,stdin);

// 针对参数值匹配输入的密码
if(strcmp(&buff[0],PASSWORD))
{
// “声诉”密码不匹配
printf("WRONG password\n");
}
else break;

// 鉴定失败计数值+1,并且在密码试输三次后终止程序运行
if(++count > 2) return ;
}
// 程序执行到这里,意味着用户输入的密码是正确的
printf("password ok!\n");
}

int main()
{
HMODULE hmod;
void (*zzz)();
if(( hmod=LoadLibrary("crackme.exe") )
&&(zzz=(void(*)())GetProcAddress(hmod,"Demo")))
zzz();
return 0;
}
那上面的程序怎么运行呀??因为直接编译,发现没有调用void demo()函数

~~~~~~~~~~~~~~~好好学习~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2007-11-19 00:50
yuyunliuhen
Rank: 12Rank: 12Rank: 12
等级:贵宾
威望:20
帖子:1423
积分:14506
注册:2005-12-12

建议翻翻孙鑫《VC++深入详解》


[此贴子已经被作者于2007-11-19 13:22:19编辑过]


Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2007-11-19 13:17
vfdff
Rank: 6Rank: 6
等级:金牌会员
威望:6
帖子:1342
积分:14898
注册:2005-7-15

没有钱买书呀

~~~~~~~~~~~~~~~好好学习~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2007-11-19 13:25
yuyunliuhen
Rank: 12Rank: 12Rank: 12
等级:贵宾
威望:20
帖子:1423
积分:14506
注册:2005-12-12

那看看这本书的视频吧,有免费下载,看看DLL那章,已经讲的够清楚了。


Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2007-11-19 13:31
vfdff
Rank: 6Rank: 6
等级:金牌会员
威望:6
帖子:1342
积分:14898
注册:2005-7-15

我使用
#include<stdio.h>
#include<windows.h>
#include<string.h>

__declspec(dllexport) void demo()
{
#define PASSWORD_SIZE 100
#define PASSWORD "myGOODpassword\n"

int count = 0;
char buff[PASSWORD_SIZE]="";

for(;;)
{
// 提示用户输入密码并且读取他
printf("enter password: ");
fgets(&buff[0],PASSWORD_SIZE,stdin);

// 针对参数值匹配输入的密码
if(strcmp(&buff[0],PASSWORD))
{
// “声诉”密码不匹配
printf("WRONG password\n");
}
else break;

// 鉴定失败计数值+1,并且在密码试输三次后终止程序运行
if(++count > 2) return ;
}
// 程序执行到这里,意味着用户输入的密码是正确的
printf("password ok!\n");
}

生成了一个mycrack.dll文件
然后再使用


#include<stdio.h>
#include<windows.h>
#include<string.h>

int main()
{
HMODULE hmod;
void (*zzz)();
if(( hmod=LoadLibrary("mycrack.dll") )
&&(zzz=(void(*)())GetProcAddress(hmod,"Demo")))
zzz();
return 0;
}调用,编译运行没有错误,但是就是没有提示输入密码
说明没有成功调用demo()函数吗?

~~~~~~~~~~~~~~~好好学习~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2007-11-19 13:54
yuyunliuhen
Rank: 12Rank: 12Rank: 12
等级:贵宾
威望:20
帖子:1423
积分:14506
注册:2005-12-12

_declspec (dllimport) void demo();
加上试试!

Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2007-11-19 14:02
vfdff
Rank: 6Rank: 6
等级:金牌会员
威望:6
帖子:1342
积分:14898
注册:2005-7-15

仍旧一样,提示press any key to quit

~~~~~~~~~~~~~~~好好学习~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2007-11-19 15:11
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.082610 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved