Is there a maximum size for Windows clipboard data? Because I’m getting null for something I know should be there

Raymond Chen

A customer had a program that opened a very large spreadsheet in Excel. Very large, like over 300,000 rows. They then selected all of the rows in the very large spreadsheet, copied those rows to the clipboard, and then ran a program that tried to extract the data. The program used the Get­Clipboard­Data function to retrieve the data in Rich Text Format. What they found was that the call to Get­Clipboard­Data was returning NULL. Is there a maximum size for clipboard data?

No, there is no pre-set maximum size for clipboard data. You are limited only by available memory and address space.

However, that’s not the reason why the call to Get­Clipboard­Data is failing.

There are two ways to make clipboard data available. One is to put the data directly on the clipboard at the time you take ownership of it. Another option is to declare that you have data of a particular type, but instead of putting the data on the clipboard, you say, “If anybody asks, let me know, and I’ll produce the data.” This is known as clipboard delay-rendering, and it is a common optimization for data formats that are rarely used or expensive to produce. If somebody asks for the format, the clipboard owner gets a WM_RENDER­FORMAT message to say, “Somebody wants that data, can you produce it now?”

Excel does not operate natively in Rich Text Format. The Rich Text Format data that it places on the clipboard is delay-rendered. And then when another program asks for the Rich Text Format data, Excel says, “Oh yeah, just hang on a second, let me go get that for you.” Mind you, Rich Text Format is not the best format for a data table. As its name suggests, Rich Text Format is designed for text. It can represent basic tables, but that’s not its bread and butter.

When the system asks a clipboard owner to render clipboard data, it sends the WM_RENDER­FORMAT message and waits up to 30 seconds for it to return. If the clipboard owner fails to produce the data within 30 seconds, then system abandons the request, and Get­Clipboard­Data returns NULL.

What’s happening is that this table is so large that it’s taking Excel longer than 30 seconds to produce the Rich Text Format table. The Get­Clipboard­Data function times out and returns NULL.

Next time, we’ll see what we can do to extend this timeout.