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