DLL Tutorial
DLL Examples
Selected Reading
© 2011 TutorialsPoint.COM
|
Making DLL's from the Borland C++ Builder
First we construct our good old DLL. Choose File->New, then select DLL Wizard. There are some options to set: Let the source be C++, don't use VCL, don't use Multi Threading, 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 Mutli Threading. 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 and watch the fun begin. (To see the results, you probably need to run it from a DOS prompt).
|
|
|
|