Solved

DLL call functions in program running it?

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

Industry Leaders: 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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

696 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