Solved

FireMonkey DLL doesn't stay active

Posted on 2014-09-13
6
217 Views
Last Modified: 2014-09-14
I have a VCL that calls a DLL written in FireMonkey.

When I call it, it immediately returns, rather than staying active. It should stay active, as it has a lot to do, and much user interface to handle.
library LangDLL;
{$R *.dres}
uses
  FMX.Forms,
  System.SysUtils,
  System.Classes,
  uMMain in 'uMMain.pas';
{$R *.res}
procedure ShowMobile(Language: ShortString; Directory: ShortString;
      AppDir: ShortString); export;
var
  MM: TfMMain;
  test: string;
begin
  test := 'OK';
try
  MM := TfMMain.Create(application);
  MM.DLL := true;
  MM.AppDir := AppDir;
  MM.Language := Language;
  MM.SubDir := Directory;
  MM.ShowModal;
  MM.Free;
except
  test := 'Failed';
end;
end;
exports
  ShowMobile;
begin
end.

Open in new window


Also, even though the debugger shows that the logic is passing through the Free command, the FireMonkey form appears to persist, and then the system destroys it a few seconds after the parent program has ended.

When the code in the DLL is compiled as a stand-alone Windows32 exe, it works fine.
0
Comment
Question by:GrahamDLovell
  • 5
6 Comments
 

Author Comment

by:GrahamDLovell
ID: 40321397
Here is progress so far:

Both PChar and ShortString don't seem to work in passing parameters to FireMonkey. I changed them to string, and put ShareMem in both the DLL library and the calling program's uses clause (as instructed in the DLL). After I did this the variables passed to FireMonkey OK.

When the variables were correctly passed, the DLL didn't (invisibly) crash, and so ShowModal worked as expected. (I need more error checking in the DLL!)

After exiting ShowModal, the program passes through MM.Free, but doesn't actually release the form. It stays current even after the calling program is closed. My best guess is something is still un-freed in the DLL - but if anyone has a better idea, please let me know.
0
 

Author Comment

by:GrahamDLovell
ID: 40321404
Is there a way in the IDE to list all the resources that have not yet been "freed" at any moment in time? In the meantime, I will make a list of them all, and check each one.
0
 

Author Comment

by:GrahamDLovell
ID: 40321412
Next result - The Fire Monkey DLL does not appear to have any "un-freed" resources at the time of closing, but after going through that , it loops through procedures in FMX.Platform.Win trying to close everything down, but apparently not succeeding.

Any suggestions?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:GrahamDLovell
ID: 40321561
Even cutting down the FMX DLL to a single TEdit does not fix the problem of the DLL not closing its Windows interface.

I have a work-around for my particular application, a simple one - don't use the DLL method, use ExecuteShell.

Here is my function, copied and cosmetically modified from http://delphi.about.com/od/windowsshellapi/a/executeprogram.htm
function TfMain.ExecuteShell(ProgStr, Params: string): boolean;
var
  SEInfo: TShellExecuteInfo;
  ExitCode: DWORD;
begin
  FillChar(SEInfo, SizeOf(SEInfo), 0) ;
  SEInfo.cbSize := SizeOf(TShellExecuteInfo) ;
  with SEInfo do
  begin
    fMask := SEE_MASK_NOCLOSEPROCESS;
    Wnd := Application.Handle;
    lpFile := PChar(ProgStr) ;
    { ParamString can contain the application parameters. }
    if Params <> '' then
      lpParameters := PChar(Params) ;
    { StartInString specifies the name of the working directory.
      If ommited, the current directory is used. }
    // lpDirectory := PChar(StartInString) ;
    nShow := SW_SHOWNORMAL;
  end;
  result := true;
  if ShellExecuteEx(@SEInfo) then
  begin
    repeat
      Application.ProcessMessages;
      GetExitCodeProcess(SEInfo.hProcess, ExitCode) ;
    until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
  end
  else
  begin
    ShowMessage('Error starting this process') ;
    result := false;
  end;
end;

Open in new window


If there is a fix / workaround for my FMX DLL problem, please reply.
0
 
LVL 26

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 40322115
0
 

Author Closing Comment

by:GrahamDLovell
ID: 40322155
My original question was fixed by fixing a bug in my own code (as I noted above), but Sinisa's sample app is very helpful in writing the interface for FireMonkey DLLs, supplementing the demonstration code at http://blogs.embarcadero.com/stephenball/2011/10/10/writing-a-firemonkey-dll-for-use-with-a-vcl-application/#comment-0. Here the finalization routine is either wrong or out-of-date (for XE6) or there is something else going on about which I know nothing. In any event, removing the finalization code fixed the problem.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Thread safe  opinion 7 126
Delphi component that can load a DLL in design time? 8 53
delphi parse string to params 3 101
How to load 2 images in same column in Delphi 2 35
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now