View Issue Details

IDProjectCategoryView StatusLast Update
0037079PackagesLCLpublic2020-05-17 21:50
ReporterZdravko Gabrovski Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformWindowsOSWindowl 
Summary0037079: Fix that solves the problem with Popup-menu under LCL Windows - DLL
DescriptionProvided patch fix the problem, described here:
https://stackoverflow.com/questions/24586440/popupmenu-does-not-show-when-in-dll
and here:
https://forum.lazarus.freepascal.org/index.php/topic,24135.msg144938.html#msg144938
Also fix the problem with "Error 1406" , described here:
https://forum.lazarus.freepascal.org/index.php?topic=46780.0

All this comes, because in TWin32WidgetSet.AppInit missing "CreateAppHandle" when it is a dll library.
Steps To ReproduceAs described in forum topics above.
TagsNo tags attached.
Fixed in Revision
LazTarget
WidgetsetWin32/Win64
Attached Files

Relationships

related to 0037072 closedJuha Manninen Inplace DBLookupComboBox editor inside DB Grid Raise "Division by zero" in DLL under Windows 7 when component is free 

Activities

Zdravko Gabrovski

2020-05-15 11:02

reporter  

win32object.diff (505 bytes)   
Index: lcl/interfaces/win32/win32object.inc
===================================================================
--- lcl/interfaces/win32/win32object.inc	(revision 63135)
+++ lcl/interfaces/win32/win32object.inc	(working copy)
@@ -142,8 +142,9 @@
     // set nice main icon
     AIcon := Windows.LoadIcon(MainInstance, 'MAINICON');
     AppSetIcon(AIcon, AIcon);
-  end;
-
+  end
+  else
+    CreateAppHandle;
   // initialize ScreenInfo
   Handle := GetDesktopWindow;
   DC := Windows.GetDC(Handle);
win32object.diff (505 bytes)   

Michael Van Canneyt

2020-05-15 11:10

administrator   ~0122813

Last edited: 2020-05-15 11:11

View 2 revisions

I am not sure this is the correct solution.
Normally, when using a library the main program passes its application handle to the library.
AFAIK the library should not create its own handle.
That's why many of the Windows API calls require you to pass an application handle.

Zdravko Gabrovski

2020-05-16 09:33

reporter   ~0122842

I tried everything, even to pass a host app handle to a dll library and assign it to the dll application. Handle, but the problem still exists.

nanobit

2020-05-16 09:43

reporter   ~0122843

Generally, please stop changing the LCL to workaround application mistakes,
as I have commented in other issue 0037072

Zdravko Gabrovski

2020-05-16 11:17

reporter   ~0122846

If you tell me where is the mistake, I will fix it.
I will attach a small sample project do demonstrate the problem.

Juha Manninen

2020-05-16 11:48

developer   ~0122848

I added a note in the related 0037072.
If the problem can be fixed in a client application, the commit can be reverted.

jamie philbrook

2020-05-16 12:16

reporter   ~0122849

I thought that was the reason why we needed a TApplication instance in the DLL ?

What will this do now with OS resources In a normal app, has anyone checked ?

Zdravko Gabrovski

2020-05-16 13:01

reporter   ~0122851

Please, find attached a two sample projects inside archive:
HosApp - project for host application (caller)
DllApp - Project for dll application (Calee).

Soon I will attach a sample video that I am creating at the moment, that will demmonstrate the probem.

I'm not saying that's the way to do it. I would be very happy if more people get involved to solve the problem.
DllFormsBug.7z (54,217 bytes)

Zdravko Gabrovski

2020-05-16 13:20

reporter   ~0122852

Plese, find attached videos
https://www.youtube.com/watch?v=ARUOQYeYaGY
https://www.youtube.com/watch?v=xNBMQKBfxDk
https://www.youtube.com/watch?v=CDcu4AJpfZE

All the sources are in the previous post.

nanobit

2020-05-16 17:33

reporter   ~0122856

As in your given link, the basic concept must be more like this:
https://wiki.freepascal.org/Form_in_DLL
Passing some hosthandle (ParentFormHandle) to the dll form.

Zdravko Gabrovski

2020-05-16 17:58

reporter   ~0122857

Nanobit, many thanks for the time, you spent with my case!

I looked over the given example very carefully, but it is not my case.
In my case, I want to use in my library(it is dll plug-in) standard forms and LazReport.

How to pass this ParentFormHandle to standard LazReport dialogs?
In the given example, there is a Form descendant class (TDLLDialog) which overrides method CreateParams of TCustomForm and did the "hack" with a PArentWindowHandle. It is not possible to do the same with lazreport; I am using it as a "blackbox" inside DLL (for example - there is a methods for report design, which creates a lot of internal forms). All this forms I must put somehow this parent window handle, how to do this? Is it possible to use some global variable for this ParentWindowHandle and use it in case of DLL, in CreateParams of custom form in case of dll usage?

