Support case where win32socketserver's window class is not unregistered properly.
Either from failure to shutdown or when instantiated in a dll that is loaded or unloaded multiple times within a single process lifetime. Change-Id: I52b05a6d84c9312fbd45aaa34ed3f49566daadfd Bug: b/140961297 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/155987 Commit-Queue: Tommi <tommi@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29574}
This commit is contained in:
@ -19,24 +19,16 @@ namespace rtc {
|
|||||||
// Win32Window
|
// Win32Window
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static const wchar_t kWindowBaseClassName[] = L"WindowBaseClass";
|
static const wchar_t kWindowBaseClassName[] = L"RtcWindowBaseClass";
|
||||||
HINSTANCE Win32Window::instance_ = nullptr;
|
HINSTANCE Win32Window::instance_ = nullptr;
|
||||||
ATOM Win32Window::window_class_ = 0;
|
ATOM Win32Window::window_class_ = 0;
|
||||||
|
|
||||||
Win32Window::Win32Window() : wnd_(nullptr) {}
|
Win32Window::Win32Window() : wnd_(nullptr) {}
|
||||||
|
|
||||||
Win32Window::~Win32Window() {
|
Win32Window::~Win32Window() { RTC_DCHECK(nullptr == wnd_); }
|
||||||
RTC_DCHECK(nullptr == wnd_);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Win32Window::Create(HWND parent,
|
bool Win32Window::Create(HWND parent, const wchar_t* title, DWORD style,
|
||||||
const wchar_t* title,
|
DWORD exstyle, int x, int y, int cx, int cy) {
|
||||||
DWORD style,
|
|
||||||
DWORD exstyle,
|
|
||||||
int x,
|
|
||||||
int y,
|
|
||||||
int cx,
|
|
||||||
int cy) {
|
|
||||||
if (wnd_) {
|
if (wnd_) {
|
||||||
// Window already exists.
|
// Window already exists.
|
||||||
return false;
|
return false;
|
||||||
@ -51,8 +43,16 @@ bool Win32Window::Create(HWND parent,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Class not registered, register it.
|
// Register or reregister the class as necessary. window_class_ == nullptr
|
||||||
|
// is not an infallible indicator that the class is unregistered.
|
||||||
WNDCLASSEXW wcex;
|
WNDCLASSEXW wcex;
|
||||||
|
memset(&wcex, 0, sizeof(wcex));
|
||||||
|
wcex.cbSize = sizeof(wcex);
|
||||||
|
if (::GetClassInfoExW(instance_, kWindowBaseClassName, &wcex) &&
|
||||||
|
!::UnregisterClassW(kWindowBaseClassName, instance_)) {
|
||||||
|
RTC_LOG_GLE(LS_ERROR) << "UnregisterClass failed.";
|
||||||
|
}
|
||||||
|
|
||||||
memset(&wcex, 0, sizeof(wcex));
|
memset(&wcex, 0, sizeof(wcex));
|
||||||
wcex.cbSize = sizeof(wcex);
|
wcex.cbSize = sizeof(wcex);
|
||||||
wcex.hInstance = instance_;
|
wcex.hInstance = instance_;
|
||||||
@ -76,14 +76,14 @@ void Win32Window::Destroy() {
|
|||||||
|
|
||||||
void Win32Window::Shutdown() {
|
void Win32Window::Shutdown() {
|
||||||
if (window_class_) {
|
if (window_class_) {
|
||||||
::UnregisterClass(MAKEINTATOM(window_class_), instance_);
|
if (!::UnregisterClass(MAKEINTATOM(window_class_), instance_)) {
|
||||||
|
RTC_LOG_GLE(LS_ERROR) << "UnregisterClass failed.";
|
||||||
|
}
|
||||||
window_class_ = 0;
|
window_class_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Win32Window::OnMessage(UINT uMsg,
|
bool Win32Window::OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam,
|
||||||
WPARAM wParam,
|
|
||||||
LPARAM lParam,
|
|
||||||
LRESULT& result) {
|
LRESULT& result) {
|
||||||
switch (uMsg) {
|
switch (uMsg) {
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
@ -96,17 +96,13 @@ bool Win32Window::OnMessage(UINT uMsg,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Win32Window::OnClose() {
|
bool Win32Window::OnClose() { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Win32Window::OnNcDestroy() {
|
void Win32Window::OnNcDestroy() {
|
||||||
// Do nothing. }
|
// Do nothing. }
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT Win32Window::WndProc(HWND hwnd,
|
LRESULT Win32Window::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
||||||
UINT uMsg,
|
|
||||||
WPARAM wParam,
|
|
||||||
LPARAM lParam) {
|
LPARAM lParam) {
|
||||||
Win32Window* that =
|
Win32Window* that =
|
||||||
reinterpret_cast<Win32Window*>(::GetWindowLongPtr(hwnd, GWLP_USERDATA));
|
reinterpret_cast<Win32Window*>(::GetWindowLongPtr(hwnd, GWLP_USERDATA));
|
||||||
|
Reference in New Issue
Block a user