Einzelnen Beitrag anzeigen

Kenrai

Registriert seit: 4. Jun 2014
11 Beiträge
 
#1

Firemonkey DLL Problem

  Alt 18. Jun 2015, 13:21
Hallo Zusammen!

Seit einiger Zeit quält mich ein Bug in meiner Anwendung....
Folgende Situation:
Es existiert eine VCL Anwendung die nun mit einer Firemonkey dll erweitert wird. Funktioniert alles eigentlich Einwandfrei, bis
auf das Schließen der Firemonkey-Form. Das Fenster hängt sich dann auf bzw. wird noch Angezeigt, hab einen Screenshot davon angefügt.

Wenn man dann dazu noch die Hauptapplikation schließt, stürzt der Prozess ab bzw. hängt sich auf und die Prozessorlast schießt hoch.
Hab extra ein Projekt erstellt und den Code nicht sauber formatiert, war rein zum testen deswegen nicht wundern. (Anstatt der VCL Anwendung ist es eine FMX aber effekt der Gleiche)

Code von der Schnittstelle in der Host-Application
Delphi-Quellcode:
unit Unit6;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, Windows, TimeCodeLib;

Function Ts_CreateGrid (Filename : String; language : Integer): Integer;

Function Ts_CloseWindow : Integer;

//##############################################################################
implementation

type
    TDLL_CreateGrid = Function(const Filename : String; language : Integer): Integer; cdecl;
    TDLL_CloseWindow = Function : Integer; cdecl;

var
  LibHandle: THandle; // Handle to the currently loaded dll

  myDLL_CreateGrid : TDLL_CreateGrid;
  myDLL_CloseWindow : TDLL_CloseWindow;

const
    dllName = 'Test.dll';

type
    EDLLError = class(Exception);


(*******************************************************************************

*******************************************************************************)

Function Ts_CloseWindow: Integer;
Begin
   if Assigned(myDLL_CloseWindow) then begin
      Result := myDLL_CloseWindow;
   End Else Begin
      Result := 0;
   End;
End;

(*******************************************************************************

*******************************************************************************)

Function Ts_CreateGrid (Filename : String; language : Integer): Integer;
Begin
   if Assigned(myDLL_CreateGrid) then begin
      Result := myDLL_CreateGrid(Filename, language);
   End Else Begin
      Result := 0;
   End;
End;


(*******************************************************************************

*******************************************************************************)

Procedure ActivateDLL;
Begin
    myDLL_CreateGrid := NIL;
    myDLL_CloseWindow := NIL;

    Try
        LibHandle := LoadLibrary(dllName);
        If (LibHandle < 32) Then Begin
            raise EDLLError.Create('Unable to load '+dllName);
        End;

        If LibHandle >= 32 Then Begin
            myDLL_CreateGrid := GetProcAddress(LibHandle, 'CreateGrid');
            myDLL_CloseWindow := GetProcAddress(LibHandle, 'CloseMainWindow');
        End;
    Except
        //
    End;
End;

//------------------------------------------------------------------------------
initialization
    ActivateDLL;

finalization
    Try
       FreeLibrary(LibHandle);
    Except

    End;
end.
Code von der DLL:

Delphi-Quellcode:
unit UnitFMXdll;

interface

uses
  ShareMem, Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  TimeCodeLib, Unit5;


procedure CreateGrid(); cdecl;

procedure CloseMainWindow; cdecl;


implementation

var
    MainForm : TForm5;

{*******************************************************************************
    CreateGrid
*******************************************************************************}

procedure CreateGrid;
begin
    try
        if MainForm <> nil then begin
            MainForm.Free;
            MainForm := nil;
        end;

        if MainForm = nil then begin
            MainForm := TForm5.Create(nil);
            MainForm.Show;
        end;
    except
        //fehler code 2!
    end;
end;

procedure CloseMainWindow;
begin
    try
        if MainForm <> nil then begin
           // MainForm.Release;
          // MainForm.Close;
            MainForm.Release;
            MainForm := nil;
        end;
    except
        //fehler code 6!
    end;
end;


initialization
    MainForm := nil;

finalization
     if MainForm <> nil then begin
        MainForm.Free;
       // MainForm := nil;
     end;
end.
Schnittstelle in der DLL

Delphi-Quellcode:
 library Project2;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }


uses
    ShareMem,
  System.SysUtils,
  System.Classes,
  UnitFMXdll in 'UnitFMXdll.pas',
  Unit5 in 'Unit5.pas{Form5};

{$R *.res}

exports
    CreateGrid name 'CreateGrid',
    CloseMainWindow name 'CloseNameWindow';
begin
end.
Hoffe jemand weis da vllt. etwas

Beste Grüße,
Eugeene
Miniaturansicht angehängter Grafiken
unbenannt.png  
  Mit Zitat antworten Zitat