| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Need Help with Memory sharing/Kernel32/Pascal dll https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=2620 |
Page 1 of 1 |
| Author: | KingHigh [ Wed Jun 26, 2013 11:05 pm ] |
| Post subject: | Need Help with Memory sharing/Kernel32/Pascal dll |
Help: Problem getting File Mapping working with Empty4/pascal dll Hi All, Hopefully, I will get a quick answer on this. I have a prototype using Kernell32.dll and using the File Mapping functions of sharing data between charts and Empty4 directories. I use a Pascal DLL so that I have an easy access to pointer functionality that Empty4 lacks. I have every thing working but I get an exception when I try to move memory into and from Mapped Memory using RtlMoveMemory(). The exception is either a C00000FD or a C0000005. SoOOO I need permission to write into the map or my pointer usage isn't working. Does anyone know if Empty4 is blocking me some how with permissions into mapped page memory or something else out there is Empty4 craziness. I have added my pascal prototype code in case anyone wants to look at it for obvious miss use of pointerw. I am new to pascal but have written a pretty solid file management dll --- but this has me stumped. KingHigh //========================================================== ======== CONST READ = 1; WRITE = 2; var MapTmp: array [0..1024] of Byte; function FPC_AccessFileMap( var CntlBlock: TCntlBlock; var XferBufr: TXferBufr ): Boolean stdcall; // CntlBlock contains r or w, chr cnt, max buffervsize, and the pointer to the buffer. // XferBufr contains integers to be written into the map or return data being read from the map. var ChrShift: Array [0..3] of DWORD = (0,8,16,24); RdOrWrt, MaxDWords, CharCnt, DWdIdx, ChrIdx, DWdChr, DWd_MapAdr: DWORD; DWdXfer, ShiftVal: Integer; MapTmpPtr: PByte; MapFilePtr: PByte; Test: Byte; begin MapTmpPtr := @MapTmp[0]; RdOrWrt := CntlBlock[0]; MaxDWords := CntlBlock[1]; CharCnt := CntlBlock[2]; DWd_MapAdr := CntlBlock[3]; // Integer containing Ptr to MapBufr //MapFilePtr := PByte(DWd_MapAdr); OutputDebugString(PChar(Format('CFS M: After var init,RdOrWrt = %d, MaxDWords = %d, CharCnt = %d, MapTmpPtr= %d. MapFilePtr= %d. ', [RdOrWrt,MaxDWords,CharCnt,DWORD(Map TmpPtr),DWORD(MapTmpPtr)]))); FPC_AccessFileMap := FALSE; if( ( ( MaxDWords * 4) >= CharCnt ) and ( CharCnt > 0 ) ) then begin if RdOrWrt = READ then // Build Int XferBufr from MapFile access. begin OutputDebugString(PChar(Format('CFS M: Lets Xfer data, in read loop, Xter[0,1,2,3] = %x, %x, %x, %x.',[XferBufr[0],XferBufr[1],XferBufr[2],XferBufr[3]]))); //RtlMoveMemory( MapTmpPtr, MapFilePtr, CharCnt ); for ChrIdx := 0 to CharCnt-1 do MapTmp[ChrIdx] := MapTmp[ChrIdx]; OutputDebugString(PChar(Format('CFS M: AFM Read Move Complete!!',[]))); for ChrIdx := 0 to CharCnt-1 do begin DWdChr := DWORD(MapTmp[ChrIdx]); OutputDebugString(PChar(Format('CFS M: After DWORD DWdIdx = %d, DWrdChr = %x.',[DWdIdx,DWdChr]))); XferBufr[DWdIdx] := XferBufr[DWdIdx] or ( (DWORD(MapTmp[ChrIdx])) shl ChrShift[ChrIdx and 3] ); OutputDebugString(PChar(Format('CFS M: Read From Map Buffer, XferBufr[DWdIdx] = %x, ChrIdx = %d.',[XferBufr[DWdIdx],ChrIdx]))); end; FPC_AccessFileMap := TRUE; OutputDebugString(PChar(Format('CFS M: AFM Read Complete!!',[]))); end else //THEN RdOrWrt = Write // Write chars from XferBufr into MapFile access begin OutputDebugString(PChar(Format('CFS M: Lets Xfer data, in write loop, Xter[0,1,2,3] = %x, %x, %x, %x.',[XferBufr[0],XferBufr[1],XferBufr[2],XferBufr[3]]))); for ChrIdx := 0 to CharCnt-1 do begin //OutputDebugString(PChar(Format('CFS M: Xfer[] = %x. ',[XferBufr[ChrIdx DIV 4]]))); OutputDebugString(PChar(Format('CFS M: After DWORD DWdXfer = %x, ShiftVal = %d, ChrIdx=%d, CharCnt=%d.', [DWdXfer,ShiftVal,ChrIdx,CharCnt]))); MapTmp[ChrIdx] := ((XferBufr[ChrIdx DIV 4]) SHR (ChrShift[ChrIdx AND 3])); OutputDebugString(PChar(Format('CFS M: After DWORD MapTmp[ChrIdx] = %x',[MapTmp[ChrIdx]]))); //OutputDebugString(PChar(Format('CFS M: Write to Map Buffer, DWdXfer = %x , ChrIdx =%d , ChrShift[ChrIdx and 3] =%x,',[DWdXfer,ChrShift[ChrIdx and 3]]))); end; //RtlMoveMemory( MapFilePtr, MapTmpPtr, CharCnt ); for ChrIdx := 0 to CharCnt-1 do MapTmp[ChrIdx] := MapTmp[ChrIdx]; FPC_AccessFileMap := TRUE; OutputDebugString(PChar(Format('CFS M: AFM Write RtlMove Complete!!',[]))); end; end; end; //======================================================================= exports FPC_CreateFileMapA, FPC_OpenFileMapA, FPC_MapViewOfFile, FPC_UnmapViewOfFile, FPC_FlushViewOfFile, FPC_AccessFileMap, FPC_CloseHandle, FPC_DeleteFileA; end. |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|