Copy the record into shared memory, exactly like how I showed you. Did you even try it?
Yes I tryed, but the compiler didn't compiled the Lazarus Part.
At "RasterImageInfo.nSize := MemSize;" there are errors:
Error: Illegal qualifier
Hint: may be pointer dereference is missing
Error: Illegal expression
I could fix it to this:
procedure TForm1.BitBtn1Click(Sender: TObject);
var
MemStrm: TMemoryStream;
MemSize: DWORD;
hMapping: THandle;
RasterImageInfo: PRasterImageInfo;
Output: String;
begin
if OpenPictureDialog1.Execute then
begin
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
MemStrm := TMemoryStream.Create;
try
Image1.Picture.Bitmap.SaveToStream(MemStrm);
MemSize := (SizeOf(TRasterImageInfo) - 1) + MemStrm.Size;
hMapping := CreateFileMapping(INVALID_HANDLE_VALUE, nil, PAGE_READWRITE, 0, MemSize, 'RasterImageInfo');
if hMapping = 0 then RaiseLastOSError;
try
RasterImageInfo := MapViewOfFile(hMapping, FILE_MAP_WRITE, 0, 0, MemSize);
if RasterImageInfo = nil then RaiseLastOSError;
try
RasterImageInfo^.nSize := MemSize;
RasterImageInfo^.nItemID := 1;
RasterImageInfo^.nFlags := $0007;
RasterImageInfo^.nWidth := Image1.Picture.Bitmap.Width;
RasterImageInfo^.nHeight := Image1.Picture.Bitmap.Height;
RasterImageInfo^.nResSize := MemStrm.Size;
Move(MemStrm.Memory^, RasterImageInfo^.nResBytes[0], MemStrm.Size);
// run external program, wait for it to finish using RasterImageInfo ...
RunCommand(toolpath, output);
finally
end;
finally
UnmapViewOfFile(RasterImageInfo);
end;
finally
CloseHandle(hMapping);
MemStrm.Free;
end;
end;
end;
Both tools are copiled now.
Is there a simple way to get the picture from the memory drawed at a screen or write it to a file?
So that I can see that it really works?
Update:
I was able to save the File with just this to lines:
#pragma warning(suppress : 4996)
FILE
* file
= fopen("memory.bmp", "wb"); fwrite(pRIInfo
->nResBytes
, 1, pRIInfo
->nResSize
, file
);
The size and the md5 hash are equal to the orignal file, if that was a normal bitmap image.
This is a good basis for further working.
Big Thanks to Remy Lebeau