Anders Melander 1301 Posted March 23 2 hours ago, KodeZwerg said: Somewhere I've done a mistake, when I remove the "halt" app going into a deadlock. function WindowProc(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin case Msg of WM_DESTROY: begin PostQuitMessage(0); Exit(0); end; else Result := DefWindowProc(hWnd, Msg, wParam, lParam); end; end; procedure RunClient; begin UpdateWindow(LHWND); while (integer(GetMessage(LMsg, LHWND, 0, 0)) > 0) do begin if (LMsg.message = WM_QUIT) then begin PostQuitMessage(0); break; end; TranslateMessage(LMsg); DispatchMessage(LMsg); end; UnregisterClass(PChar(GClassName), LInst); end; The main problem was that GetMessage is declared to return a BOOL but it actually returns an integer. Specifically, it returns -1 when the message queue has been destroyed. 1 Share this post Link to post