?
Solved

DLL call functions in program running it?

Posted on 2007-03-28
3
Medium Priority
?
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 21

Assisted Solution

by:ziolko
ziolko earned 240 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 260 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

650 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