Recent

Author Topic: Add a status bar in dll-form.  (Read 715 times)

lychee

  • Newbie
  • Posts: 3
Add a status bar in dll-form.
« 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?

winni

  • Hero Member
  • *****
  • Posts: 1359
Re: Add a status bar in dll-form.
« Reply #1 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

lychee

  • Newbie
  • Posts: 3
Re: Add a status bar in dll-form.
« Reply #2 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.

« Last Edit: September 17, 2019, 07:02:03 pm by lychee »

winni

  • Hero Member
  • *****
  • Posts: 1359

jamie

  • Hero Member
  • *****
  • Posts: 2942
Re: Add a status bar in dll-form.
« Reply #4 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.

Number 1 at blue screen app creations!

lychee

  • Newbie
  • Posts: 3
Re: Add a status bar in dll-form.
« Reply #5 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'.

Cyrax

  • Hero Member
  • *****
  • Posts: 806
Re: Add a status bar in dll-form.
« Reply #6 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.

zgabrovski

  • New Member
  • *
  • Posts: 18
Re: Add a status bar in dll-form.
« Reply #7 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.
« Last Edit: April 15, 2020, 12:57:45 pm by zgabrovski »

zgabrovski

  • New Member
  • *
  • Posts: 18
Re: Add a status bar in dll-form.
« Reply #8 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

To solve the case you just need to assign in your DLL function application handle to be = to caller application handle.

My code is (in dll):
Code: Pascal  [Select][+][-]
  1. function InitReportlibrary( AppHnd: THandle; DBParams : PChar; IsWin1251 : Integer  ) : Integer; stdcall;
  2. var L : TStringlist;
  3. begin
  4. L := TStringList.Create;
  5. ParentHandle := AppHnd;
  6. fIsWin1251 := IsWin1251;
  7. Result := -1;
  8. try
  9.   LastErr := '';
  10.   if IsWin1251<>0 then
  11.     L.Text := CP1251ToUTF8( DBParams )
  12.   else
  13.     L.Text := DBParams;
  14.   Application.Initialize;
  15.   Application.Handle := AppHnd;  //<-------- The MAGIC!
  16.   DataModule2 :=  TDataModule2.Create( Application ) ;
  17.   MainForm := TMainForm.Create( Application );      
  18. .................
  19.  

Cheers,
Zdravko


 

TinyPortal © 2005-2018