| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1408 人关注过本帖, 1 人收藏
标题:请教多个进程如何读写共享内存?
取消只看楼主 加入收藏
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:317
专家分:448
注 册:2019-10-11
结帖率:100%
收藏(1)
已结贴  问题点数:20 回复次数:1 
请教多个进程如何读写共享内存?
DECLARE INTEGER GetLastError IN win32api
Declare Long OpenFileMapping In WIN32API Long, Long, String
Declare Long CreateFileMapping In WIN32API Long, Long, Long, Long, Long, String
DECLARE INTEGER CloseHandle IN kernel32.DLL INTEGER hObject

DECLARE integer GetProcessHeap IN WIN32API
DECLARE integer HeapAlloc IN WIN32API Long,Long,Long
DECLARE integer HeapFree IN WIN32API integer,integer,integer

Declare long MapViewOfFile IN WIN32API long hFileMappingObject,Long dwDesiredAccess, Long dwFileOffsetHigh, Long dwFileOffsetLow, Long dwNumberOfBytesToMap
Declare Long UnmapViewOfFile in win32api long lpBaseAddress
**申明可能有错
Declare Long WriteProcessMemory in win32api long @hProcess, Long lpBaseAddress ,long  @lpBuffer ,long  nSize , Long @lpNumberOfBytesWritten
Declare long ReadProcessMemory in WIN32API long hProcess , Long lpBaseAddress ,long lpBuffer,long nSize ,Long @lpNumberOfBytesWritten

cPID = "争王"
hmap = OpenFileMapping(983071, 0, cPID)  &&读
If 0 == hmap  &&没有创建
    hmap = CreateFileMapping(-1, 0,4, 0, 40, cPID)  &&读写
    pmap=MapViewOfFile(hMap, 0xF0000+1+2+4+8+0x10, 0, 0, 4)
    hProcHeap=GetProcessHeap()
    lhMemPtr=HeapAlloc(hProcHeap,0,4)
    SYS(2600,lhMemPtr,4,"1234")
    lpnum=0
SYS(2600,pmap,0,,"123")  &&也出错
**写内存,出错,句柄无效
*    ?hmap
*    ?WriteProcessMemory(@pmap,0,@lhMemPtr,4,@lpnum)
*    ?lpnum
    ?GetLastError()
    HeapFree(hProcHeap,0,lhMemPtr)
    UnmapViewOfFile(pmap)
ELSE
**读内存
    pmap=MapViewOfFile(hMap, 983071, 0, 0, 0)
    ?SYS(2600,pmap,4)
    UnmapViewOfFile(pmap)
    =CloseHandle(hmap)
Endif
retu
搜索更多相关主题的帖子: Long 读写 内存 INTEGER 共享 
2022-06-08 16:40
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:317
专家分:448
注 册:2019-10-11
收藏
得分:0 
谢谢!
Declare Long OpenFileMapping In WIN32API Long, Long, String
Declare Long CreateFileMapping In WIN32API Long, Long, Long, Long, Long, String
Declare long MapViewOfFile IN WIN32API long hFileMappingObject,Long dwDesiredAccess, Long dwFileOffsetHigh, Long dwFileOffsetLow, Long dwNumberOfBytesToMap
Declare Long UnmapViewOfFile in win32api long lpBaseAddress
DECLARE INTEGER CloseHandle IN kernel32.DLL INTEGER hObject

cPID = "争王"
hmap = OpenFileMapping(4, 0, cPID)
If 0 = hmap
    hmap = CreateFileMapping(-1, 0,4, 0, 40, cPID)
    pmap=MapViewOfFile(hMap, 2, 0, 0, 0)
    cWrite="1234567测试"
    SYS(2600,pmap,LEN(cWrite),cWrite)
    UnmapViewOfFile(pmap)
ELSE
    pmap=MapViewOfFile(hMap, 4, 0, 0, 0)
    cWrite=SYS(2600,pmap,40)
?cWrite
    UnmapViewOfFile(pmap)
    =CloseHandle(hmap)
Endif
retu
2022-06-09 08:19
快速回复:请教多个进程如何读写共享内存?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012830 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved