Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Borland Delphi > Re: Question ab...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 13 Topic 3832 of 3940
Post > Topic >>

Re: Question about DLLs

by "BRoberts" <berdontemail@[EMAIL PROTECTED] > Jul 7, 2008 at 09:57 PM

"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.
 




 13 Posts in Topic:
Question about DLLs
Ikke <ikke@[EMAIL PROT  2008-07-07 21:25:17 
Re: Question about DLLs
"Skybuck Flying"  2008-07-07 23:38:47 
Re: Question about DLLs
Jamie <jamie_ka1lpa_no  2008-07-07 17:52:32 
Re: Question about DLLs
"BRoberts" <  2008-07-07 21:57:04 
Re: Question about DLLs
Rob Kennedy <me3@[EMAI  2008-07-07 21:08:41 
Re: Question about DLLs
"Maarten Wiltink&quo  2008-07-08 08:28:42 
Re: Question about DLLs
epc8@[EMAIL PROTECTED]   2008-07-09 12:47:51 
Re: Question about DLLs
Troll <troll@[EMAIL PR  2008-07-09 21:04:15 
Re: Question about DLLs
"Maarten Wiltink&quo  2008-07-10 10:41:25 
Re: Question about DLLs
Troll <troll@[EMAIL PR  2008-07-10 15:45:05 
Re: Question about DLLs
Graham Smith <wot@[EMA  2008-07-10 10:59:30 
Re: Question about DLLs
Rob Kennedy <me3@[EMAI  2008-07-10 08:45:40 
Re: Question about DLLs
Chau Chee Yang <cychau  2008-07-22 21:17:40 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 15:48:34 CDT 2008.