How do I give a Pointer to a other process lazarus / 34-Windows ---------------------------------------------------------------------- LazUser20 · 2021-05-13 20:46 I have the following data structure. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  PRasterImageInfo=^TRasterImageInfo;  TRasterImageInfo=packed record  nSize: DWord;    nItemID: LongInt;    hItem: THandle;    nFlags, nWidth, nHeight, nResSize: DWord;  end;  It is filled with data: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.BitBtn1Click(Sender: TObject);begin  if OpenPictureDialog1.Execute    then      begin        Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);         RasterImageInfo.nSize:=sizeOf(RasterImageInfo);        RasterImageInfo.nItemID := 1;        RasterImageInfo.hItem := Image1.Picture.Bitmap.Handle;        RasterImageInfo.nFlags := $0007;        RasterImageInfo.nWidth  := Image1.Picture.Bitmap.Width;        RasterImageInfo.nHeight := Image1.Picture.Bitmap.Height;        RasterImageInfo.nResSize := GetFileSize(OpenPictureDialog1.FileName);         ValueListEditor1.Values['nSize']:=IntToStr(RasterImageInfo.nSize);      ValueListEditor1.Values['nItemID']:=IntToStr(RasterImageInfo.nItemI D);        ValueListEditor1.Values['nItem']:=IntToStr(RasterImageInfo.nItemID);      ValueListEditor1.Values['nFlags']:=IntToStr(RasterImageInfo.nFlags);      ValueListEditor1.Values['nWidth']:=IntToStr(RasterImageInfo.nWidth);      ValueListEditor1.Values['nHeight']:=IntToStr(RasterImageInfo.nHei ght);        ValueListEditor1.Values['nResSize']:=IntToStr(RasterImage Info.nResSize);        Label1.Caption := IntToStr(Image1.Picture.Bitma p.Width*Image1.Picture.Bitmap.Height*24);       end;end;       How do I send the pointer to a other process (maybe as start parameter), to access the data of this structure in the other process? The data structure is from here: http://www.x-ways.net/forensics/x-tensions/XWF_functions.html#E At this time the second process read the pointer from the start arguments: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #include // std::cout, std::endl, std::cin#include #include #include // EXIT_SUCCESS#include // strcmp() int main(int argc, struct RasterImageInfo* pRIInfo){        for (int i = 0; i < argc; i++)      {                // Ausgabe aller Parameter                std::cout << i << " \"" << pRIInfo->nSize<< "\"" << std::endl;        std::cout << i << " \"" << pRIInfo->nItemID << "\"" << std::endl;        std::cout << i << " \"" << pRIInfo->hItem << "\"" << std::endl;      std::cout << i << " \"" << pRIInfo->nFlags << "\"" << std::endl;      std::cout << i << " \"" << pRIInfo->nWidth << "\"" << std::endl;      std::cout << i << " \"" << pRIInfo->nHeight << "\"" << std::endl;      std::cout << i << " \"" << pRIInfo->nResSize << "\"" << std::endl;        }         std::cin.get();        return EXIT_SUCCESS;}   The pascal program is only for testing, if the C++-Tool read valid data, because I dont have access to a X-Ways. ---------------------------------------------------------------------- ASerge · 2021-05-14 00:38 Passing pointers is useless until a copy of the memory is passed, because Windows processes each have their own memory. There are several memory sharing mechanisms, but this must be explicitly implemented in both processes. Are you the creator of programs for both processes? ---------------------------------------------------------------------- Remy Lebeau · 2021-05-14 01:28 Quote from: LazUser20 on May 13, 2021, 10:46:27 pmHow do I send the pointer to a other process (maybe as start parameter), to access the data of this structure in the other process? You can't use pointers across process boundaries.  What you can do instead is allocate a named block of shared memory via CreateFileMapping() and MapViewOfFile() (see Sharing Files and Memory), and then each process can obtain its own pointer to the shared memory and read/write data in the block as needed.  You could pass the file mapping's shared name in a command-line parameter, if needed. Note: you can't share an HBITMAP handle across processes, period.  So this approach will not work for sharing the TRasterImageInfo.hItem field.  You will have to save the TBitmap's pixel data according to MSDN's Bitmap Storage documentation.  For instance, by saving the TBitmap to a TMemoryStream and then copying the raw bytes from the stream to the shared memory. For example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  PRasterImageInfo = ^TRasterImageInfo;  TRasterImageInfo = packed record    nSize: DWord;    nItemID: LongInt;    nFlags, nWidth, nHeight, nResSize: DWord;    nResBytes: array[0..0] of Byte;  end;     procedure TForm1.BitBtn1Click(Sender: TObject);var  MemStrm: TMemoryStream;  MemSize: DWORD;  hMapping: THandle;  RasterImageInfo: PRasterImageInfo;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 := Strm.Size;          Move(MemSStrm.Memory^, RasterImageInfo.nResBytes[0], Strm.Size);           // run external program, wait for it to finish using RasterImageInfo ...       finally        UnmapViewOfFile(RasterImageInfo);      end;    finally      CloseHandle(hMapping);    end;  finally    MemStrm.Free;  end;end; Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #include // std::cout, std::endl, std::cin#include #include #include // EXIT_SUCCESS#include // std::strcmp() #pragma pack(push, 1) // <-- or your compiler's equivalenttypedef struct TRasterImageInfo{  DWORD nSize;    LONG nItemID;    DWORD nFlags, nWidth, nHeight, nResSize;    BYTE nResBytes[1];} TRasterImageInfo, *PRasterImageInfo;#pragma pack(pop) // <-- or your compiler's equivalent     int main(int argc, char* argv[]){         HANDLE hMapping = OpenFileMapping(FILE_MAP_READ, FALSE, TEXT("RasterImageInfo"));    if (hMapping == NULL)        return EXIT_FAILURE;     PRasterImageInfo pRIInfo = (PRasterImageInfo) MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0);    if (pRIInfo == NULL)    {        CloseHandle(hMapping);        return EXIT_FAILURE;  }     // Ausgabe aller Parameter    std::cout << i << " \"" << pRIInfo->nSize << "\"" << std::endl;    std::cout << i << " \"" << pRIInfo->nItemID << "\"" << std::endl;    std::cout << i << " \"" << pRIInfo->nFlags << "\"" << std::endl;    std::cout << i << " \"" << pRIInfo->nWidth << "\"" << std::endl;    std::cout << i << " \"" << pRIInfo->nHeight << "\"" << std::endl;    std::cout << i << " \"" << pRIInfo->nResSize << "\"" << std::endl;    // use pRIInfo->nResBytes as needed...     UnmapViewOfFile(pRIInfo);    CloseHandle(hMapping);     std::cin.get();    return EXIT_SUCCESS;} ---------------------------------------------------------------------- LazUser20 · 2021-05-30 12:21 OK. Thank you for your help. How do I put the whole record at the process execute (or something similar) to get it as process parameter at the other programm? Is ist possible just to get only a FilePointer and put this in a record instead of a handle to memory? ---------------------------------------------------------------------- MarkMLl · 2021-05-30 12:53 Quote from: LazUser20 on May 30, 2021, 02:21:42 pmOK. Thank you for your help. How do I put the whole record at the process execute (or something similar) to get it as process parameter at the other programm? Use shared memory. QuoteIs ist possible just to get only a FilePointer and put this in a record instead of a handle to memory? In general, no. You can pass a filename around and then open that with appropriate locking discipline, but you might do better considering IPC using OS-specific or UDP datagrams. MarkMLl ---------------------------------------------------------------------- engkin · 2021-05-30 13:03 X-Ways expects your code to be in a DLL. Meaning your code is going to be in the "same" process. ---------------------------------------------------------------------- Remy Lebeau · 2021-05-31 09:17 Quote from: LazUser20 on May 30, 2021, 02:21:42 pmHow do I put the whole record at the process execute (or something similar) to get it as process parameter at the other programm? Copy the record into shared memory, exactly like how I showed you. Did you even try it? Quote from: LazUser20 on May 30, 2021, 02:21:42 pmIs ist possible just to get only a FilePointer and put this in a record instead of a handle to memory? No. ---------------------------------------------------------------------- LazUser20 · 2021-06-09 17:20 Quote from: engkin on May 30, 2021, 03:03:51 pmX-Ways expects your code to be in a DLL. Meaning your code is going to be in the "same" process. Actual I don't have Xways so at this time it is not planed to build a X-tension. The project only should address the processing of the data and this maybe will be used later for building an xtension.  So I plan to build a tool, which read an image file and create the data structure and give this to the c++ program. ---------------------------------------------------------------------- ccrause · 2021-06-09 19:36 Quote from: LazUser20 on June 09, 2021, 07:20:04 pmQuote from: engkin on May 30, 2021, 03:03:51 pmX-Ways expects your code to be in a DLL. Meaning your code is going to be in the "same" process. Actual I don't have Xways so at this time it is not planed to build a X-tension. The project only should address the processing of the data and this maybe will be used later for building an xtension.  So I plan to build a tool, which read an image file and create the data structure and give this to the c++ program. Do you have an example of calling this C++ program with a pointer to RasterImageInfo?  I only know the very basics of C/C++, but the main function of the C++ program you showed in the first post looks non- standard.  Is that a real working program? ---------------------------------------------------------------------- LazUser20 · 2021-06-13 14:51 Quote from: Remy Lebeau on May 31, 2021, 11:17:19 am 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: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     #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 ---------------------------------------------------------------------- Remy Lebeau · 2021-06-13 19:03 Quote from: LazUser20 on June 13, 2021, 04:51:42 pmYes 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 guess that means FreePascal does not support the same "extended pointer syntax" that Delphi does, which allows for omiting the caret (^) when dereferencing a pointer. Quote from: LazUser20 on June 13, 2021, 04:51:42 pmI could fix it to this: That looks correct, yes. ---------------------------------------------------------------------- marcov · 2021-06-13 20:01 Quote from: Remy Lebeau on June 13, 2021, 09:03:20 pm I guess that means FreePascal does not support the same "extended pointer syntax" that Delphi does, which allows for omiting the caret (^) when dereferencing a pointer. It does for 20 years now. IF you actually set it to Delphi compatibility. ---------------------------------------------------------------------- engkin · 2021-06-13 20:31 or use: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$H+}{$ModeSwitch autoderef} ---------------------------------------------------------------------- dsiders · 2021-06-13 20:40 Quote from: engkin on June 13, 2021, 10:31:37 pmor use: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$H+}{$ModeSwitch autoderef} Aha! I've never noticed that one. Thanks @engkin.