[fpc-pascal] Library callback : how do I do that?

Henry Vermaak henry.vermaak at gmail.com
Thu Aug 8 12:58:44 CEST 2013


On Thu, Aug 08, 2013 at 11:34:53AM +0100, Lukasz Sokol wrote:
> This would be fine, IFF i was adding this to the main form of my
> application...  but I'm not. I'm trying to wrap this .dll in a
> separate unit, only communicating to the form through a wrapper
> object, defined in a separate unit.  The object itself, would be
> created /by/ the form window, but won't be a GUI object, so won't be
> in the message queue;
> 
> Doing a chain like:
> 
> (Setup) (form passes its handle to the object) -> (object installs
> callback function) and then (normal operation) (form receives callback
> via Windows Message) -> (form calls e.g OnCallback function of the
> object)
> 
> seems a bit backwards.
> 
> I can imagine, that I need to have the Callback procedure as 
> 
> procedure Callback(Port, Event, Value : Integer); stdcall;
> 
> but how do I call functions/procedures of MyObject in a threadsafe
> manner from there?

Lazarus has QueueAsyncCall, which is a thread safe, cross platform way
of queueing method calls asynchronously.

E.g. for USB hotplug notification, I register this function with my
device library:

	procedure NotifyPlug(status: cint); cdecl;
	begin
	  Application.QueueAsyncCall(@MainForm.NotifyAsync, status);
	end;

Henry



More information about the fpc-pascal mailing list