Exporting functions in the Exe-File

just write whatever you want
Post Reply
MarcWetzel
Posts: 5
Joined: Sat Dec 30, 2006 1:02 pm

Exporting functions in the Exe-File

Post by MarcWetzel »

Hi,

as here are many people around, who might know
if the following approach is complete bullsh*t or just nice...

It is possible to export a function in the main program, eg.:

Code: Select all

program Test;

procedure Test;
begin
      DoSomething;
end;

exports
    Test;


begin
     Test;
end.


My question is the following:
What happens to code like this:

Code: Select all

program Test;

type
      TTestClass = class
           procedure DoSomeThing;
      end;

var
    TestClass: TTestClass;


procedure Test;
begin
      TestClass.DoSomething;
end;

exports
    Test;

initialization
    TestClass:= TTestClass.Create;
    
finalization
     FreeAndNil(TestClass);
begin
     Test;
end.



If many Plugins link to this exported function, do they all get a reference to the same instance of TestClass?
Or does each library get its own reference?

The following approach I have in mind:

EXE-File loads a external library (dll plugin),
the dll tries to link to the exported function with GetProcAddress and
calls this function.


Regards
Marc
madshi
Site Admin
Posts: 10749
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

You can export functions from the exe and it works just fine. Everytime a dll calls the exported function it is executed again. But how are they supposed to get a reference to anything? Your exported procedure doesn't return anything.

Btw, using "initialization", "finalization" *and* "begin" is very confusing. Please use only initialization and finalization.
Post Reply