Juha Manninen

2020-05-16 18:14

developer   ~0122858

Don't put LazReport into a DLL. Its design is not perfect with all the GUI dependencies. There is another report engine in FPC libs. It has no GUI dependency and can go to a DLL safely.
I personally would put only non-GUI stuff into shared libraries. It also promotes good design with separation of GUI and logic.

Zdravko Gabrovski

2020-05-16 18:44

reporter   ~0122859

Dear Juha, thanks for your suggestion. Generally speaking you are right.
But I have no other option.
In my case my DLL Plugin must be connected to other applications - written both in Delphi and Lazarus.
There is some issues with Lazreport , but I fixed it.
(https://bugs.freepascal.org/view.php?id=37065)
Now it works perfect.
The only problem is with status line of preview form and popup-menus.
Thanks again to your time!
Zdravko.

jamie philbrook

2020-05-16 22:34

reporter   ~0122865

So I assume your are loading this DLL after the main app as started ?
Because if you load the DLL using what I call the embedded method these get loaded before the TApplication gets initiated.

When passing handles of the host app over to the DLL the host app must first be initiated before you even LOAD the DLL..
so the DLL should be done at runtime after the app has started and the required procedures linked also at runtime..

  Are you doing all of this after the Application in the host app has started ?

Zdravko Gabrovski

2020-05-16 23:14

reporter   ~0122868

Yes I am loading DLL with SafeLoadLibrary when click the button.
The host app is started, it main form is shown, and when you click the button it will load dll dynamically.
Short answer: Yes, host app is started. The sources are attached in my note 6 messages above.

Zdravko Gabrovski

2020-05-17 21:49

reporter   ~0122890

So I found another solution of the problem without change of win32Object and Appinit.
If we did not change them, the popup menu "popup" works, only status bar does not create.
Status bar problem comes from method InitializePreferredStatusBarHeight in Win32WSComCtrls.pp
After
Parent := TWin32WidgetSet(WidgetSet).AppHandle;
Which is Zero in case of usage in dll, I add

  if ( Parent=0 ) and IsLibrary then
    Parent := Screen.ActiveForm.Handle;

Please, close this issue, I will open another one.

Zdravko Gabrovski

2020-05-17 21:50

reporter   ~0122891

So I found another solution of the problem without change of win32Object and Appinit.
If we did not change them, the popup menu "popup" works, only status bar does not create.
Status bar problem comes from method InitializePreferredStatusBarHeight in Win32WSComCtrls.pp
After
Parent := TWin32WidgetSet(WidgetSet).AppHandle;
Which is Zero in case of usage in dll, I add

  if ( Parent=0 ) and IsLibrary then
    Parent := Screen.ActiveForm.Handle;

Please, close this issue, I will open another one.

Issue History

Date Modified Username Field Change
2020-05-15 11:02 Zdravko Gabrovski New Issue
2020-05-15 11:02 Zdravko Gabrovski File Added: win32object.diff
2020-05-15 11:10 Michael Van Canneyt Note Added: 0122813
2020-05-15 11:11 Michael Van Canneyt Note Edited: 0122813 View Revisions
2020-05-16 09:33 Zdravko Gabrovski Note Added: 0122842
2020-05-16 09:43 nanobit Note Added: 0122843
2020-05-16 11:17 Zdravko Gabrovski Note Added: 0122846
2020-05-16 11:41 Juha Manninen Relationship added related to 0037072
2020-05-16 11:48 Juha Manninen Note Added: 0122848
2020-05-16 12:16 jamie philbrook Note Added: 0122849
2020-05-16 13:01 Zdravko Gabrovski Note Added: 0122851
2020-05-16 13:01 Zdravko Gabrovski File Added: DllFormsBug.7z
2020-05-16 13:20 Zdravko Gabrovski Note Added: 0122852
2020-05-16 17:33 nanobit Note Added: 0122856
2020-05-16 17:58 Zdravko Gabrovski Note Added: 0122857
2020-05-16 18:14 Juha Manninen Note Added: 0122858
2020-05-16 18:44 Zdravko Gabrovski Note Added: 0122859
2020-05-16 22:34 jamie philbrook Note Added: 0122865
2020-05-16 23:14 Zdravko Gabrovski Note Added: 0122868
2020-05-17 15:23 Juha Manninen Note View State: 0122851: private
2020-05-17 15:23 Juha Manninen Note View State: 0122813: private
2020-05-17 15:23 Juha Manninen Note View State: 0122813: public
2020-05-17 15:23 Juha Manninen Note View State: 0122851: public
2020-05-17 21:49 Zdravko Gabrovski Note Added: 0122890
2020-05-17 21:50 Zdravko Gabrovski Note Added: 0122891