delphi获取第三方进程里面的数据

想读取第三方软件里面stringgrid里面的刷新数据,最后一条。跑不通

img

delphi代码。gpt给的。报错。


procedure TForm1.Button1Click(Sender: TObject);


var
  hWebslin: HWND; // Webslin.exe main window handle
  hStringGrid: HWND; // StringGrid handle
  RowCount: Integer; // Number of rows
  ColCount: Integer; // Number of columns
  RowIndex: Integer; // Row index
  ColIndex: Integer; // Column index
  CellTextLength: Integer; // Cell text length
  CellTextBuffer: PChar; // Cell text buffer
  GM_GETROWCOUNT,GM_GETCOLCOUNT,GM_GETCELLTEXTLENGTH:integer;
  GM_GETCELLTEXT: PChar;


begin
  hWebslin := FindWindow(nil,'webslin.exe'); // Get webslin.exe main window handle by title (you can also use other methods such as EnumWindows or GetWindowThreadProcessId)

  if hWebslin <> 0 then // If webslin.exe main window handle is valid
  begin

    hStringGrid := FindWindowEx(hWebslin,0,nil,'Tstringgrid'); // Get StringGrid handle by class name (you can also use other criteria such as title or ID)

    if hStringGrid <> 0 then // If StringGrid handle is valid
    begin

      RowCount := SendMessage(hStringGrid, GM_GETROWCOUNT, 0, 0); // Get number of rows
      ColCount := SendMessage(hStringGrid, GM_GETCOLCOUNT, 0, 0); // Get number of columns

      RowIndex := RowCount -1 ; // Set row index to last row

      for ColIndex := 0 to ColCount -1 do // Loop through all columns in last row
      begin

        CellTextLength := SendMessage(hStringGrid,GM_GETCELLTEXTLENGTH ,RowIndex * ColCount + ColIndex +1 ,0); // Get cell text length by row and column index (note that index starts from one)
        GetMem(CellTextBuffer ,CellTextLength +1); // Allocate cell text buffer memory space (note that one extra byte is needed for null terminator)
        SendMessage(hStringGrid,GM_GETCELLTEXT ,RowIndex * ColCount + ColIndex +1 ,LPARAM(CellTextBuffer)); // Get cell text by row and column index and store it in buffer

        ShowMessage(CellTextBuffer); // Show cell text (you can also do other things with it)

        FreeMem(CellTextBuffer); // Free cell text buffer memory space

      end;

    end;

   end;

这些控件不是标准windows控件,所以spy++得不到数据,应该考虑直接去读取进程的内存获取。

不是签入啊。我是要获取获取的usb数据存入数据库。他原来的上位机程序只能导出txt。如果他的上位机程序能直接写数据库就没这个问题了。