c语言dll bcb,BCB 创建 DLL完全入门级别

DLL是什么呢?

动态链接库英文为DLL,是Dynamic Link Library 的缩写形式,DLL 是一个包含可由多个程序同时使用的代码和数据的库,DLL不是可执行文件。动态链接提供了一种方法,使进程可以调用不属于其可执行代码的函数。函数的可执行代码位于一个 DLL 中,该 DLL 包含一个或多个已被编译、链接并与使用它们的进程分开存储的函数。DLL 还有助于共享数据和资源。多个应用程序可同时访问内存中单个DLL 副本的内容。DLL 是一个包含可由多个程序同时使用的代码和数据的库。

BCB创建使用DLL的步骤:

1、File->New->other->DLL Wizard(建立一个DLL工程)。

2、File->Save All(保存工程信息)。

3、创建自己的函数。

//---------------------------------------------------------------------------

#include

#include

#pragma hdrstop

//---------------------------------------------------------------------------

//   Important note about DLL memory management when your DLL uses the

//   static version of the RunTime Library:

//

//   If your DLL exports any functions that pass String objects (or structs/

//   classes containing nested Strings) as parameter or function results,

//   you will need to add the library MEMMGR.LIB to both the DLL project and

//   any other projects that use the DLL.  You will also need to use MEMMGR.LIB

//   if any other projects which use the DLL will be performing new or delete

//   operations on any non-TObject-derived classes which are exported from the

//   DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling

//   EXE's to use the BORLNDMM.DLL as their memory manager.  In these cases,

//   the file BORLNDMM.DLL should be deployed along with your DLL.

//

//   To avoid using BORLNDMM.DLL, pass string information using "char *" or

//   ShortString parameters.

//

//   If your DLL uses the dynamic version of the RTL, you do not need to

//   explicitly add MEMMGR.LIB as this will be done implicitly for you

//---------------------------------------------------------------------------

/*自己需要导出的函数

该函数为自己定义,也就是其他程序访问该DLL时候的方法。

*/

extern "C" __declspec(dllexport) int __stdcall Test();

/**

DLL 入口

*/

#pragma argsused

int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)

{

return 1;

}

//---------------------------------------------------------------------------

/**

实现定义的函数信息

*/

__declspec(dllexport) int __stdcall Test()

{

return 3;

}

完成以上步骤以后,我们应该知道Test供其他程序调用的接口。

4、build该工程,在build时,设置linker和Package里面的选项。

不能使用动态链接。(Linker)

package(删除运行时所需要的Library)

5、build完成以后将会在保存工程的目录下生成一个DLL文件。

6.、使用BCB implib命令将DLL转换成为Lib文件。

进入BCB安装下面的Bin目录下。

将DLL复制到该目录。

implib xx.lib xx.dll

xx.lib就是该dll对应的lib文件

7、使用DLL在此使用的是“隐式调用法”。

在需要使用该DLL的工程里面的.h文件里面加入:

extern "C" __declspec(dllimport) int __stdcall Test();//我们可以直接使用Test()函数了。

8、将Lib文件加入工程

view->project manager->右键->Add(添加生成的Lib文件)。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值