兩個進程這間共享記憶體,並且發消息的例程有沒有,最好給我一份

jian_a0672 2004-08-11 02:46:03
兩個進程這間共享記憶體,並且發消息的例程有沒有,最好給我一份
...全文
31 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
jian_a0672 2004-08-11
謝謝你,各我怎麽好的回複.

但是我在編譯的時候還是出錯了,不知道是怎麽一回事
回复
huahao0672 2004-08-11


以下的代碼我是測試過的,請你在重新的編譯一次

BOOL CProcess1Dlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
{
PCOPYDATASTRUCT pcds = (PCOPYDATASTRUCT) pCopyDataStruct;
LPCSTR sz;
ULONG leftSize;
__int64 startPos;
ULONG reqSize;
ULONG FileIndex;
//_tstring pFileName;
switch(pcds->dwData)
{
case ACTION_TEXT:
sz=(LPCSTR)(pcds->lpData);
s_Edit=sz;
s_Edit.TrimRight();
s_Edit += "\r\n";
int nEditLen;
nEditLen=pEdit->GetWindowTextLength();
pEdit->ReplaceSel(s_Edit);
pEdit->ShowCaret();
break;
case END_DLG:
EndDialog(1);
break;
}
return CDialog::OnCopyData(pWnd, pCopyDataStruct);

}



hFileMapping=::CreateFileMapping((HANDLE)0xFFFFFFFF,NULL,PAGE_READWRITE,0,1<<16,"MyFileMapping");
if (hFileMapping!= NULL && GetLastError() == ERROR_ALREADY_EXISTS)
{
CloseHandle(hFileMapping);
hFileMapping = INVALID_HANDLE_VALUE;
}

lpMapAddress = (MappingBuf *)MapViewOfFile(hFileMapping,FILE_MAP_ALL_ACCESS,
0,
0,
0);



HANDLE CreateFileMapping(
HANDLE hFile, // handle to file
LPSECURITY_ATTRIBUTES lpAttributes, // security
DWORD flProtect, // protection
DWORD dwMaximumSizeHigh, // high-order DWORD of size
DWORD dwMaximumSizeLow, // low-order DWORD of size
LPCTSTR lpName // object name
);


LPVOID MapViewOfFile(
HANDLE hFileMappingObject, // handle to file-mapping object
DWORD dwDesiredAccess, // access mode
DWORD dwFileOffsetHigh, // high-order DWORD of offset
DWORD dwFileOffsetLow, // low-order DWORD of offset
SIZE_T dwNumberOfBytesToMap // number of bytes to map
);
Mapping a file makes the specified portion of the file visible in the address space of the calling process.

Multiple views of a file (or a file-mapping object and its mapped file) are said to be "coherent" if they contain identical data at a specified time. This occurs if the file views are derived from the same file-mapping object. A process can duplicate a file-mapping object handle into another process by using the DuplicateHandle function, or another process can open a file-mapping object by name by using the OpenFileMapping function.


回复
相关推荐
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2004-08-11 02:46
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……