How the process communicates between processes in Windows

Source: Internet
Author: User
Tags int size

An indirect way, you can use a "share name" to request a block of shared memory for reading and writing:

HANDLE GetShare(char * &ShareP,int size,char *ShareName)
{
//ShareP申请的内存块地址,size字节数,ShareName共享名
HANDLE fh=CreateFileMapping((HANDLE)-1,0,PAGE_READWRITE,0,Size,ShareName);
ShareP=(char *)MapViewOfFile(fh,FILE_MAP_ALL_ACCESS,0,0,0);
if(GetLastError()!=ERROR_ALREADY_EXISTS)
  ZeroMemory(ShareP,size); // 共享区初始化
return(fh);
}
char * ShareP=NULL;
void test() // 申请一块128个字节的字符数组
  {
  HANDLE fh=GetShare(ShareP,128,"ShareForMyProg");
  for (int i=0;i<128;i++)
   ShareP[i]=i;
  CloseHandle(fh);
  }

If you have multiple programs or the same program running multiple times, you can also use this method to enter the variable communication; Several of your processes can use this approach to communicate data to each other.

Related Article

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.