进程之间采用剪贴板来传输对象 { UpdateData(TRUE); if (OpenClipboard()) { int size = m_Text.GetLength() * sizeof(TCHAR); HANDLE hMem = GlobalAlloc(GMEM_MOVEABLE, size+1 * sizeof(TCHAR)); TCHAR* buffer = (TCHAR*) GlobalLock(hMem); memcpy(buffer, (LPCTSTR)m_Text, size); GlobalUnlock(hMem); EmptyClipboard(); #ifdef UNICODE SetClipboardData(CF_UNICODETEXT, hMem); #else SetClipboardData(CF_TEXT, hMem); #endif CloseClipboard(); } } { if (OpenClipboard()) { if (IsClipboardFormatAvailable(CF_TEXT)) { HANDLE hMem = GetClipboardData(CF_TEXT); char* buffer = (char*)GlobalLock(hMem); GlobalUnlock(hMem); m_Text = buffer; } if (IsClipboardFormatAvailable(CF_UNICODETEXT)) { HANDLE hMem = GetClipboardData(CF_UNICODETEXT); wchar_t* buffer = (wchar_t*)GlobalLock(hMem); GlobalUnlock(hMem); m_Text = buffer; } CloseClipboard(); UpdateData(FALSE); } } 各个进程之间的内存不可共享,使用GlobalAlloc()分配的内存是系统级的,每个进程都可以访问到