使用 Borland C++ Builder 制作 DLL

首先,我们构建我们旧的 DLL。转到文件 −> 新建,然后选择 DLL 向导。有一些选项需要设置:

  • 让源代码为 C++,不要使用 VCL
  • 不要使用多线程,
  • 使用 VC++ 样式 DLL。
  • 输入源代码。
extern "C" __declspec(dllexport) void myfun(int * a){*a = - *a; }

将项目另存为"DLLproj";将源文件另存为"MyMax"。然后构建项目,例如使用 CTRL-F9。您无法运行该项目,因为没有主程序,因此按 F9 将导致错误。

现在我们需要一个主项目来调用 DLL。启动一个新的控制台应用程序(文件 -> 新建,选择控制台向导)。无需包含对 VCL 或多线程的支持。然后输入源代码:

#include <iostream.h>

extern "C" __declspec(dllimport) void myfun ( int * a);

void main(int argc, char* argv[])
{
   int a = 6;
   int b = a;
   myfun(&b);

   cout << '-' << a << " er " << b << " ! 
";
}

接下来,将 DLL 包含在项目中(项目 −> 添加到项目)。您需要包含的是 .lib 文件 (DLLproj.lib)。保存项目。然后构建项目。(要查看结果,您可能需要从 DOS 提示符运行它)。

dll_examples.html