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.
Need Help with Memory sharing/Kernel32/Pascal dll
Jump to
- Welcome
- Board admin messages
- Afterprime
- Funding our Forum. Tommaso needs our help.
- TDesk: A Thomas Special. The greatest trading tool ever.
- Automated trading systems
- ↳ Archived EA's
- ↳ EA's for Dummies.
- ↳ The demo/live money EA results forum
- ↳ Automated Loss Recovery
- ↳ Thingy Bob EA's
- ↳ Pipcruiser's Pipmasher forum
- ↳ Peaky forum
- ↳ Super Slope EA's
- ↳ Coordinated EA Testing Forum
- ↳ Moving Day
- ↳ Trendy Moving Day Adapted
- ↳ Trendy Monster Moving Day
- ↳ The Paycheck Project
- Manual trading systems
- ↳ Captain Jack's forum
- Utilities Indicators and Scripts
- ↳ Indicators
- ↳ Utilities
- ↳ Scripts
- Rene's stuff
- ↳ Auto-trading EA's and EA monitors
- ↳ Chart/template copying and history loading
- ↳ Clocks and calendars
- ↳ Data analysis tools
- ↳ Indicators and matrixes
- Nanningbob's Holy Grail Indicator forum
- ↳ Nanningbob 10.x
- ↳ Bob's individual forum
- ↳ Manual 10.x trading
- ↳ 10.x EA forum
- ↳ 10.x Indi forum
- ↳ 10.7 Auto Traders Forum
- BALUDA'S SUPER CSS-2.0. THE SIMPLEST TRADING SYSTEM EVER
- MQ5 Nuggets for the Dauntless
- Alternatives to Global Prime
- Coders Hangout
- ↳ Ideas for Possible Automation
- ↳ Coding Lessons - info for all
- Alternative platforms
- ↳ cTrader and cAlgo
- ↳ General discussion
- ↳ Indicators
- ↳ Robots
- ↳ JForex
- ↳ LMAX
- ↳ Tradable
- ↳ Protrader
- Know your MT4 platform
- General Forex Discussion
- ↳ Trading journals
- ↳ Finding a new platform
- ↳ Scam broker forum
- Trading Psychology & Money Management
- Macroeconomics and the Forex markets
- Newbie Discussion
- ↳ Automated trading (Rookies)
- ↳ General Discussion (Rookies)
- Lounge
- Commercial wares
- ↳ Beta testing groups
- ↳ Commercial stuff recommended by forum members
- ↳ Members' business to business
- ↳ Commercial EA's and Indi's etc
- ↳ VPS promotions
- ↳ INFINITE WEALTH