delphi 进程间传递数据
2021/5/18 7:28:33
本文主要是介绍delphi 进程间传递数据,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1.共享内存
//创建共享内存 hMapFile := CreateFileMapping( INVALID_HANDLE_VALUE, // use paging file nil, // default security PAGE_READWRITE, // read/write access 0, // maximum object size (high-order DWORD) 256, // maximum object size (low-order DWORD) PChar(globalCloseName)); // name of mapping object if hMapFile <> 0 then begin pshare := MapViewOfFile(hMapFile, // handle to map object FILE_MAP_ALL_ACCESS, // read/write permission 0, 0, 256); if PShare = nil then begin closehandle(hMapFile); hMapFile := 0; end; end;
//释放共享内存 CloseHandle(hMapFile); UnmapViewOfFile(pshare);
//引用共享内存 hMapFile := OpenFileMapping( FILE_MAP_ALL_ACCESS, // read/write access FALSE, // do not inherit the name PChar(globalCloseName)); // name of mapping object if hMapFile <> 0 then begin PShare := MapViewOfFile(hMapFile, // handle to map object FILE_MAP_ALL_ACCESS, // read/write permission 0, 0, 255); if PShare = nil then begin CloseHandle(hMapFile); hMapFile := 0; end; end;
2.消息
//发送消息 procedure SendProgramMsg(DesForm: THandle; wIdent,lp: Word;sSendMsg:string); var SendData : TCopyDataStruct; nParam : Integer; begin nParam := MakeLong(lp, wIdent); SendData.cbData := Length(AnsiString(sSendMsg)) + 1; GetMem(SendData.lpData, SendData.cbData); (PAnsiChar(SendData.lpData) + SendData.cbData)^ := #0; Move(PAnsiChar(AnsiString(sSendMsg))^, PAnsiChar(AnsiString(SendData.lpData))^, Length(AnsiString(sSendMsg)) + 1); SendMessage(DesForm, WM_COPYDATA, nParam, Cardinal(@SendData)); FreeMem(SendData.lpData); end;
//接收消息 procedure TfMain.MyMessage(var MsgData: TWmCopyData); var sRecv: AnsiString; sData: string; wIdent, wRecog: Word; begin wIdent := HiWord(MsgData.From); wRecog := LoWord(MsgData.From); sRecv := AnsiString(PAnsiChar(MsgData.CopyDataStruct^.lpData)); sData:= string(sRecv); case wIdent of end; end;
这篇关于delphi 进程间传递数据的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-01成为百万架构师的第一课:设计模式:Spring中的设计模式
- 2025-01-01一个基于注解驱动的可视化的DDD架构-超越COLA的设计
- 2025-01-01PlantUML 时序图 基本例子
- 2025-01-01plantuml 信号时序图
- 2025-01-01聊聊springboot项目如何优雅进行数据校验
- 2024-12-31自由职业者效率提升指南:3个时间管理技巧搞定多个项目
- 2024-12-31适用于咨询行业的项目管理工具:提升跨团队协作和工作效率的最佳选择
- 2024-12-31高效协作的未来:2024年实时文档工具深度解析
- 2024-12-31商务谈判者的利器!哪 6 款办公软件能提升春节合作成功率?
- 2024-12-31小团队如何选择最实用的项目管理工具?高效协作与任务追踪指南