Can a C ++ header file with classes be converted to a Delphi block?

I have a C ++ * .h file with three classes in it. The header file is for accessing the DLL. I have almost no knowledge of C ++. However, it seems that I am recalling somewhere that you cannot convert a * .h file to a Delphi block in which there are classes. It's true?

If this is not true and the classes in the header files are not a problem, what is the general approach for converting classes to Delphi?

+8
c ++ header-files delphi
source share
3 answers

In the sense that you can use DLLs from Delphi code? Yes, good luck with that. You know how you cannot use Delphi classes in DLLs if the client code is not written in the same version of Delphi, and even then, as a rule, this is a bad idea due to shared memory with memory? C ++ creates exactly the same problem, only exponentially worse, because there is no standardized ABI, and for you there are all kinds of problems with C ++ - the language that creates problems for you.

The only real way to make it work reliably is with an interface that uses standard ABI. If you have a source, try creating a C interface that wraps the C ++ interface. If not, ask the person who wrote the DLL to provide the C interface, and ask who decided to use this DLL, why you use a third-party library without a source .: P

+3
source share

C ++ classes, like Delphi classes, are not intended for binary interaction.

The Delphi class can only be exported for consumption by other Delphi code, and then only in a package and only when run-time packages are used, and only when all modules use the same version of Delphi. Similarly, C ++ classes can only be imported from a DLL using code compiled with the same tool chain that compiled the DLL.

Thus, your Delphi code will not be able to use this DLL. As I see it, you have the following options:

  • Convince the DLL provider to provide an interactive interface for the library. For example, a simple C-style functional interface or a COM interface.
  • Write the adapter in C ++ using the same compiler that was used to build the DLL. This will be due to the fact that you import the classes into your shell and place them in your Delphi code in a friendly manner. Again, a simple C or COM style interface is an obvious choice.
+8
source share

As noted in the previous answer, the solution uses SWIG to generate pascal bindings. I started developing the SWIG pascal module, but I did not have time to complete it. It basically works, but it lacks all the test cases for integration into SWIG.

I used it in my personal projects, and I managed to import a complex library as GDAL.

+1
source share

All Articles