Windows API one-day training (76) globalalloc Function

Source: Internet
Author: User

In Windows, a function is very useful, that is, the clipboard function. Program To exchange data with another program, that is, the two processes can share data. To implement this function, the Windows system has corresponding support at the underlying layer, that is, the memory of the high-end address is the system memory, so that different processes can share data. Therefore, the globalalloc function is called to allocate system memory so that different processes can share data, that is, the clipboard function, and the memory can be allocated within a process, access Data in another process and delete the memory.

The globalalloc function declaration is as follows:

Hglobal
Winapi
Globalalloc (
_ In uint uflags,
_ In size_t dwbytes
);

Uflags is the memory identifier.
Dwbytes is the size of the allocated memory.

An example of calling a function is as follows:
#001 //
#002 // global memory allocation.
#003 // Cai junsheng 2007/11/19 QQ: 9073204 Shenzhen
#004 void memglobal (void)
#005 {
#006 // allocate global memory.
#007 byte * pglobal = (byte *): globalalloc (gmem_fixed, 1024 );
#008
#009 if (! Pglobal)
#010 {
#011 return;
#012}
#013 else
#014 {
#015 // test the global memory.
#016 zeroemory (pglobal, 1024 );
#017 memcpy (pglobal, _ T ("memory allocated successfully \ r \ n "),
#018 sizeof (_ T ("memory allocated successfully \ r \ n ")));
#019 outputdebugstring (lpwstr) pglobal );
#020}
#021
#022 // release the global memory.
#023: globalfree (hglobal) pglobal );
#024}

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/caimouse/archive/2007/11/19/1893461.aspx

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.