Narrowing the problem. The locking issue was not an issue after all.
But the clipboard remains inaccessible.
The issue can be replicated by having a second clipboard viewer run
after mine is running. In other words, it seems to be a clipboard
chain problem. The crazy thing now is that all one needs to do to be
added to the clipboard chain is to call
m_hNextClipboardViewer = SetClipboardViewer();
which my app does in the OnInitDialog handler. No messages are sent
when a second viewer becomes active later on. The only other message
is on _removal_ and that one I handle as follows:
void CMyDlg::OnChangeCbChain(HWND hWndRemove, HWND hWndAfter)
if ( m_hNextClipboardViewer == hWndRemove )
m_hNextClipboardViewer = hWndAfter;
else if ( m_hNextClipboardViewer != NULL )
// If there is a next clipboard viewer, pass the message on to it
::SendMessage( m_hNextClipboardViewer, WM_CHANGECBCHAIN, (WPARAM)
hWndRemove, (LPARAM)hWndAfter );
That is, standard stuff. Of course, the problem occurs before
OnChangeCbChain is called since the problem occurs when the second
viewer starts, not when it is removed.
So, summing up. When a second viewer starts, my viewer fails to work
(OpenClipboard works ok, GetClipboardData returns NULL, that is, no
access to clipboard data). Before and after the second viewer is run,
everything is fine. While a second viewer is running, the clipboard