background image

  注意:动态链接库中调用过程、函数时有不同的 CALL

 

方式 __cdecl  

、 __pascal, 

__fastcall、__stdcall,BCB 中默认的方式为__cdecl(可不写),如果考虑兼容性可用时
__stdcall

 

声明方法为:

extern 揅?__declspec(dllexport) int __stdcall test(); 

 

  对于其中过程、函数也改为:
int __stdcall test() 
  二、使用 DLL 
  在 BCB 中使用 DLL

 

有两种方法:

  1

 

.用静态调用法

  首先需要在 BCB 的项目中加入输入接口库(import library),打开工程项目,使用 BCB 
View|Project Manager 打开项目列表,向项目中加入接口库(*.lib)

 

 

  其次在头文件中加入接口声明。

 

  例程序如下:
//define in include file 
extern 揅?__declspec(dllimport) int __cdecl test(); 
//use function in main program 
int I

 

I=test(); 

 

注意:
(1)动态链接库调用过程、函数时 CALL

 

方式 与创建时方式一样不写为__cdecl,其它需要

 

声明。
(2)BCB 创建的 DLL 有对应的输入接口库(import library),如只有 DLL 而无库时,可用
BCB 的 implib 工具产生:implib xxx.lib xxx.dll;另外可用:tlib xxx.lib,xxx.lst 产生 DLL 的
内部函数列表,许多 Windows

 

的未公开技术就是用这种方法发现的。

  2

 

.动态调用法

  动态调用法要用 Windows API 中的 LoadLibrary()和 GetProcAddress()来调入 DLL 库,

 

指出库中函数位置,这种方法较常见。

 

  例程序如下:
HINSTANCE dd; 
int _stdcall (*ddd)(void); 
dd=LoadLibrary(搙 xx.dll?; 
ddd=GetProcAddress(dd,搕 est?; 
Caption=IntToStr(ddd()); 
FreeLibrary(dd); 

 

  三、注意:
创建 DLL 时编译链接时注意设置 Project Options  

Packages 标签:去除 Builder with runtime packages

 

检查框。

Linker 标签:去除 Use dynamic RTL

 

检查框。

否则创建的 DLL 需要 Runtime packages or Runtime library。

用 C++Bulider 在 WIN.INI 中保存信息

现在许多软件把程序中需要的数据保存在注册表中,这样当用户装的软件越来越多时,
致使注册表越来越庞大,容易使系统出错。当然,微软也建议在注册表中保存数据,但当