fix crash where a shared lib is loaded/unloaded repeatedly

When a shared lib which uses nana is dynamic loaded/unloaded multiple
times, the crash would occur when creating a form after reloading the shared lib
This commit is contained in:
Jinhao
2019-08-14 03:39:26 +08:00
parent 15a015aa4e
commit e37cc5ec37
2 changed files with 17 additions and 4 deletions

View File

@@ -173,15 +173,22 @@ namespace detail
static LRESULT WINAPI Bedrock_WIN32_WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
HINSTANCE windows_module_handle()
{
MEMORY_BASIC_INFORMATION mbi;
static int dummy;
VirtualQuery(&dummy, &mbi, sizeof(mbi));
return reinterpret_cast<HINSTANCE>(mbi.AllocationBase);
}
bedrock::bedrock()
: pi_data_(new pi_data),
impl_(new private_impl)
{
nana::detail::platform_spec::instance(); //to guaranty the platform_spec object is initialized before using.
WNDCLASSEX wincl;
wincl.hInstance = ::GetModuleHandle(0);
wincl.hInstance = windows_module_handle();
wincl.lpszClassName = L"NanaWindowInternal";
wincl.lpfnWndProc = &Bedrock_WIN32_WindowProc;
wincl.style = CS_DBLCLKS | CS_OWNDC;
@@ -229,6 +236,8 @@ namespace detail
delete impl_;
delete pi_data_;
::UnregisterClass(L"NanaWindowInternal", windows_module_handle());
}