Lazarus

Programming => LCL => Topic started by: lychee on September 17, 2019, 06:16:14 pm

Title: Add a status bar in dll-form.
Post by: lychee on September 17, 2019, 06:16:14 pm
 I'm learning code form https://wiki.lazarus.freepascal.org/Form_in_DLL.
I want add a status bar in dll-form. So I modify the TDLLDialog.Create constructor.
Code: Pascal  [Select][+][-]
  1. constructor TDLLDialog.Create(aOwner: TComponent);
  2.   var
  3.     BtnShowMessage: TButton;
  4.     StatusBar1: TStatusBar;
  5.   begin
  6.     inherited CreateNew(aOwner);
  7.  
  8.     Caption := 'This form is in a DLL !!!';
  9.     Position := poWorkAreaCenter;
  10.     Width := 200;
  11.     Height := 100;
  12.  
  13.     BtnShowMessage := TButton.Create(Self);
  14.     BtnShowMessage.Parent := Self;
  15.     BtnShowMessage.Caption := 'Show message';
  16.     BtnShowMessage.AutoSize := True;
  17.     BtnShowMessage.OnClick := @BtnShowMessageClick;
  18.     StatusBar1 := TStatusBar.Create(Self);
  19.     StatusBar1.Parent := Self;
  20.   end;          
  21.  

It’s compiled ok, but run it ,I got  Failed to create win32 control, error: 1406, Why? What’s mistake did  I made?
Title: Re: Add a status bar in dll-form.
Post by: winni on September 17, 2019, 06:40:22 pm
Hi!

Error 1406 means that for whatever reasons Windows fails to write into the registry.
I would say: disable your anti virus software and try again.

Which Windows version? In very old versions (<= 2000) it could also be, that the registry reached the maximum size.

Winni
Title: Re: Add a status bar in dll-form.
Post by: lychee on September 17, 2019, 07:00:01 pm
Hi!

Error 1406 means that for whatever reasons Windows fails to write into the registry.
I would say: disable your anti virus software and try again.

Which Windows version? In very old versions (<= 2000) it could also be, that the registry reached the maximum size.

Winni
Windows XP without  anti-virus.

FYI
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d
https://docs.microsoft.com/en-us/windows/win32/debug/system-error-codes--1300-1699-

0x0000057E

ERROR_TLW_WITH_WSCHILD

Cannot create a top-level child window.

Title: Re: Add a status bar in dll-form.
Post by: winni on September 17, 2019, 08:46:14 pm
Hu!?

https://support.microsoft.com/de-de/help/300451/windows-installer-error-1406-occurs-when-installing-software (https://support.microsoft.com/de-de/help/300451/windows-installer-error-1406-occurs-when-installing-software)

And now, Microsoft?! What is right?
Title: Re: Add a status bar in dll-form.
Post by: jamie on September 18, 2019, 12:35:35 am
My Windows Help file states this..

1406L = "Error_TLW_WITH_WSCHILD"

Which means "Tool Window as a Child Window"

 normally tool windows are not childs.

 Also, I don't know if that is actually a true dialog window or a TFORM ?

 if it's a TFORM style then you need to create using CreateNew, Not Create otherwise it will be looking for resource to load in.

Title: Re: Add a status bar in dll-form.
Post by: lychee on September 18, 2019, 05:13:55 am
My Windows Help file states this..

1406L = "Error_TLW_WITH_WSCHILD"

Which means "Tool Window as a Child Window"

 normally tool windows are not childs.

 Also, I don't know if that is actually a true dialog window or a TFORM ?

 if it's a TFORM style then you need to create using CreateNew, Not Create otherwise it will be looking for resource to load in.



Actually, the code from https://wiki.freepascal.org/Form_in_DLL works fine.
I just add a status bar in TDLLDialog.
Code: Pascal  [Select][+][-]
  1. StatusBar1 := TStatusBar.Create(Self);
  2. StatusBar1.Parent := Self;
  3.  
When you click 'Show modal form' button, You'll got 'Failed to create win32 control, error: 1406'.
Title: Re: Add a status bar in dll-form.
Post by: Cyrax on September 18, 2019, 08:17:23 am
Using LCL from DLL is not supported. Maybe upcoming dynamic package support at FPC will change that.
Title: Re: Add a status bar in dll-form.
Post by: zgabrovski on April 15, 2020, 12:55:52 pm
Confirmation: The bug is related with a StatusBar control under Windows.
Just replaced with standard panel and works fine.
LCL works fine in DLL.
Title: Re: Add a status bar in dll-form.
Post by: zgabrovski on April 15, 2020, 09:09:47 pm
So here is the solution, if you want to have a StatusBar working in your LCL form in DLL.
The problem becomes from unassigned application handle in DLL library code.
Lazarus LCL tries to creates a form with WS_CHILD style, which raises an error.

Here is the similar problem described (it is for VC++, but same problem)
https://stackoverflow.com/questions/39423719/cwindowimpl-create-returns-error-code-1406 (https://stackoverflow.com/questions/39423719/cwindowimpl-create-returns-error-code-1406)

The fix is already applied.

https://bugs.freepascal.org/view.php?id=37100 (https://bugs.freepascal.org/view.php?id=37100)

Cheers,
Zdravko
TinyPortal © 2005-2018