Solved

DLL call functions in program running it?

Posted on 2007-03-28
3
225 Views
Last Modified: 2010-04-05
Is it possible for a DLL to call functions in the program which is running the DLL?

I can do this with window messages but is that the only way?

Surely the DLL can have some kind of access to the program which is using it?
0
Comment
Question by:TheJkWhoSaysNi
3 Comments
 
LVL 21

Assisted Solution

by:ziolko
ziolko earned 60 total points
ID: 18814240
yup it's called callback.

look at one of my PAQ's:
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20080180.html

ziolko.
0
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 65 total points
ID: 18815001
Or an easier method: export your methods in your executable!!! Example:
------------------------------------------------------------
program EXE;
{$APPTYPE CONSOLE}
uses Windows;

procedure Callback; export;
begin
  WriteLn('Callback called');
end;

exports
  Callback;

var
  DLLHandle: THandle;
begin
  DLLHandle := LoadLibrary('DLL.dll');
  ReadLn;
  CloseHandle(DLLHandle);
end.
------------------------------------------------------------
library DLL;

uses
  Windows;

type
  TCallback = procedure;

var
  Callback: TCallback;
begin
  Callback := GetProcAddress(MainInstance, 'Callback');
  Callback;
end.
------------------------------------------------------------
Basically, what it does is that the DLL will look for the method called "Callback" in the instance of the executable. Since the executable exports this method, it can easily call this method even without the EXE first having to tell the DLL where to find the method. :-)
0
 

Author Comment

by:TheJkWhoSaysNi
ID: 18818931
Thanks to both of you. I'll split the points. Going to try both methods :)

Thanks ziolko and Workshop_Alex.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question