Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What principles should be followed to make a DLL created using Delphi works well in other Delphi version?

Tags:

dll

delphi

After this question, I need to know what principles should be followed in order to make an encapsulation of a class in a dll compatible to other version of Delphi. I made a class using generics feature in RAD2010 and make a dll which has a function that return an instance of it. When I tried to use the dll using BDS2006 or Delphi 6, the DLL didn't work as expected. But if I use RAD2010 in other computer, there is no issue. Is it caused by using the feature that not available in previous Delphi version (the stack<> stuffs?)? For string matters, I already follow the comment guidance in the library file, that I put ShareMem in both library first uses clause and my project. And I have copied borlndmm.dll from RAD2010 to the same folder where I tried the DLL using BDS2006. It didn't crash, but it didn't work es expected. A function return an empty string when in RAD2010 environment it worked very well.

Once again, I have a question : what principles should be followed in order to make an encapsulation of a class in a dll compatible to other version of Delphi? Thank you in advance. (For encapsulating functions in a dll when no OOP is used, I have no issued for other version of Delphi).

like image 624
WishKnew Avatar asked Nov 17 '09 02:11

WishKnew


People also ask

How do I call an external DLL in Delphi?

It should be: function I2C_GetNumChannels(out numChannels: Longword): FT_Result; stdcall; external 'libmpsse. dll'; The function you are calling accepts the address of a 32 bit unsigned integer.


1 Answers

The definition of a string changed with D2009. If you want to make string communication safe, use a PAnsiChar or a WideString.

The basic rule of communication through DLLs is to not use anything specific to Delphi, so no Delphi strings and no TObject descendants. Interfaces, records and COM types work fine, though.

like image 153
Mason Wheeler Avatar answered Sep 30 '22 02:09

Mason Wheeler