{"id":109632,"date":"2024-04-10T07:00:00","date_gmt":"2024-04-10T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=109632"},"modified":"2024-04-06T08:45:50","modified_gmt":"2024-04-06T15:45:50","slug":"20240410-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20240410-00\/?p=109632","title":{"rendered":"How can I find out which process has locked me out of the clipboard?"},"content":{"rendered":"<p>A customer was trying to figure out why their program ran into sporadic problems where its attempts to access the clipboard fail with the error <code>CLIPBRD_<wbr \/>E_<wbr \/>CANT_<wbr \/>OPEN<\/code>. They were wondering if there was a way to figure out the source of the problem, or at least some data they could collect to include with their telemetry so they could try to analyze the problem on their back end.<\/p>\n<p>There are two functions for getting handles to windows related to the clipboard. The functions have similar names, but the names are clear once you know what they mean.<\/p>\n<p>The first function is <code>Get\u00adClipboard\u00adOwner<\/code>. This is the window that had the clipboard open when it called <code>Empty\u00adClipboard<\/code>, presumably in preparation for calling <code>Set\u00adClipboard\u00adData<\/code> to put new data on the clipboard. The clipboard owner is the window which will receive messages like <code>WM_<wbr \/>RENDER\u00adFORMAT<\/code> and <code>WM_<wbr \/>DESTROY\u00adCLIPBOARD<\/code> to inform it about requests to produce or destroy clipboard data.<\/p>\n<p>The clipboard owner is <i>not<\/i> the window that prevented you from accessing the clipboard.\u00b9<\/p>\n<p>The window that prevented you from opening the window is reported by the <code>Get\u00adOpen\u00adClipboard\u00adWindow<\/code> function. This is the window handle that was passed to <code>Open\u00adClipboard<\/code>, and for which there has yet to be a corresponding <code>Close\u00adClipboard<\/code>.<\/p>\n<p>Note that if your call to <code>Open\u00adClipboard<\/code> fails, it&#8217;s possible that your call to <code>Get\u00adOpen\u00adClipboard\u00adWindow<\/code> might return <code>NULL<\/code>. There is of course a race condition where the clipboard opener closes the clipboard just before you call <code>Get\u00adOpen\u00adClipboard\u00adWindow<\/code>. Another possibility is that the code that opened the clipboard passed <code>NULL<\/code> as the window handle, so there is no handle to return to you.<\/p>\n<p>But if you&#8217;re just calling it for diagnostic purposes, say, to log why you got locked out of the clipboard, then these cautions aren&#8217;t really a big deal. You&#8217;re not responding programmatically to the clipboard opener; you&#8217;re just doing some logging to help understand the problem.<\/p>\n<p>\u00b9 I mean, it might happen to be the window just by coincidence.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can ask for the clipboard opener.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-109632","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You can ask for the clipboard opener.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/109632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=109632"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/109632\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=109632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=109632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=109632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}