[fpc-devel] bug ID #4855

L505 fpc505 at z505.com
Mon Apr 10 09:25:27 CEST 2006


----- Original Message -----
From: "Peter Vreman" <peter at freepascal.org>
To: "FPC developers' list" <fpc-devel at lists.freepascal.org>
Sent: Monday, April 10, 2006 12:18 AM
Subject: Re: [fpc-devel] bug ID #4855


> Buys Regarding this bug #4855 I need to get it fixed..
>
>
>
> The issue like this...  I have 2 parts to my system...
>
>
>
> The EXE ... and a DLL
>
>
>
> In the DLL I have an exported function that returns an Interface...
>
>
>
> Function dosomething( const aObjectInt : ISomeInt ) : ISomeOtherInt
>
>
>
> This fails and causes the application to die..
>
> However if I put the same function inside the EXE it works fine.

> > The DLL has it's own memory manager. The EXE can't access the memory
> > allocated in the DLL.

I'm not familiar with interfaces and if they would work in this case, but how
about exporting the memory manager from the DLL or the EXE, and only using one
memory manager instead of two. We do it for ansistrings and it works fine in
PSP/PWU dll/dso.

Source code for working dso/dll that exports the memory manager (and is imported
by EXE) is here:
DLL/DSO main unit:
https://opensvn.csie.org/pspcgi/psp-1.6.0-release/LibraryUnits/pwu_lib.pas
Library wrapper that EXE uses:
https://opensvn.csie.org/pspcgi/psp-1.6.0-release/MainUnits/pwu.pas


But this is a summary of how it works below:

-----------------------------
{ IN THE DLL }
// export memory manager from library for CGI program to use
procedure GetMemMan(out MemMan: TMemoryManager); stdcall;
begin
  GetMemoryManager(MemMan);
end;

exports
  GetMemMan name 'GetSharedMemMan';

-----------------------------
{ IN THE EXE PROGRAM }
initialization
  // always load library before program runs
  MainLibHandle:= LoadLibrary(LibPath);
  GetMemoryManager(OldMemMan); //store old memory manager
  GetMemMan:= TGetMemMan(GetProcAddress(LibHandle, 'GetSharedMemMan'));

 { Get the shared memory manager which is stored in the library itself }
  GetMemMan(GottenMemMan);

 { Set gotten memory manager up before import *any* functions from library. }
  SetMemoryManager(GottenMemMan);

finalization
  // always free library before CGI program closes
  if MainLibHandle <> NilHandle then
  begin
    FreeLibrary(LibHandle)
  end;
  SetMemoryManager(OldMemMan); // restore original memory manager
end.




More information about the fpc-devel mailing list