I'm writing a set of DLLs which allows other developers write their own DLL as an extension. In the Delphi code, I widely use enums, and enum sets. I use enums through DLLs. I know I can safely use an enum through a DLL across different projects compiled with Delphi. However, I'm not sure about how adaptable it is across various languages.
Is it safe to use enums through a DLL while supporting other various languages? Or should I cast it as an integer instead?
Enums need to be passed as integers (Word or DWORD), and you should use the compiler directive {$MINENUMSIZE} (AKA
{$Z}
) to ensure that they're the proper size. The Delphi compiler will use different sizes based on the number of enum values unless you do so.If you're planning to interop with C/C++ code on the Windows OS, use
{$MINENUMSIZE 4}
.The documentation I linked above addresses interop with C/C++ - see the third paragraph: