Linking into Borland C++ Builder 5.0

Necessary files:

TcAdsDll.dll is located in the Windows 'System32' directory. The TcAdsApi.h and TcAdsDef.h are located in the ..\ADS Api\TcAdsDll\Include directory of TwinCAT. 

Necessary tools:

Comment

The library file: TcAdsDll.lib supplied with the TwinCAT installation cannot be included and compiled in Borland C++ Builder projects for compatibility reasons. When trying to link this lib, you get the following error message:

[Linker Error]
'E:\BORLAND\CBUILDER5\PROJECTS\SAMPLE1\TCADSDLL.LIB'
contains invalid OMF record, type 0x21 (possibly COFF)

With the Borland utility: IMPLIB.EXE a new library can be generated from the TcAdsDll.dll. This can then be compiled and linked without errors.  IMPLIB.EXE is located by default in the Borland ...\Bin directory. Use the following command on the DOS prompt:

IMPLIB -a TcAdsDll
TcAdsDll.dll

The switch -a generates Microsoft-compatible aliases for the dll functions.

For the enumeration types (enums) in the TcAdsDEF.h 4 bytes (32 bits) of memory must be allocated. Make sure that under Project->Options on the compiler tab the following option is selected: "Treat enum types as ints":

Linking into Borland C++ Builder 5.0 1:

To access the DLL functions the two header files must be included in the Borland C++ Builder project. E.g.:

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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"

#include "c:\TwinCAT\ADS Api\TcAdsDll\Include\TcAdsDEF.h"
#include "c:\TwinCAT\ADS Api\TcAdsDll\Include\TcAdsAPI.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------

The TcAdsDll.Lib can be added to the project via the Project->Add to project... menu.