Making DLL's from the Borland C++ Builder


Advertisements


At first, we construct our good old DLL. Go to File −> New, then select DLL Wizard. There are some options to set:

  • Let the source be C++, don't use VCL
  • Don't use multithreading,
  • Use VC++ Style DLL.
  • Enter the source.
extern "C" __declspec(dllexport) void myfun(int * a){*a = - *a; }

Save the project as "DLLproj"; save the source file as "MyMax". Then build the project, e.g. using CTRL-F9. You can't run the project because there is no main, so pressing F9 will result in an error.

Now we need a main project to call the DLL. Start a new Console application (File -> New, choose Console Wizard). No need to include support for VCL or Multithreading. Then enter the source:

#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 << " ! \n";
}

Next, include the DLL in the project (Project −> Add to Project). It is the .lib file (DLLproj.lib) that you need to include. Save the project. Then build the project. (To see the results, you may probably need to run it from a DOS prompt).


dll_examples.htm