Exporting functions in the Exe-File

just write whatever you want

Exporting functions in the Exe-File

Postby MarcWetzel » Thu Jan 18, 2007 3:11 pm

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
MarcWetzel
 
Posts: 5
Joined: Sat Dec 30, 2006 1:02 pm

Postby madshi » Fri Jan 19, 2007 10:17 am

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.
madshi
Site Admin
 
Posts: 9822
Joined: Sun Mar 21, 2004 5:25 pm


Return to fun talk

Who is online

Users browsing this forum: No registered users and 3 guests