In Windows 10 , something is wrong, ucrtbased.dll spits exceptions:

An unhandled exception at 0x542FF4E9 (ucrtbased.dll) in some.exe: 0xC000041D: An unhandled exception was detected during a user callback.

 #if !_WIN64 #define swinp SetWindowLong #define gwinp GetWindowLong #define WINC_PTR GWL_USERDATA #else #define swinp SetWindowLongPtr #define gwinp GetWindowLongPtr #define WINC_PTR GWLP_USERDATA #endif // _WIN64 

The code in which the exception occurs:

 LRESULT window_base::p_msg_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { window_base* self_; if (uMsg == WM_NCCREATE) { swinp(hWnd, WINC_PTR, LONG(LPCREATESTRUCT(lParam)->lpCreateParams)); return TRUE; } self_ = reinterpret_cast<window_base*>(gwinp(hWnd, WINC_PTR)); if (!self_) return DefWindowProc(hWnd, uMsg, wParam, lParam); // Именно тут return self_->msg_proc(hWnd, uMsg, wParam, lParam); } 

The msg_proc is a purely virtual f-tion protected:

 virtual LRESULT WINAPI msg_proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) = 0; 

The message number at which the exception is thrown: WM_CANCELMODE

    1 answer 1

    It is necessary to get rid of these defains, they are absolutely useless. Setting the pointer to user data is done incorrectly, the pointer is cast into the LONG type, thereby potentially deteriorating.

     if(WM_NCCREATE == uMsg) { assert(0 != lParam); auto const & params{*reinterpret_cast<::LPCREATESTRUCT>(lParam)}; auto const old_value{::SetWindowLongPtrW(hWnd, GWLP_USERDATA, reinterptre_cast<::LONG_PTR>(params.lpCreateParams))} assert(0 == old_value); return TRUE; } 

    Also check the code that assigns the value to the lpCreateParams field.

    • Assigned directly to CreateWindowEx - LLENN