| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1549 人关注过本帖
标题:DLL编程的优点
只看楼主 加入收藏
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
结帖率:79.17%
收藏
 问题点数:0 回复次数:8 
DLL编程的优点
现在好多程序都是使用.dll来实现一个特定的功能函数,但是现在看了下DLL编程,感觉这个和以前的编写普通的子程序好像没有多大改变,反而有的复杂了,所以她一定有什么优点,希望哪位大侠介绍下为什么我们选择.dll?
搜索更多相关主题的帖子: DLL 优点 dll 子程序 函数 
2007-11-18 16:10
Janlex
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:303
专家分:0
注 册:2006-9-12
收藏
得分:0 

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

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

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


★★★★★欢迎光临我的博客 ★★★★★
http://www.
2007-11-18 16:49
vfdff
Rank: 6Rank: 6
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
收藏
得分:0 

#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: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 

建议翻翻孙鑫《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
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
收藏
得分:0 
没有钱买书呀

~~~~~~~~~~~~~~~好好学习~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2007-11-19 13:25
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 

那看看这本书的视频吧,有免费下载,看看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
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
收藏
得分:0 
我使用
#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: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 
_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
等 级:侠之大者
威 望:8
帖 子:2172
专家分:425
注 册:2005-7-15
收藏
得分:0 
仍旧一样,提示press any key to quit

~~~~~~~~~~~~~~~好好学习~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2007-11-19 15:11
快速回复:DLL编程的优点
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038518 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved