Solved

DLL call functions in program running it?

Posted on 2007-03-28
3
223 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 157
Intraweb download file link ? 1 134
Strange behavior when a form is closed 6 57
TEMBEDDEDWB how can i change its user agent ? 8 58
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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