Thema: Delphi Cpp > Pas

Einzelnen Beitrag anzeigen

Nils_13

Registriert seit: 15. Nov 2004
2.647 Beiträge
 
#1

Cpp > Pas

  Alt 28. Mär 2008, 17:59
Hi,

ich muss einen Cpp-Code übersetzen und habe Probleme mit den gegebenen Typen.
Extreme Probleme macht mir die Übersetzung von einem LPVOID und CHAR_INFO. Was ich ebensowenig herausfinden konnte ist, was ein &... bedeutet. Ich wusste einfach nicht, was ich da Google fragen sollte. Ich habe im unteren Code (Pascal) die problematischen Zeilen markiert und die Fehlermeldung dazugeschrieben. Hier die beiden Codes:
Code:
#include <windows.h>
#include <stdio.h>
 
VOID main(void)

    HANDLE hStdout, hNewScreenBuffer;
    SMALL_RECT srctReadRect;
    SMALL_RECT srctWriteRect;
    CHAR_INFO chiBuffer[160]; // [2][80];
    COORD coordBufSize;
    COORD coordBufCoord;
    BOOL fSuccess;
 
    // Get a handle to the STDOUT screen buffer to copy from and
    // create a new screen buffer to copy to.
 
    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    hNewScreenBuffer = CreateConsoleScreenBuffer( 
       GENERIC_READ |           // read/write access
       GENERIC_WRITE,
       0,                      // not shared
       NULL,                   // default security attributes
       CONSOLE_TEXTMODE_BUFFER, // must be TEXTMODE
       NULL);                  // reserved; must be NULL
    if (hStdout == INVALID_HANDLE_VALUE || 
            hNewScreenBuffer == INVALID_HANDLE_VALUE)
    {
        printf("CreateConsoleScreenBuffer (%d)\n", GetLastError());
        return;
    }
 
    // Make the new screen buffer the active screen buffer.
 
    if (! SetConsoleActiveScreenBuffer(hNewScreenBuffer) )
    {
        printf("SetConsoleActiveScreenBuffer (%d)\n",
            GetLastError());
        return;
    }
 
    // Set the source rectangle.
 
    srctReadRect.Top = 0;   // top left: row 0, col 0 
    srctReadRect.Left = 0;
    srctReadRect.Bottom = 1; // bot. right: row 1, col 79 
    srctReadRect.Right = 79;
 
    // The temporary buffer size is 2 rows x 80 columns.
 
    coordBufSize.Y = 2;
    coordBufSize.X = 80;
 
    // The top left destination cell of the temporary buffer is
    // row 0, col 0.
 
    coordBufCoord.X = 0;
    coordBufCoord.Y = 0;
 
    // Copy the block from the screen buffer to the temp. buffer.
 
    fSuccess = ReadConsoleOutput( 
       hStdout,       // screen buffer to read from
       chiBuffer,     // buffer to copy into
       coordBufSize,  // col-row size of chiBuffer
       coordBufCoord, // top left dest. cell in chiBuffer
       &srctReadRect); // screen buffer source rectangle
    if (! fSuccess)
    {
        printf("ReadConsoleOutput (%d)\n", GetLastError());
        return;
    }
 
    // Set the destination rectangle.
 
    srctWriteRect.Top = 10;   // top lt: row 10, col 0 
    srctWriteRect.Left = 0;
    srctWriteRect.Bottom = 11; // bot. rt: row 11, col 79 
    srctWriteRect.Right = 79;
 
    // Copy from the temporary buffer to the new screen buffer.
 
    fSuccess = WriteConsoleOutput( 
        hNewScreenBuffer, // screen buffer to write to
        chiBuffer,       // buffer to copy from
        coordBufSize,    // col-row size of chiBuffer
        coordBufCoord,   // top left src cell in chiBuffer
        &srctWriteRect); // dest. screen buffer rectangle
    if (! fSuccess)
    {
        printf("WriteConsoleOutput (%d)\n", GetLastError());
        return;
    }
    Sleep(5000);
 
    // Restore the original active screen buffer.
 
    if (! SetConsoleActiveScreenBuffer(hStdout))
    {
        printf("SetConsoleActiveScreenBuffer (%d)\n",
            GetLastError());
        return;
    }
}
Nützliches:
Code:
HANDLE WINAPI CreateConsoleScreenBuffer(
  __in       DWORD dwDesiredAccess,
  __in       DWORD dwShareMode,
  __in_opt   const SECURITY_ATTRIBUTES* lpSecurityAttributes,
  __in       DWORD dwFlags,
  __reserved LPVOID lpScreenBufferData
);
Delphi-Quellcode:
procedure TfrmMain.Button1Click(Sender: TObject);
var hStdout, hNewScreenBuffer : THandle;
    srctReadRect, srctWriteRect : TRect;
    coordBufSize, coordBufCoord : TPoint;
    fSuccess : Boolean;
    CHAR_INFO chiBuffer[160]; // [2][80]; <--
