Recent

Author Topic: Create C Header for Pascal DLL ?  (Read 549 times)

Hen3ry

  • Newbie
  • Posts: 4
Create C Header for Pascal DLL ?
« on: November 25, 2020, 11:39:04 pm »
Hi,

I newer really programmed in C so I have a rather simple question: What should I provide to a C programmer to use a DLL I wrote in Lazarus?

Function MyFunction(S1,S2,S3:PChar):Integer; cdecl;

How would the C Header file look like? Should I provide anything else except a documentations what the parameters mean? Is there a tool for creating headers for library sources?

Thank you
Hen3ry

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Create C Header for Pascal DLL ?
« Reply #1 on: November 26, 2020, 01:56:07 am »
What should I provide to a C programmer to use a DLL I wrote in Lazarus?

The DLL itself, of course.  And a header file that declares the types and functions that the DLL exports, eg:

Code: [Select]
#ifndef MYDLL_H
#define MYDLL_H

#ifdef __cplusplus
extern "C" {
#endif

__declspec(dllimport) int __cdecl MyFunction(char *S1, char *S2, char *S3);

#ifdef __cplusplus
}
#endif

#endif

A C/C++ programmer can then generate an import .lib file from the DLL using the tools of their compiler toolchain, then add that .lib to their project, and #include the header file into their code.

Should I provide anything else except a documentations what the parameters mean?

No.

Is there a tool for creating headers for library sources?

Not that I'm aware of, but I would be surprised if such a tool does not exist somewhere.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018