"Jamie" <jamie_ka1lpa_not_valid_after_ka1lpa_@[EMAIL PROTECTED]
> wrote in message
news:w3wck.28$Y51.2@[EMAIL PROTECTED]
> Ikke wrote:
>
>> Hi everybody,
>>
>> Is it possible to call a .dll from Delphi, and have it call your
program
>> back, and if so, how would I go about doing something like this?
>> Does anybody know of a way to accomplish this? Sorry for being so vague
>> about it, but as you might have noticed I myself am not very clear as
to
>> how to do this, thus I'm asking for help :)
>>
>> Thanks,
>>
>> Ikke
> Create a function in the DLL that accepts a pointer to a procedure or
> function in your program..
> Call it the SetCallBack function in the DLL>
> SetCallBack( Code:Pointer);
>
> the callback must conform to a standard the DLL expects..
> for example.
> in your app..
>
> Procedure MyCallBack(MsgCode, Parm1,Parm2,Parm3:integer) stdcall;
> Begin
> // do code here;
> End;
>
>
> and to set it up in the DLL..
>
> SetCallBack(@[EMAIL PROTECTED]
);
>
> etc..
> ---- in the DLL ---
>
> Var
> MyCallBack:Procedure(MsgCode,Parm1,Parm2,Parm3:integer) stdcall;
>
> Procedure SetCallBack(Code:pointer);
> Begin
> MyCallBack := Code;
> End;
>
> etc.
>
> One last thing to remember,, this does not work with interprocesses!
> so if this is what you're thinking of doing, look for another avenue.
>
> http://webpages.charter.net/jamie_5"
>
If the dll is also written in Delphi use a common unit
unit MyDLLInterface;
Interface
Type
tCallBack = procedure ( {formal parameter list} ); stdcall;
end.
In the DLL
.. . .
uses MyDLLInterface;
procedure SomeProc (. . .; callBack : tCallBack; . . .);
begin
.. . .
callBack ( {actual parameter list} );
.. . .
end;
In the unit that calls the dll
procedure theCallBack ( {formal parameter list that is exactly the same as
in tCallBack} ); stdcall;
begin
.. . .
end;
.. . .
dllRoutine (. . ., @[EMAIL PROTECTED]
. . .);
.. . .
One can also do interesting things such as assigning procedures to
procedure
variables, i.e. dispatch vectors, etc. You may want to read the Procedural
Types section of the Object Pascal (Reference) Manual.


|