The RFB spec says the clipboard data should be in the ISO 8859-1 character set, but we follow several other VNC implementations in actually using Windows-1252 (which is a superset of ISO 8859-1).
DoReadTCP automatically disposes the old read buffer handle before doing the read, and then locks the new read buffer handle before returning. This removes the need for most explicit locking/unlocking of the handle. A macro is provided to dispose of the handle earlier (useful in a few cases where it may be big, and another read isn't immediately performed).
Also, set displayInProgress to FALSE in NextRect, rather than in code for each encoding.