Solved

DLL call functions in program running it?

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now