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,
> 
> First of all many thanks for making this nice toolkit available to us!
> 
> I have a suggestion about improvement I see could be useful. The
> scenario is the following:
> 
> 1. From 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().
> 
> The procedure (1-3) also works under Linux using dlsym().
> In fact in both cases I use pthreads :))
> 
> 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.
> 
> I found a work around by obtaining FLTK class name in UTF16 as the following:
> 
> 
> wchar_t class_namew[100];
> 
> 
> char class_name[100];
> strcpy(class_name, "FLTK");
> 
>  // convert UTF-8 class_name to wchar_t for RegisterClassExW and 
> CreateWindowExW
> 
> fl_utf8toUtf16(class_name,strlen(class_name),         // in
>                (unsigned short*)class_namew,          // out
>                sizeof(class_namew)/sizeof(wchar_t));
> 
> 
> Now in DllMain wheh DLL is unloaded I call
> 
>       case DLL_PROCESS_DETACH:
>            HINSTANCE hInst = GetModuleHandle(NULL);
>            BOOL ret = UnregisterClass(class_namew,  hInst);
> 
> After these fixes DLL can be loaded and FLTK code used multiple
> times.
> 
> 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.
> 
> Just a suggestion,
> 
> Best Regards,
> 
> Mikhail
> 
> 
> 
> 
> _______________________________________________
> 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

Reply via email to