{"componentChunkName":"component---src-templates-post-template-js","path":"/windows-clipboard-en","result":{"data":{"markdownRemark":{"id":"4377d256-f2ed-5b8e-98e5-79dde91a8425","html":"<blockquote>\n<p>This page has been machine-translated from the <a href=\"/windows-clipboard\">original page</a>.</p>\n</blockquote>\n<p>This time, I will summarize what I learned about Windows clipboard operations, its mechanisms, and how to inspect data, together with sample programs.</p>\n<!-- omit in toc -->\n<h2 id=\"table-of-contents\" style=\"position:relative;\"><a href=\"#table-of-contents\" aria-label=\"table of contents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Table of Contents</h2>\n<ul>\n<li>\n<p><a href=\"#about-the-windows-clipboard\">About the Windows Clipboard</a></p>\n<ul>\n<li><a href=\"#clipboard-formats\">Clipboard Formats</a></li>\n<li><a href=\"#clipboard-operations\">Clipboard Operations</a></li>\n<li><a href=\"#clipboard-ownership\">Clipboard Ownership</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#implementing-clipboard-operations\">Implementing Clipboard Operations</a></p>\n<ul>\n<li><a href=\"#read-operations-with-the-win32-api\">Read Operations with the Win32 API</a></li>\n<li><a href=\"#write-operations-with-the-win32-api\">Write Operations with the Win32 API</a></li>\n<li><a href=\"#the-ole-clipboard\">The OLE Clipboard</a></li>\n</ul>\n</li>\n<li><a href=\"#summary\">Summary</a></li>\n</ul>\n<h2 id=\"about-the-windows-clipboard\" style=\"position:relative;\"><a href=\"#about-the-windows-clipboard\" aria-label=\"about the windows clipboard permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>About the Windows Clipboard</h2>\n<p>The clipboard itself is a mechanism that allows applications to transfer data.</p>\n<p>By using clipboard functionality, users can exchange various kinds of data such as text, files, and images between different applications.</p>\n<p>Reference: <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/dataxchg/about-the-clipboard\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">About the Clipboard - Win32 apps | Microsoft Learn</a></p>\n<h3 id=\"clipboard-formats\" style=\"position:relative;\"><a href=\"#clipboard-formats\" aria-label=\"clipboard formats permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Clipboard Formats</h3>\n<p>The Windows clipboard can store not only text, but also HTML, rich text, and objects in various formats.</p>\n<p>Because of this, for example, when you copy text from a browser or editor to another application, situations can arise where not only plain text but also various kinds of information such as text decoration and background color are copied.</p>\n<p>Many commonly used data types are included in the standard Windows clipboard formats, but users can also register new clipboard formats.</p>\n<p>It also seems that applications can register what are called private formats.</p>\n<p>Reference: <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/dataxchg/clipboard-formats\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Clipboard Formats - Win32 apps | Microsoft Learn</a></p>\n<p>There are various kinds of system-predefined clipboard formats. For example, copied text appears to be automatically stored as <code class=\"language-text\">CF_UNICODETEXT</code> or <code class=\"language-text\">CF_TEXT</code>.</p>\n<p>Reference: <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/dataxchg/standard-clipboard-formats\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Standard Clipboard Formats (Winuser.h) - Win32 apps | Microsoft Learn</a></p>\n<h3 id=\"clipboard-operations\" style=\"position:relative;\"><a href=\"#clipboard-operations\" aria-label=\"clipboard operations permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Clipboard Operations</h3>\n<p>There seem to be several available ways to implement clipboard operations, but regardless of which method you use, it appears that the starting point is ultimately to open the clipboard with <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/winuser/nf-winuser-openclipboard\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">OpenClipboard function (winuser.h)</a>.</p>\n<p>Also, because only one application in the system can open the clipboard at a time, if a particular application has opened the clipboard by using the OpenClipboard function, other applications cannot open the clipboard.</p>\n<p>Reference: <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/dataxchg/clipboard-operations\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Clipboard Operations - Win32 apps | Microsoft Learn</a></p>\n<p>In practice, when I ran the following program as a test, copy and paste operations in other applications such as browsers stopped working during the sleep period after the clipboard was acquired by the OpenClipboard function.</p>\n<div class=\"gatsby-highlight\" data-language=\"c\"><pre class=\"language-c\"><code class=\"language-c\"><span class=\"token macro property\"><span class=\"token directive-hash\">#</span><span class=\"token directive keyword\">include</span> <span class=\"token string\">&lt;windows.h></span></span>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#</span><span class=\"token directive keyword\">include</span> <span class=\"token string\">&lt;iostream></span></span>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#</span><span class=\"token directive keyword\">include</span> <span class=\"token string\">&lt;string></span></span>\n\n<span class=\"token keyword\">void</span> <span class=\"token function\">OpenClipboardWithSleep</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token function\">OpenClipboard</span><span class=\"token punctuation\">(</span><span class=\"token constant\">NULL</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        std<span class=\"token operator\">::</span>cerr <span class=\"token operator\">&lt;&lt;</span> <span class=\"token string\">\"Failed to open clipboard.\"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token comment\">// Sleep for demonstration purposes (not required in production)</span>\n    <span class=\"token function\">Sleep</span><span class=\"token punctuation\">(</span><span class=\"token number\">10000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">CloseClipboard</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">int</span> <span class=\"token function\">wmain</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n    <span class=\"token function\">OpenClipboardWithSleep</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Sample code related to clipboard operations is collected below.</p>\n<p>Reference: <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/dataxchg/using-the-clipboard\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Using the Clipboard - Win32 apps | Microsoft Learn</a></p>\n<h3 id=\"clipboard-ownership\" style=\"position:relative;\"><a href=\"#clipboard-ownership\" aria-label=\"clipboard ownership permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Clipboard Ownership</h3>\n<p>When copying information to the clipboard, you first call the <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/winuser/nf-winuser-emptyclipboard\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">EmptyClipboard function (winuser.h)</a> to empty the data in the clipboard and release handles, and then assign ownership of that clipboard to the window that currently has the clipboard open.</p>\n<p>The owner of the clipboard can be checked with the <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/winuser/nf-winuser-getclipboardowner\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">GetClipboardOwner function (winuser.h)</a>.</p>\n<p>The clipboard also has a mechanism called delayed rendering for improving performance, and you can use it by specifying NULL for the hMem parameter when saving data to the clipboard with the <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/winuser/nf-winuser-setclipboarddata\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">SetClipboardData function (winuser.h)</a>.</p>\n<p>When delayed rendering is used, data in the requested format is copied from the clipboard owner not at copy time but when requested, such as during paste, which avoids the performance impact of unnecessary rendering.</p>\n<p>Although delayed rendering can improve performance when copying large data and similar cases, it also seems to have disadvantages such as delayed application responsiveness during paste and being unable to copy data if the application has already exited.</p>\n<p>Reference: <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/dataxchg/clipboard-operations#cut-and-copy-operations\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Clipboard Operations - Win32 apps | Microsoft Learn</a></p>\n<p>Reference: <a href=\"https://doslabo.com/blog/windows-clip-board\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Windows clipboard performance varies depending on the hardware spec | Doslabo</a></p>\n<h2 id=\"implementing-clipboard-operations\" style=\"position:relative;\"><a href=\"#implementing-clipboard-operations\" aria-label=\"implementing clipboard operations permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Implementing Clipboard Operations</h2>\n<p>To study the Windows clipboard, I created some code and checked how it behaved.</p>\n<h3 id=\"read-operations-with-the-win32-api\" style=\"position:relative;\"><a href=\"#read-operations-with-the-win32-api\" aria-label=\"read operations with the win32 api permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Read Operations with the Win32 API</h3>\n<p>Below is a HEX dump of the result of reading data from the clipboard with the <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/winuser/nf-winuser-getclipboarddata\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">GetClipboardData function (winuser.h)</a>.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/de789440ad1f7a0d59ef831c18087d13/2bef9/image-20260104091655978.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 64.58333333333334%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAYAAACpUE5eAAAACXBIWXMAAAsTAAALEwEAmpwYAAABpklEQVQ4y02Tx44DMQxDfU05JEjvvU56RQ7J//8VF08AjT0Y1sgyRVKeNJlMtNlstN1utV6vNZ1OtdvttFwuNZ/PdTwe9Xw+dT6fRS258Xis2Wymer2uSqWiarWaVyqXy+p2u+p0OhqNRhEPBoP47vV6ajabarVaarfborZUKuXFtxffgCeYwaYoCu33+8yOGHZmRCMaDofDaEiOZjRmcV6r1ZR+v1+AIel+v2d5xJfLRbfbTe/3O3Kv1yvOr9dr5LAA6dyHGCrS5/MJDw+Hg06nU4C4AQwNyjk5ajinIaz6/X74vlqtwppERyQyEGRSjGwA3JmYnXMWMcBIBdCg2JEej0egU2QgX4Y5oDB1/B8QhgzOnrKHZANZFgBcYAcAz9g5YwFODrDFYhFeMrAA/H6/uRhfYEyMFXhHTI5m7NTQjAEhGTC/DBhnyX4mXCRmGFz0sMiZNQCcw9DPCR/DQzp6KBTaJw8Hv4iR6W9igAGBJUAwJU7IwgeKzZBLjmlkhn42xNzj3QHGQFBJg5AMGMUYTSGM2L3I+82xiAFBMswajUb+Tf8AlwN09DMsuPgAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/de789440ad1f7a0d59ef831c18087d13/8ac56/image-20260104091655978.webp 240w,\n/static/de789440ad1f7a0d59ef831c18087d13/d3be9/image-20260104091655978.webp 480w,\n/static/de789440ad1f7a0d59ef831c18087d13/e46b2/image-20260104091655978.webp 960w,\n/static/de789440ad1f7a0d59ef831c18087d13/a9a89/image-20260104091655978.webp 1024w\"\n              sizes=\"(max-width: 960px) 100vw, 960px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/de789440ad1f7a0d59ef831c18087d13/8ff5a/image-20260104091655978.png 240w,\n/static/de789440ad1f7a0d59ef831c18087d13/e85cb/image-20260104091655978.png 480w,\n/static/de789440ad1f7a0d59ef831c18087d13/d9199/image-20260104091655978.png 960w,\n/static/de789440ad1f7a0d59ef831c18087d13/2bef9/image-20260104091655978.png 1024w\"\n            sizes=\"(max-width: 960px) 100vw, 960px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/de789440ad1f7a0d59ef831c18087d13/d9199/image-20260104091655978.png\"\n            alt=\"image-20260104091655978\"\n            title=\"image-20260104091655978\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/6a26e5ccadc70b903fd3eab2960c8db8/20751/image-20260104091645000.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 42.083333333333336%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAYAAAD5nd/tAAAACXBIWXMAAAsTAAALEwEAmpwYAAABH0lEQVQoz22RS4+CUAyF7xaQuFEEn4AIyEMN4IKE//+3OvmalGQms2hOb9vbnp66LMukqip5Pp/SNI1cLhd5vV5SFIWUZanxtm3VyG23WwmCQDabzb/mwjCU0+mklqap4vV6lePxqA3iOFYfo9b3/V/med7qM8g9Hg+53+/KBsPP81xZ88an6W6306b4DE2SRA6Hwxo7n8+y3+/FTdMkdV0LjVkVZM2u61YpyGPkzTcJxnGU9/stn89HZXLzPEvf98qMhGlGzNB8hpieNEV/G0RD6tyyLBqAjQX5+LchMQZyOMPb7aZ/qRuGQbdz3+9XWcGQBIVMBRlCkTEiZhKArGyMWZejOqbxCfHtMCQROIoiFR7kbT7IUWDIMXhjHOcHgdrfw6NNppYAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/6a26e5ccadc70b903fd3eab2960c8db8/8ac56/image-20260104091645000.webp 240w,\n/static/6a26e5ccadc70b903fd3eab2960c8db8/d3be9/image-20260104091645000.webp 480w,\n/static/6a26e5ccadc70b903fd3eab2960c8db8/e46b2/image-20260104091645000.webp 960w,\n/static/6a26e5ccadc70b903fd3eab2960c8db8/7f429/image-20260104091645000.webp 1037w\"\n              sizes=\"(max-width: 960px) 100vw, 960px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/6a26e5ccadc70b903fd3eab2960c8db8/8ff5a/image-20260104091645000.png 240w,\n/static/6a26e5ccadc70b903fd3eab2960c8db8/e85cb/image-20260104091645000.png 480w,\n/static/6a26e5ccadc70b903fd3eab2960c8db8/d9199/image-20260104091645000.png 960w,\n/static/6a26e5ccadc70b903fd3eab2960c8db8/20751/image-20260104091645000.png 1037w\"\n            sizes=\"(max-width: 960px) 100vw, 960px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/6a26e5ccadc70b903fd3eab2960c8db8/d9199/image-20260104091645000.png\"\n            alt=\"image-20260104091645000\"\n            title=\"image-20260104091645000\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>Below is the implementation of the function that reads data with the GetClipboardData function.</p>\n<div class=\"gatsby-highlight\" data-language=\"c\"><pre class=\"language-c\"><code class=\"language-c\"><span class=\"token keyword\">void</span> <span class=\"token function\">ReadAndDumpClipboard</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token function\">OpenClipboard</span><span class=\"token punctuation\">(</span><span class=\"token constant\">NULL</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        std<span class=\"token operator\">::</span>cerr <span class=\"token operator\">&lt;&lt;</span> <span class=\"token string\">\"Failed to open clipboard.\"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    std<span class=\"token operator\">::</span>cout <span class=\"token operator\">&lt;&lt;</span> <span class=\"token string\">\"=== Clipboard Content Dump ===\"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl<span class=\"token punctuation\">;</span>\n\n    UINT format <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">int</span> count <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Enumerate all clipboard formats</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>format <span class=\"token operator\">=</span> <span class=\"token function\">EnumClipboardFormats</span><span class=\"token punctuation\">(</span>format<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">!=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        count<span class=\"token operator\">++</span><span class=\"token punctuation\">;</span>\n        std<span class=\"token operator\">::</span>wstring formatName <span class=\"token operator\">=</span> <span class=\"token function\">GetFormatNameString</span><span class=\"token punctuation\">(</span>format<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n        std<span class=\"token operator\">::</span>wcout <span class=\"token operator\">&lt;&lt;</span> L<span class=\"token string\">\"[\"</span> <span class=\"token operator\">&lt;&lt;</span> count <span class=\"token operator\">&lt;&lt;</span> L<span class=\"token string\">\"] Format ID: \"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>dec <span class=\"token operator\">&lt;&lt;</span> format\n            <span class=\"token operator\">&lt;&lt;</span> L<span class=\"token string\">\" | Name: \"</span> <span class=\"token operator\">&lt;&lt;</span> formatName <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl<span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Get clipboard data handle</span>\n        HANDLE hData <span class=\"token operator\">=</span> <span class=\"token function\">GetClipboardData</span><span class=\"token punctuation\">(</span>format<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>hData <span class=\"token operator\">==</span> <span class=\"token constant\">NULL</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            std<span class=\"token operator\">::</span>cout <span class=\"token operator\">&lt;&lt;</span> <span class=\"token string\">\"    [Error] GetClipboardData returned NULL.\"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">continue</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// If we can lock the data, we assume it's a memory block</span>\n        <span class=\"token keyword\">void</span><span class=\"token operator\">*</span> pData <span class=\"token operator\">=</span> <span class=\"token function\">GlobalLock</span><span class=\"token punctuation\">(</span>hData<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pData<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token class-name\">size_t</span> size <span class=\"token operator\">=</span> <span class=\"token function\">GlobalSize</span><span class=\"token punctuation\">(</span>hData<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            std<span class=\"token operator\">::</span>cout <span class=\"token operator\">&lt;&lt;</span> <span class=\"token string\">\"    Type: Memory Block | Size: \"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>dec <span class=\"token operator\">&lt;&lt;</span> size <span class=\"token operator\">&lt;&lt;</span> <span class=\"token string\">\" bytes\"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl<span class=\"token punctuation\">;</span>\n\n            <span class=\"token function\">PrintHexDump</span><span class=\"token punctuation\">(</span>pData<span class=\"token punctuation\">,</span> size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n            <span class=\"token function\">GlobalUnlock</span><span class=\"token punctuation\">(</span>hData<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n<span class=\"token comment\">// Fallback for non-lockable formats</span>\n            std<span class=\"token operator\">::</span>cout <span class=\"token operator\">&lt;&lt;</span> <span class=\"token string\">\"    Type: GDI Handle or Non-Lockable Object (Cannot dump raw bytes safely)\"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>count <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        std<span class=\"token operator\">::</span>cout <span class=\"token operator\">&lt;&lt;</span> <span class=\"token string\">\"Clipboard is empty.\"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">CloseClipboard</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The GetClipboardData function returns a handle to the clipboard object corresponding to the clipboard format value received as an argument.</p>\n<div class=\"gatsby-highlight\" data-language=\"c\"><pre class=\"language-c\"><code class=\"language-c\">HANDLE <span class=\"token function\">GetClipboardData</span><span class=\"token punctuation\">(</span>\n  <span class=\"token punctuation\">[</span>in<span class=\"token punctuation\">]</span> UINT uFormat\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The list of clipboard formats currently available in the clipboard can be obtained on each call to the <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/winuser/nf-winuser-enumclipboardformats\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">EnumClipboardFormats function (winuser.h)</a>, so the following loop checks the clipboard data in sequence. (If there is no more available clipboard data, the function returns 0.)</p>\n<div class=\"gatsby-highlight\" data-language=\"c\"><pre class=\"language-c\"><code class=\"language-c\"><span class=\"token comment\">// Enumerate all clipboard formats</span>\n<span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>format <span class=\"token operator\">=</span> <span class=\"token function\">EnumClipboardFormats</span><span class=\"token punctuation\">(</span>format<span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">!=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span> <span class=\"token punctuation\">}</span></code></pre></div>\n<p>The data inside the handle of the acquired clipboard object is read after locking the memory block with the <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/winbase/nf-winbase-globallock\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">GlobalLock function (winbase.h)</a>, as in the sample code in <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/dataxchg/using-the-clipboard#paste-information-from-the-clipboard\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Paste Information from the Clipboard</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"c\"><pre class=\"language-c\"><code class=\"language-c\"><span class=\"token comment\">// If we can lock the data, we assume it's a memory block</span>\n<span class=\"token keyword\">void</span><span class=\"token operator\">*</span> pData <span class=\"token operator\">=</span> <span class=\"token function\">GlobalLock</span><span class=\"token punctuation\">(</span>hData<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pData<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token class-name\">size_t</span> size <span class=\"token operator\">=</span> <span class=\"token function\">GlobalSize</span><span class=\"token punctuation\">(</span>hData<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    std<span class=\"token operator\">::</span>cout <span class=\"token operator\">&lt;&lt;</span> <span class=\"token string\">\"    Type: Memory Block | Size: \"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>dec <span class=\"token operator\">&lt;&lt;</span> size <span class=\"token operator\">&lt;&lt;</span> <span class=\"token string\">\" bytes\"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl<span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">PrintHexDump</span><span class=\"token punctuation\">(</span>pData<span class=\"token punctuation\">,</span> size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">GlobalUnlock</span><span class=\"token punctuation\">(</span>hData<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>When saving clipboard data with the <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/winuser/nf-winuser-setclipboarddata\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">SetClipboardData function (winuser.h)</a>, the destination global memory must have been allocated as movable memory by using the <code class=\"language-text\">GMEM_MOVEABLE</code> flag, so the GlobalLock function is required to access that memory region.</p>\n<blockquote>\n<p>If the hMem parameter identifies a memory object, the object must have been allocated by using a function with the GMEM_MOVEABLE flag.</p>\n</blockquote>\n<p>Reference: <a href=\"https://stackoverflow.com/questions/27151468/windows-api-clipboard-globallock-use-or-not-to-use\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">c++ - Windows API - Clipboard - GlobalLock - use or not to use? - Stack Overflow</a></p>\n<p>Reference: <a href=\"https://wisdom.sakura.ne.jp/system/winapi/win32/win90.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Clipboard</a></p>\n<h3 id=\"write-operations-with-the-win32-api\" style=\"position:relative;\"><a href=\"#write-operations-with-the-win32-api\" aria-label=\"write operations with the win32 api permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Write Operations with the Win32 API</h3>\n<p>Writing information to the clipboard (copying) can also be achieved by implementing processing similar to the sample code below.</p>\n<p>Reference: <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/dataxchg/using-the-clipboard#copy-information-to-the-clipboard\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Copy Information to the Clipboard</a></p>\n<div class=\"gatsby-highlight\" data-language=\"c\"><pre class=\"language-c\"><code class=\"language-c\"><span class=\"token comment\">// Using Win32 API to write and read clipboard text</span>\nbool <span class=\"token function\">WriteTextToClipboard</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> std<span class=\"token operator\">::</span>wstring<span class=\"token operator\">&amp;</span> text<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    \n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token function\">OpenClipboard</span><span class=\"token punctuation\">(</span><span class=\"token constant\">NULL</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        std<span class=\"token operator\">::</span>cerr <span class=\"token operator\">&lt;&lt;</span> <span class=\"token string\">\"Failed to open clipboard.\"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl<span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> false<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span><span class=\"token function\">EmptyClipboard</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        std<span class=\"token operator\">::</span>cerr <span class=\"token operator\">&lt;&lt;</span> <span class=\"token string\">\"Failed to empty clipboard.\"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl<span class=\"token punctuation\">;</span>\n        <span class=\"token function\">CloseClipboard</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> false<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Calculate size in bytes (including null terminator)</span>\n    <span class=\"token class-name\">size_t</span> size <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>text<span class=\"token punctuation\">.</span><span class=\"token function\">length</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">sizeof</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">wchar_t</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Need to allocate global memory for clipboard data(GMEM_MOVEABLE)</span>\n    HGLOBAL hGlob <span class=\"token operator\">=</span> <span class=\"token function\">GlobalAlloc</span><span class=\"token punctuation\">(</span>GMEM_MOVEABLE<span class=\"token punctuation\">,</span> size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token operator\">!</span>hGlob<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token function\">CloseClipboard</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token keyword\">return</span> false<span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n\n<span class=\"token comment\">// Lock the memory and copy the text</span>\n    <span class=\"token keyword\">void</span><span class=\"token operator\">*</span> pMem <span class=\"token operator\">=</span> <span class=\"token function\">GlobalLock</span><span class=\"token punctuation\">(</span>hGlob<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>pMem<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n\n        <span class=\"token function\">memcpy</span><span class=\"token punctuation\">(</span>pMem<span class=\"token punctuation\">,</span> text<span class=\"token punctuation\">.</span><span class=\"token function\">c_str</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token function\">GlobalUnlock</span><span class=\"token punctuation\">(</span>hGlob<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// Set the clipboard data as CF_UNICODETEXT</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token function\">SetClipboardData</span><span class=\"token punctuation\">(</span>CF_UNICODETEXT<span class=\"token punctuation\">,</span> hGlob<span class=\"token punctuation\">)</span> <span class=\"token operator\">==</span> <span class=\"token constant\">NULL</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token function\">GlobalFree</span><span class=\"token punctuation\">(</span>hGlob<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            std<span class=\"token operator\">::</span>cerr <span class=\"token operator\">&lt;&lt;</span> <span class=\"token string\">\"Failed to set clipboard data.\"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n        <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            std<span class=\"token operator\">::</span>cout <span class=\"token operator\">&lt;&lt;</span> <span class=\"token string\">\"[Write] Successfully copied text to clipboard.\"</span> <span class=\"token operator\">&lt;&lt;</span> std<span class=\"token operator\">::</span>endl<span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n\n    <span class=\"token function\">CloseClipboard</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">return</span> true<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>In the above code, the clipboard is first opened and assigned to the current task with the OpenClipboard function called with NULL as its argument, then the clipboard is emptied with the <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/winuser/nf-winuser-emptyclipboard\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">EmptyClipboard function (winuser.h)</a>, after which ownership of the clipboard is assigned to the current window.</p>\n<p>In addition, as mentioned above, movable memory is allocated by the <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/winbase/nf-winbase-globalalloc\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">GlobalAlloc function (winbase.h)</a> using the <code class=\"language-text\">GMEM_MOVEABLE</code> flag, and the data to be stored in the clipboard is written with GlobalLock -> memcpy -> GlobalUnlock.</p>\n<p>Finally, the handle into which the data to be stored was written is placed on the clipboard in <code class=\"language-text\">CF_UNICODETEXT</code> format with the <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/winuser/nf-winuser-setclipboarddata\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">SetClipboardData function (winuser.h)</a>.</p>\n<p>This confirms that, as shown below, the text saved to the clipboard in <code class=\"language-text\">CF_UNICODETEXT</code> format has been written as a wide string.</p>\n<p>Windows also automatically stores certain clipboard formats as corresponding data in other formats.</p>\n<p>Reference: <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/dataxchg/clipboard-formats#synthesized-clipboard-formats\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Clipboard Formats - Win32 apps | Microsoft Learn</a></p>\n<p>Therefore, even if data is explicitly saved only to the clipboard in <code class=\"language-text\">CF_UNICODETEXT</code> format by <code class=\"language-text\">SetClipboardData(CF_UNICODETEXT, hGlob)</code>, it appears that the text is also automatically converted to a single-byte string and stored in <code class=\"language-text\">CF_TEXT</code> and <code class=\"language-text\">CF_OEMTEXT</code>, which are implicit type-conversion targets of <code class=\"language-text\">CF_UNICODETEXT</code>.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/ae39cc8e3e9d83385496ea53e4e47692/709cb/image-20260104180352020.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 92.08333333333334%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAACXBIWXMAAAsTAAALEwEAmpwYAAACBklEQVQ4y32UR64DIAxEvU3vvffelSgXyP2P5OhZmgjlR39hGQzYw3jAptOpb7dbv16v4Verle/3+7DlcumbzSbG7Ot2uz4ajbzX63m/3/dCoeC5XM7z+fzHLJvNxsZ2u+2DwSDGnU7Hm81mjFutVsTxHCaJDnOWmDxmVMZABqLFYuHD4dDX67XPZrNI1mg0ogBJU1+v171SqYSVy2UvlUpur9fLd7tdXPnxeIS/3W5+v9/9fD5H7HK5RIw1YvjD4eCTySSKAwIA3MhYAAUoWcCPx+NAzBx0IKjVal6tVj8GOmgCqVAWi0U34MOZFknAGGMM+YzZDFf/WXBIJVDB13w+jy6CDJQYMeag+u7oLzNQwAN8cBivziIPiMZAqEPqtjqeFjK44iAJQAlCNoKIRJIHlslkPvJQoT8JSUYSrgdfoIMCUBMXFazDdYrqFwVGFQ5j0p0OE6MgBYijNQk5bUQ6D4QkIJkkQwyRwyeJU7kgH0kITxHJiLkhXK6EMDESYYidAowpxpumGNKS6R84nU5xGxpsIJDBH0Hpkjkb8VCjxqRXFJ/EMeMgOgMJHQcFSGkIyPUDgUhNSBuSNiaETddAxDuEOzyH6ThzOJJJe2hS3RZqxvH0ns9n8HM8HuPBgwiEfAggY03vXE3SFwe3+j+1ZiDRl4TpHX/ziRePuiYfgvbrrb8BD+TO6/LFw84AAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/ae39cc8e3e9d83385496ea53e4e47692/8ac56/image-20260104180352020.webp 240w,\n/static/ae39cc8e3e9d83385496ea53e4e47692/d3be9/image-20260104180352020.webp 480w,\n/static/ae39cc8e3e9d83385496ea53e4e47692/e46b2/image-20260104180352020.webp 960w,\n/static/ae39cc8e3e9d83385496ea53e4e47692/43c62/image-20260104180352020.webp 1034w\"\n              sizes=\"(max-width: 960px) 100vw, 960px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/ae39cc8e3e9d83385496ea53e4e47692/8ff5a/image-20260104180352020.png 240w,\n/static/ae39cc8e3e9d83385496ea53e4e47692/e85cb/image-20260104180352020.png 480w,\n/static/ae39cc8e3e9d83385496ea53e4e47692/d9199/image-20260104180352020.png 960w,\n/static/ae39cc8e3e9d83385496ea53e4e47692/709cb/image-20260104180352020.png 1034w\"\n            sizes=\"(max-width: 960px) 100vw, 960px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/ae39cc8e3e9d83385496ea53e4e47692/d9199/image-20260104180352020.png\"\n            alt=\"image-20260104180352020\"\n            title=\"image-20260104180352020\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<h3 id=\"the-ole-clipboard\" style=\"position:relative;\"><a href=\"#the-ole-clipboard\" aria-label=\"the ole clipboard permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The OLE Clipboard</h3>\n<p>On Windows, in addition to the method confirmed so far that uses the Win32 API directly, implementation can also be done by using the OLE/COM model.</p>\n<p>When using the COM-based OLE clipboard, data is exchanged by using the <a href=\"https://learn.microsoft.com/ja-jp/dotnet/api/system.windows.forms.idataobject?view=windowsdesktop-8.0\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">IDataObject interface (System.Windows.Forms)</a> object obtained with the <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/ole2/nf-ole2-olegetclipboard\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">OleGetClipboard function (ole2.h)</a> as the interface.</p>\n<p>When reading clipboard data in various formats from the IDataObject interface used to receive clipboard data obtained by the OleGetClipboard function, call <a href=\"https://learn.microsoft.com/ja-jp/dotnet/api/system.windows.idataobject.getdata?view=windowsdesktop-8.0\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">IDataObject.GetData method (System.Windows)</a> with the format supported by the enumerated data object by using <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/objidl/nf-objidl-idataobject-enumformatetc\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">IDataObject::EnumFormatEtc (objidl.h)</a> with <code class=\"language-text\">DATADIR_GET</code> passed as the parameter.</p>\n<p>The <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/objidl/ns-objidl-formatetc\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">FORMATETC (objidl.h)</a> obtained by the EnumFormatEtc method abstracts generalized clipboard formats.</p>\n<p>The OLE clipboard also seems to be extended so that storage media other than global memory can be used for data transfer, and the TYMED enumeration in the FORMATETC structure appears to indicate the type of medium.</p>\n<p>For example, if this value indicates <code class=\"language-text\">TYMED_HGLOBAL</code>, it means that a global memory handle is being used as the storage medium.</p>\n<p>Reference: <a href=\"https://learn.microsoft.com/ja-jp/cpp/mfc/clipboard-using-the-ole-clipboard-mechanism?view=msvc-170\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Clipboard: Using the OLE Clipboard Mechanism | Microsoft Learn</a></p>\n<p>Reference: <a href=\"https://www.sinis.ro/static/ch19c.htm\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">The OLE Clipboard</a></p>\n<h2 id=\"summary\" style=\"position:relative;\"><a href=\"#summary\" aria-label=\"summary permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Summary</h2>\n<p>I wrote down some notes about the Windows clipboard.</p>","fields":{"slug":"/windows-clipboard-en","tagSlugs":["/tag/windows/","/tag/english/"]},"frontmatter":{"date":"2026-01-05","description":"Notes on Windows clipboard implementation.","tags":["Windows","English"],"title":"Notes on Windows Clipboard Implementation","socialImage":{"publicURL":"/static/43145cd70b197963749bf8f9d96f17b3/windows-clipboard.png"}}}},"pageContext":{"slug":"/windows-clipboard-en"}},"staticQueryHashes":["251939775","401334301","825871152"]}