On Fri, 6 Jul 2012 10:41:37 -0700 Mikhail Tchernychev wrote:
MT> 1. Main application (whatever toolkit is used) loads library dynamically
MT> using LoadLibrary() under MSW or loading shared object under Linux.
MT>
MT> 2. If DLL is loaded, main program starts new thread using pthreads library
MT> or its port under windows. For simplicity, main application may block
MT> and wait till thread terminates.
MT>
MT> 3. Newly created thread call wxWidget application. It appeared to me
MT> the that it is enough to replace (example)
MT>
MT> IMPLEMENT_APP(MyApp)
MT>
MT> with
MT>
MT> wxIMPLEMENT_APP_NO_MAIN(MyApp);
MT>
MT> int main_test() {
MT> int argc =0;
MT> char *argv[1];
MT> argv[0] = "app";
MT> ::wxEntry(argc, argv);
MT> return 0;
MT> }
MT>
MT> now thread calls main_test() and it makes complete winWidgets
MT> application appear on the screen.
MT>
MT> 4. There is no interaction between main thread and wxWidgets trhread.
MT>
MT> My main concern is: Is it safe to do it this way?
Yes.
MT> I did look into provided "dll" example in the wxWidgets 2.3.9 samples
MT> folder and it is only applicable to windows.
Yes, because there are extra problems with HINSTANCE and such there which
don't exist under Unix. But in principle the same approach should work
under Unix too and it would be nice to modify the sample to build there
too.
MT> It also seems to me that ::wxEntry(int argc, char **argv) should take
MT> cake about HINSTANCE for the thread, as well as for clean up.
HINSTANCE is global, not per-thread, so I'm not sure what do you mean.
If you can pass HINSTANCE of the DLL in the main application itself (you
obtain it from LoadLibrary()) then you could avoid the call to
MSWGetModuleHandle() in the DLL code. But OTOH doing it like the sample
does makes it self-contained and doesn't have any real drawbacks.
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/