PDA

View Full Version : LCL and DLLs, initializing the widget set safely?



cronodragon
08-12-2009, 12:32 PM
Hello PGD guys! :)

I'm trying to create a dll with an LCL form, and found that is not working. After looking around I found several posts that say LCL is not working in DLL, like: http://www.mail-archive.com/lazarus@miraclec.com/msg16490.html

I traced down the problem, and it seems the widget set is not being initialized in the DLL. While debbuging I got this:

---------------------------------------------
TWinControl.GetHandle Creating handle on the fly: :TForm1
WARNING:[TWinControl.HandleNeeded] creating handle for TForm1 while destroying handles!
[TWinControl.CreateWnd] START :TForm1
TWinControl.CreateWnd (V)TWin32WSCustomForm :TForm1
FinishCreateWindow :: CreateWindowEx pClassName=Window, WindowTitle=
Failed to create win32 control, error: 1407 : No se ha encontrado la clase de ventana.
[FORMS.PP] ExceptionOccurred
Sender=Exception
Exception=Failed to create win32 control, error: 1407 : No se ha encontrado la clase de ventana.
Stack trace:
$1011936D FINISHCREATEWINDOW, line 226 of win32wscontrols.pp
TApplication.HandleException Failed to create win32 control, error: 1407 : No se ha encontrado la clase de ventana.
Stack trace:
$1011936D FINISHCREATEWINDOW, line 226 of win32wscontrols.pp
---------------------------------------------

According to that, there is an exception at win32wscontrols.pp, function FinishCreateWindow(), because CreateWindow() is being called without registering the window class. And that function is called when trying to resolve the window's handle.

I found that applications register the window class with calls to TApplication.Initialize() -> WidgetSet.AppInit() -> WinRegister()

Without knowledge of LCL's internals, I tried to call those methods and functions from the DLL's initialization section, but it didn't work. The exception was gone, but the DLL still failed and broke the debug information. Could someone with knowledge of the LCL tell if it's possible to initialize the widget set in the DLL, and how should that be done to be safely?

Regards!
-Marco

JSoftware
08-12-2009, 02:34 PM
As far as I can remember that bug is still acknowledged, and unresolved. Why would you want to do that anyways? :)

cronodragon
09-12-2009, 02:25 PM
Why? Because it can be solved hehehe! Indeed I solved it yesterday ;) Now I have a Netscape plugin running in Firefox 3.5 created with LCL/Win32 :yes:

Lazarus rules!