Creating an API (contract) for your own DLL - Delphi-PRAXiS
Summary
For example, like this: uses ComObj, // for the EOleSysError and EOleException VarUtils; // for the ESafeArrayError const // ID for our rules ThisDllIID: TGUID = {AA76E538-EF3C-4F35-9914-B4801B211A6D}; // "Customer" bit, it is always 0 for Microsoft-defined codes CUSTOMER_BIT = 1 shl 29; // Delphi uses this value to pass EAbort // It is assumed that E_Abort should show "Aborted" message, // while EAbortRaisedHRESULT should be handled silently. Accordingly, for safecall there is no such problem, since Result for it is always Integer (HRESULT) - a simple type, for which var and out are equivalent; • All APIs must have a unique IID/ (non- interfaces (not mentioned in headers) might not have a , although I would recommend always specifying an IID). It also means the ability to share memory, do transparent error handling (cross-module exceptions).If you go this route, then you should consider usingpackages (BPLs) instead of DLLs.packages are specialized DLLs that are specifically tailored for use only in Delphi, which gives you a lot of goodies. For example, like this:uses ComObj, // for the EOleSysError and EOleException VarUtils; // for the ESafeArrayError const // ID for ourrules ThisDllIID: TGUID = {AA76E538-EF3C-4F35-9914-B4801B211A6D}; // "Customer" bit, it is always 0 for Microsoft-defined codes CUSTOMER_BIT = 1 shl 29; // Delphi uses this value to pass EAbort // It is assumed that E_Abort should show "Aborted" message, // while EAbortRaisedHRESULT should be handled silently. The fix for this bug is included in the code examples at the link at the end of the article.The DllMain is a special function in athat is called by the system when theis loaded into, unloaded from a process (and attached/detached to/from a thread).