Common clipboard functions for Process Communication in VC ++

Source: Internet
Author: User

Common clipboard functions for Process Communication in VC ++

I have Excerpted from the book 21-day student VC ++.

 

In the operating system, communication between different processes on the same machine is very important. Generally, there are three communication methods between processes: clipboard, mail slot, and pipeline. Since the last two methods require a certain operating system foundation, we will not introduce them here. This section describes in detail the implementation of Process Communication Using the clipboard.
Common clipboard Functions
You should be familiar with the clipboard. When you press Ctrl + C, the selected content will be copied to the clipboard, and then press Ctrl + v, you can copy the content on the clipboard to the application.

Note: to copy the content of a process to another process, the simplest way is to use the clipboard.
In the reader's impression, the clipboard is usually considered as a media for data transmission. The data to be copied is saved to the clipboard first. This idea is not correct. Because the data to be copied is not really saved on the clipboard, but in a memory area. The clipboard is associated with the memory area. Or, the clipboard is used to manage the memory area. For example, to copy the content of process a to process B through the clipboard, follow the steps below.
Apply for a memory block in the 4 GB address space of process.
Write the data to be copied to the applied memory block, and then send the memory block to the clipboard manager.
Process B retrieves data from the clipboard.
The following are some functions related to clipboard operations.
Openclipboard function: This function is used to open the clipboard to check or prevent other applications from modifying the content in the clipboard. If the clipboard has been opened in another window before the current process calls this function to open the clipboard, the function call will fail. In this case, you should call the closeclipboard function to close the clipboard and then call openclipboard to open it.
Globalalloc: This function is used to allocate a memory area of the specified size on the stack.
Globallock: This function is used to lock a memory block and return a pointer variable pointing to the first byte in the memory block. The reference counter is incremented by 1.
Globalunlock: This function is used to unlock the locked memory block. The reference counter number is reduced by 1.
Setclipboarddata function: This function is used to put the memory block in the clipboard manager in the format of the specified clipboard content.
Getclipboarddata function: This function is used to retrieve memory blocks from the clipboard in the format of the specified clipboard content.
Closeclipboard function: This function is used to close the clipboard and release clipboard resources.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.