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.
It works on both Win and Linux, I compiled and ran examples on both platforms. The issue is that if library in thread safe, I suppose it to run in a separate safely, including start up and shut down. Best Mikhail > Note that dynamically loading/unloading code like this generally does = > not work and is not portable, particularly where C++ is involved... > > On Jun 24, 2012, at 12:35 PM, Mikhail Tchernychev = > <[email protected]> wrote: > > > Hello Everyone, > >=20 > > First of all many thanks for making this nice toolkit available to us! > >=20 > > I have a suggestion about improvement I see could be useful. The > > scenario is the following: > >=20 > > 1. =46rom 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(). > >=20 > > The procedure (1-3) also works under Linux using dlsym(). > > In fact in both cases I use pthreads :)) > >=20 > > The problem is that under Win32 FLTK window class is not unregistered = > therefore (1-3) works only once; if DLL is loaded again, FLTK tries to = > register class again and CreateWindowEx() function from Fl_win32.cxx = > fails. > >=20 > > I found a work around by obtaining FLTK class name in UTF16 as the = > following: > >=20 > >=20 > > wchar_t class_namew[100]; > >=20 > >=20 > > char class_name[100]; > > strcpy(class_name, "FLTK"); > >=20 > > // convert UTF-8 class_name to wchar_t for RegisterClassExW and = > CreateWindowExW > >=20 > > fl_utf8toUtf16(class_name,strlen(class_name), // in > > (unsigned short*)class_namew, // out > > sizeof(class_namew)/sizeof(wchar_t)); > >=20 > >=20 > > Now in DllMain wheh DLL is unloaded I call > >=20 > > case DLL_PROCESS_DETACH: > > HINSTANCE hInst =3D GetModuleHandle(NULL); > > BOOL ret =3D UnregisterClass(class_namew, hInst); > >=20 > > After these fixes DLL can be loaded and FLTK code used multiple > > times. > >=20 > > 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 = > This would help if class name in future versions would change. > >=20 > > Just a suggestion, > >=20 > > Best Regards, > >=20 > > Mikhail > >=20 > >=20 > >=20 > >=20 > > _______________________________________________ > > fltk-dev mailing list > > [email protected] > > http://lists.easysw.com/mailman/listinfo/fltk-dev > > _____________ > Michael Sweet > _______________________________________________ fltk-dev mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk-dev
