This will be my first attempt to code a DLL in Delphi for calling from other languages.
I have done a lot of googling and see a few good pointers, but nothing exhaustive (at least, I have questions that don't find answered in the Embarcadero material).
I wonder if this list of caveats is exhhaustive, or if I missed anything, and if anyone can anser my questions below.
ShareMem unit.String type and should stick with PCharintegetr and PChar (any others?)A few questions:
integers and PChars? booleans? Or am I stuck with "zer0 === false and all else is true"?
is there anything else I should know?
Thanks in advance for any help
The compiler forbids me to export enums and constants. Am I just not declaring them correctly? I would like calling Delphi s/w to be able to use the enum elements and all callers to be able to use constants.
You cannot export enumerated types and constants. The caller will have to declare them again. The same goes for types.
I should not use any structures because of possible differences in byte alignment between compilers.
Feel free to use records. Alignment is standardised across compilers on the same platform. Do make sure that you use a modern Delphi, XE2 or later, that follows the platform standard for alignment correctly.
So, if I can't accept strctures as parameters. I guess I should just have a long parameter list of integers and PChars?
You can receive records as parameters.
Can I accept arrays as parameters, or does boundary alignment make that dangerous?
You can accept arrays. You need to receive a pointer to the first element, and the number of elements. Array elements are always layed out immediately following the previous elements.
Can I accept/return floats/doubles? Booleans? Or am I stuck with "zero === false and all else is true"?
Yes you can use floating point types and booleans.
Is there anything else I should know?
Almost certainly.
I'll mention one more issue, but there surely are more. Don't use records as return types to functions. Delphi does not follow the platform standard in its handling of function return types for records. Use an out parameter instead.
A good way to learn by example what can be done is to study the Windows API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With