begin
  hStdout := GetStdHandle(STD_OUTPUT_HANDLE);
  hNewScreenBuffer := CreateConsoleScreenBuffer(GENERIC_READ, GENERIC_WRITE, nil, 0, CONSOLE_TEXTMODE_BUFFER, 0); <-- [Fehler] Unit1.pas(34): Inkompatible Typen: 'Integer' und 'Pointer' >>> siehe "Nützliches"

  if (hStdout = INVALID_HANDLE_VALUE) or (hNewScreenBuffer = INVALID_HANDLE_VALUE) then
    raise Exception.Create('CreateConsoleScreenBuffer: '+IntToStr(GetLastError));

  if not SetConsoleActiveScreenBuffer(hNewScreenBuffer) then
    raise Exception.Create('SetConsoleActiveScreenBuffer: '+IntToStr(GetLastError));

  srctReadRect.Top := 0; // top left: row 0, col 0
  srctReadRect.Left := 0;
  srctReadRect.Bottom := 1; // bottom right: row 1, col 79
  srctReadRect.Right := 79;
  // The temporary buffer size is 2 rows x 80 columns
  coordBufSize.Y := 2;
  coordBufSize.X := 80;
  // The top left destination cell of the temporary buffer is
  // row 0, col 0.
  coordBufCoord.X := 0;
  coordBufCoord.Y := 0;

  // Copy the block from the screen buffer to the temp. buffer.
  fSuccess := ReadConsoleOutput(hStdout, chiBuffer, coordBufSize, coordBufCoord, ^srctReadRect); <-- hierfür müsste ich CHAR_INFO übersetzen können, abgesehen davon könnte es noch mehr Ärger in dieser Zeile geben
  if not fSuccess then
    raise Exception.Create('ReadConsoleOutput: '+IntToStr(GetLastError));

  // Set the destination rectangle.
  srctWriteRect.Top := 10; // top lt: row 10, col 0
  srctWriteRect.Left := 0;
  srctWriteRect.Bottom := 11; // bot. rt: row 11, col 79
  srctWriteRect.Right := 79;

  // Copy from the temporary buffer to the new screen buffer.
  fSuccess := WriteConsoleOutput(hNewScreenBuffer, chiBuffer, coordBufSize, coordBufCoord, ^srctWriteRect); <-- hierfür müsste ich CHAR_INFO übersetzen können, abgesehen davon könnte es noch mehr Ärger in dieser Zeile geben
  if not fSuccess then
    raise Exception.Create('WriteConsoleOutput: '+IntToStr(GetLastError));
  Sleep(5000); // Nötig ????

  // Restore the original active screen buffer.
  if not SetConsoleActiveScreenBuffer(hStdout)
    raise Exception.Create('SetConsoleActiveScreenBuffer: '+IntToStr(GetLastError));
end;
  Mit Zitat antworten Zitat