TCHAR szName[MAX_PATH] = _T("2010ShareMem"); //首先试图打开一个命名的内存映射文件对象 m_hMap = ::OpenFileMapping(FILE_MAP_ALL_ACCESS, 0, szName); if (m_hMap == NULL) { m_hMap = ::CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, MAX_PATH * sizeof(TCHAR), szName); } 写入: TCHAR szName[MAX_PATH] = _T("2010ShareMem"); LPVOID pBuffer; //首先试图打开一个命名的内存映射文件对象 HANDLE hMap = ::OpenFileMapping(FILE_MAP_ALL_ACCESS, 0, szName); if (hMap != NULL) { pBuffer = ::MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0); GetDlgItem(IDC_EDIT1)->GetWindowText((TCHAR*)pBuffer, MAX_PATH); ::UnmapViewOfFile(pBuffer); ::CloseHandle(hMap); } 读取: TCHAR szName[MAX_PATH] = _T("2010ShareMem"); LPVOID pBuffer; //首先试图打开一个命名的内存映射文件对象 HANDLE hMap = ::OpenFileMapping(FILE_MAP_ALL_ACCESS, 0, szName); if (hMap != NULL) { pBuffer = ::MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0); GetDlgItem(IDC_EDIT2)->SetWindowText((TCHAR*)pBuffer); ::UnmapViewOfFile(pBuffer); ::CloseHandle(hMap); }