4

I am interested in learning windows system internals and how things work. I am inclined towards learning system programming on windows. With that context, I am curious to know few things on how windows clipboard internally functions:

  • What precisely happens when we select some text, image etc and press Ctrl + C ?
  • What precisely happens when we we press Ctrl + V in different application?
  • Where exactly the copied data resides? Does the copied data go into kernel mode memory - that is shared across all processes?
  • How the copied data becomes available to a different process?

I want to know the answer to the above questions from the system programmer's perspective.

Also, share any resources that discuss about windows clipboard internals.

Anand Patel
  • 6,031
  • 11
  • 48
  • 67
  • 3
    Start here with Microsoft's description: http://msdn.microsoft.com/en-us/library/windows/desktop/ms648709.aspx – Mark Ransom Nov 17 '11 at 17:09
  • @MarkRansom, unfortunately doc says nothing about memory managment of copyied memory. Simple example - where is object (allocated via GlobalAlloc) stored after closing source application – Alex Aparin Apr 27 '17 at 09:07

1 Answers1

2

I have some good resources on my site: http://www.clipboardextender.com It talks about clipboard viewer implementation, typical mistakes, do's and dont's.

Basically the clipboard is a shared memory area that you copy data into (aka. "copy", such as in response to the user pressing Ctrl+C) and copy data from (aka "paste"). The data can be simultaneously represented in dozens of common formats, and any number of programmer-defined formats.

It is impossible to completely "backup" the clipboard and restore it like it was, without impacting other programs, and causing a negative user experience. Look into "delayed rendering" to see why, and consider what would happen when an Excel user copies 5000 rows x 255 columns in a spreadsheet, and presses Ctrl+V. Understand that, and you'll understand the magic (and pitfalls) of delayed rendering.

Chris Thornton
  • 15,620
  • 5
  • 37
  • 62
  • So "shared memory" is a fixed block in virtual memory, right? So it has a predetermined size? – flow2k May 18 '18 at 20:00
  • flow2k - the size is determined by the program that copies the data to the clipboard. It allocates a block large enough to hold the data. So the size can vary greatly. – Chris Thornton May 23 '18 at 19:30