Page 1 of 1

Exporting functions in the Exe-File

Posted: Thu Jan 18, 2007 3:11 pm
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

Posted: Fri Jan 19, 2007 10:17 am
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.