melchiorre caruso wrote:
> Al Boldi wrote:
> > But, you could instead just try setting WakeMainThread in your lib
> > yourself, and let the handler post a message to the mainthread. That's
> > what the Interfaces unit does. Can you try this
>
> I do not know how to do it,
It turns out that you need an export trick to do this.
Include the attached 'LibSyncMgr.inc' into your lib after your exports-line
with this line:
{$i LibSyncMgr.inc}
Make sure there is no LCL or Interfaces unit included in your library
project.
Then include the attached 'LibSyncMgr.pas' in your main-apps uses clause.
Then add this line:
TLibSyncMgr.Create(self).LibHandle := LibHandle;
right after your LoadLibrary call.
> Btw, I solved the problem using threadx.pas;
Sure, but this isn't cross-platform.
Thanks for testing!
--
Al
{ Library Exports for External Synchronize support }
procedure LibCheckSynchronize(TimeOut : longint=0);
begin
CheckSynchronize(TimeOut);
end;
procedure LibSetWakeMainThread(WakeProc: TNotifyEvent);
begin
WakeMainThread:=WakeProc;
end;
exports LibCheckSynchronize,LibSetWakeMainThread;
unit LibSyncMgr;
interface
uses
ExtCtrls,DynLibs,Classes;
type
TLibCheckSynchronize = procedure (TimeOut: LongInt = 0);
TLibSetWakeMainThread = procedure (WakeProc: TNotifyEvent);
{ TLibSyncMgr }
TLibSyncMgr = class(TComponent)
private
FLibHandle: TLibHandle;
FLibSync: TLibCheckSynchronize;
FLibWake: TLibSetWakeMainThread;
FTimer: TTimer;
procedure SetLibHandle(const AValue: TLibHandle);
procedure Wake(Sender: TObject);
procedure DoSync(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
property LibHandle: TLibHandle read FLibHandle write SetLibHandle;
end;
implementation
{ TLibSyncMgr }
constructor TLibSyncMgr.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FTimer:=TTimer.Create(self);;
FTimer.Enabled:=false;
FTimer.Interval:=1;
FTimer.OnTimer:=DoSync;
end;
procedure TLibSyncMgr.SetLibHandle(const AValue: TLibHandle);
begin
if FLibHandle=AValue then exit;
FLibHandle:=AValue;
if Pointer(FLibHandle) = nil then exit;
FLibSync := GetProcedureAddress(LibHandle, 'LibCheckSynchronize');
if not Assigned(FLibSync) then exit;
FLibWake := GetProcedureAddress(LibHandle, 'LibSetWakeMainThread');
if not Assigned(FLibWake) then exit;
FLibWake(Wake);
end;
procedure TLibSyncMgr.Wake(Sender: TObject);
begin
FTimer.Enabled:=true;
end;
procedure TLibSyncMgr.DoSync(Sender: TObject);
begin
FTimer.Enabled:=false;
FLibSync(1000);
end;
end.