Thank you Matthias, MFC DLLs take care about this issue by using AfxLoadLibrary() or something like that. Standard Win32 DLL does not clear after itself.
It seem to work fine. What would you recommend is case if plugin needs its own GUI called on demand? If it only FLTK potentially dangerous to use this way or any other GUI toolkit as well? Best Regards, Mikhail > > I see nothing wrong in deregistering the class, or rather ignoring that = > it is already registered. I think we can easily apply the patch.=20 > > If all this work for you in a dll, that's great, but I would not = > recommend it either. ;-) > > On 25.06.2012, at 18:02, Mikhail Tchernychev wrote: > > > C++ is not involved because I write C interface to the DLL. > > I believe plugins normally work like this, and if plugin > > has user interface it should be independent from the loader. > > For instance wxWidgets does. > >=20 > > It works on both Win and Linux, I compiled and ran examples on both > > platforms. > >=20 > > The issue is that if library in thread safe, I suppose it to run > > in a separate safely, including start up and shut down. > >=20 > > Best > > Mikhail > >=20 > >=20 > >> Note that dynamically loading/unloading code like this generally does = > =3D > >> not work and is not portable, particularly where C++ is involved... > >>=20 > >> On Jun 24, 2012, at 12:35 PM, Mikhail Tchernychev =3D > >> <[email protected]> wrote: > >>=20 > >>> Hello Everyone, > >>> =3D20 > >>> First of all many thanks for making this nice toolkit available to = > us! > >>> =3D20 > >>> I have a suggestion about improvement I see could be useful. The > >>> scenario is the following: > >>> =3D20 > >>> 1. =3D46rom another win32 application, DLL is loaded using = > LoadLibrary() > >>> 2. Library starts new thread and call FLTK program from this thread. > >>> It does work fine. > >>> 3. After job is done, library is unloaded from the program space > >>> using FreeLibrary(). > >>> =3D20 > >>> The procedure (1-3) also works under Linux using dlsym(). > >>> In fact in both cases I use pthreads :)) > >>> =3D20 > >>> The problem is that under Win32 FLTK window class is not = > unregistered =3D > >> therefore (1-3) works only once; if DLL is loaded again, FLTK tries = > to =3D > >> register class again and CreateWindowEx() function from Fl_win32.cxx = > =3D > >> fails. > >>> =3D20 > >>> I found a work around by obtaining FLTK class name in UTF16 as the =3D= > > >> following: > >>> =3D20 > >>> =3D20 > >>> wchar_t class_namew[100]; > >>> =3D20 > >>> =3D20 > >>> char class_name[100]; > >>> strcpy(class_name, "FLTK"); > >>> =3D20 > >>> // convert UTF-8 class_name to wchar_t for RegisterClassExW and =3D > >> CreateWindowExW > >>> =3D20 > >>> fl_utf8toUtf16(class_name,strlen(class_name), // in > >>> (unsigned short*)class_namew, // out > >>> sizeof(class_namew)/sizeof(wchar_t)); > >>> =3D20 > >>> =3D20 > >>> Now in DllMain wheh DLL is unloaded I call > >>> =3D20 > >>> case DLL_PROCESS_DETACH: > >>> HINSTANCE hInst =3D3D GetModuleHandle(NULL); > >>> BOOL ret =3D3D UnregisterClass(class_namew, hInst); > >>> =3D20 > >>> After these fixes DLL can be loaded and FLTK code used multiple > >>> times. > >>> =3D20 > >>> I would suggest to add something to Fl class to allow user to > >>> unregister class under Win32 on demand, or have access to class ATOM = > =3D > >> This would help if class name in future versions would change. > >>> =3D20 > >>> Just a suggestion, > >>> =3D20 > >>> Best Regards, > >>> =3D20 > >>> Mikhail > >>> =3D20 > >>> =3D20 > >>> =3D20 > >>> =3D20 > >>> _______________________________________________ > >>> fltk-dev mailing list > >>> [email protected] > >>> http://lists.easysw.com/mailman/listinfo/fltk-dev > >>=20 > >> _____________ > >> Michael Sweet > >>=20 > >=20 > > _______________________________________________ > > fltk-dev mailing list > > [email protected] > > http://lists.easysw.com/mailman/listinfo/fltk-dev > _______________________________________________ fltk-dev mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk-dev
