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 11 of 14 Topic 3832 of 3952
Post > Topic >>

Re: Question about DLLs

by Graham Smith <wot@[EMAIL PROTECTED] > Jul 10, 2008 at 10:59 AM

In message <Xns9AD4EF8673996ikkehierbe@[EMAIL PROTECTED]
>, Ikke
<ikke@[EMAIL PROTECTED]
> writes
>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?
>
>What I'd like to do is the following:
>- I have a Delphi application which dynamically calls a .dll (consider it
a
>plugin written in another language)
>- the application calls a few functions from the .dll
>So far so good - I know how to accomplish this, although I'm not sure how
>I'd go about setting up an interface for the .dll(s).
>

Try something like this. It is the method I have been using for some
time now. (Delphi 6):

// define the type of function you will call in the DLL
Type
  TfuncPStrToBool = function (AStr:Pshortstring):boolean; StdCall;


// now define some variables ...
var
  // A variable to store the Windows ID for the loaded DLL
  LibHandle : THandle;

  // a variable to hold the address of the function you will call.
  funcEnterUserName   : TfuncPStrToBool;

  // a place to enter a user name ...
  UName:shortstring;

..... now the code ...

  // try to load the DLL (you do this ONLY ONCE in your application)
  LibHandle := LoadLibrary('yourlibname.dll');

  // check that the DLL is loaded ...
  if LibHandle=0 then
    Failed;     // do whatever you need to do: e.g exit/raise exception.


  // load the address of the function you are interested in.
  // In this case the function is a TfuncPStrToBool (defined above)
  // and it is called "EnterUserName".
  @[EMAIL PROTECTED]
 := GetProcAddress(LibHandle, 'EnterUserName');


...Later in your code you can call the EnterUserName function...

  if @[EMAIL PROTECTED]
>nil then
    if funcEnterUserName(@[EMAIL PROTECTED]
) =FALSE then
      ....something_went_wrong
    else
      ... all OK, name is in the string UName


Finally you should always unload your DLL...

  if LibHandle <> 0 then
    FreeLibrary(LibHandle);



>Next it should do the following:
>- at random times (as the .dll sees fit), the .dll should call specific
>functions from my application
>It is this particular function that I'm not sure about.
>
>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 :)
>

I don't think you should attempt this, even if it is possible. If your
app were to crash, the DLL would not know, and continue to call the
function which is not now there.

Instead, try calling the DLL periodically, 'pu****ng' any data to the DLL
rather than the DLL 'pulling' its data.

Gray

-- 
E-mail: Remove X's and underscores from X_grahams_x@[EMAIL PROTECTED]

 




 14 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 
Re: Question about DLLs
John H. Guillory <john  2008-10-09 19:13:18 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Sun Oct 12 7:01:42 CDT 2008.