Who can give me a sample for how to using boost::thread in a MFC regular dll?

Hello everyone! I have a MFC application that using boost::thread, it runs well. Now I wrapped it to a MFC regular dll, but I get a assertion error when I using this dll. // (In my another MFC dialog application) void AFXAPI AfxCoreInitModule() { ASSERT(AfxGetModuleState() != AfxGetAppModuleState()); // assertion error // the return value of AfxGetModuleState() and AfxGetAppModuleState() are both not-empty, // but they are different. ... } Any advice? thanks!

Hi,
On Sun, Apr 18, 2010 at 2:18 PM, DDGG
Hello everyone!
I have a MFC application that using boost::thread, it runs well. Now I wrapped it to a MFC regular dll, but I get a assertion error when I using this dll.
// (In my another MFC dialog application) void AFXAPI AfxCoreInitModule() { ASSERT(AfxGetModuleState() != AfxGetAppModuleState()); // assertion error // the return value of AfxGetModuleState() and AfxGetAppModuleState() are both not-empty, // but they are different. ... }
Any advice? thanks!
Try adding at the begining of each exported function this line AFX_MANAGE_STATE(AfxGetStaticModuleState()); Cheers,

Thanks for your help, but it is no way...
I have placed my sample project to:
http://ddgg.50webs.com/TestBoostThreadDll.rar
World you like to help me? Thanks a lot!
2010/4/19 Ismael Bejarano
Hi,
On Sun, Apr 18, 2010 at 2:18 PM, DDGG
wrote: Hello everyone!
I have a MFC application that using boost::thread, it runs well. Now I wrapped it to a MFC regular dll, but I get a assertion error when I using this dll.
// (In my another MFC dialog application) void AFXAPI AfxCoreInitModule() { ASSERT(AfxGetModuleState() != AfxGetAppModuleState()); // assertion error // the return value of AfxGetModuleState() and AfxGetAppModuleState() are both not-empty, // but they are different. ... }
Any advice? thanks!
Try adding at the begining of each exported function this line AFX_MANAGE_STATE(AfxGetStaticModuleState());
Cheers, _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Hi,
On Mon, Apr 19, 2010 at 12:24 PM, DDGG
Thanks for your help, but it is no way... I have placed my sample project to: http://ddgg.50webs.com/TestBoostThreadDll.rar
World you like to help me? Thanks a lot!
I've tried with VS 2005 with boost-1.42 and it work as expected (I've to replace CWinAppEx with CWinApp because they don't exists in VS2005). Sorry, but I don't have VS 2008. Cheers,

You are very kind, thank you for your help!
I have found the solution, at the last reply of this:
http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/ec0ce12e-d54d...
// extern BOOL (WINAPI * const _pRawDllMain)(HANDLE, DWORD,
LPVOID)=&dll_callback;
I commented it and recompiled the boost library, and then the problem
disappeared.
2010/4/20 Ismael Bejarano
Hi,
On Mon, Apr 19, 2010 at 12:24 PM, DDGG
wrote: Thanks for your help, but it is no way... I have placed my sample project to: http://ddgg.50webs.com/TestBoostThreadDll.rar
World you like to help me? Thanks a lot!
I've tried with VS 2005 with boost-1.42 and it work as expected (I've to replace CWinAppEx with CWinApp because they don't exists in VS2005). Sorry, but I don't have VS 2008.
Cheers, _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

DDGG
You are very kind, thank you for your help! I have found the solution, at the last reply of this: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/ec0ce12e-d54d...
// extern BOOL (WINAPI * const _pRawDllMain)(HANDLE, DWORD, LPVOID)=&dll_callback; I commented it and recompiled the boost library, and then the problem disappeared.
If you do that then you are liable to leak memory and potentially resources if you use any boost.thread facilities from any thread not started with boost::thread. In particular, boost::thread_specific_ptr variables will not be destroyed when a non-boost::thread thread exits, but other uses of the boost thread library may also leak memory. The best option in this case is to use the DLL build of boost.thread. Anthony -- Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/ just::thread C++0x thread library http://www.stdthread.co.uk Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
participants (3)
-
Anthony Williams
-
DDGG
-
Ismael Bejarano