Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Rob Kennedy already gave you <a href="https://stackoverflow.com/questions/1017692/use-a-function-from-dll/1018594#1018594">an answer</a> with information about possible reasons for the problem you are experiencing, and some ways to code this differently.</p> <p>There is however another way to do this, which is both straightforward and compatible with other development environments as well: interfaces. Consider the following code:</p> <pre><code>type IPortNotification = interface ['{7BECA1D9-A6E8-4406-9910-5B36A6B0D564}'] procedure StatusChanged(ACardNo, APortNo: integer; ANewPortStatus: byte); procedure DataReceived(ACardNo, APortNo: integer; ADataPtr: PByte; ADataLength: integer); end; function RegisterPortNotification(ANotification: IPortNotification): BOOL; stdcall; external PortDLL; function UnregisterPortNotification(ANotification: IPortNotification): BOOL; stdcall; external PortDLL; </code></pre> <p>The DLL just exports two functions to register and unregister interface pointers, and the interface implements the event handlers in your code directly. This makes the DLL fairly generic, you could rewrite it at any time in another language, and you could use it from other dev environments as well - there is nothing Delphi specific like the event handlers in <code>T_API_INIT_PARAMS</code>.</p> <p>Note that now you can implement multicast events nearly for free, by registering several interface pointers.</p> <p>It's also much easier like this to extend the API. With the record in your original code you can't add callbacks without breaking binary compatibility. With <code>RegisterPortNotification()</code> you can always query the passed interface for new, extended interfaces, and register them instead.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload