Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Wie, um den Code zu übersetzen C + + bis Delphi (https://www.delphipraxis.net/177393-wie-um-den-code-zu-uebersetzen-c-bis-delphi.html)

SlpLow 4. Nov 2013 19:09

Wie, um den Code zu übersetzen C + + bis Delphi
 
(Leider ist es On-Line Translation)
Hallo liebe!
Nicht genug Wissen, um den Code zu C++ Delphi übersetzen, so hoffe ich, Künstler zu helfen.

C + + Code

WCHAR * buff;
DWORD readed;
buff = new

WCHAR(WCHAR_MAX);
if
(WIMGetImageInformation(WIM_FILE_HANDLE, (PVOID*)&buff, &readed))
{
wprintf(L"%s", buff); // muss TMemo, D2009
}

Struktur des Referenz MSDN
BOOL
WINAPI
WIMGetImageInformation(
HANDLE hImage,
PVOID *ppvImageInfo,
PDWORD pcbImageInfo
);

Delphi funktion
TWIMGetImageInformation = function(
hImage: THandle;
ppvImageInfo: Pointer;
pcbImageInfo: PDWORD
): BOOL; stdcall;

greenzed 5. Nov 2013 00:04

AW: Wie, um den Code zu übersetzen C + + bis Delphi
 
aus c++ zu delphi?

himitsu 5. Nov 2013 00:17

AW: Wie, um den Code zu übersetzen C + + bis Delphi
 
Und wo genau ist nun das Problem?
Die Übersetzung sieht soweit ja OK aus.
(wenn man die Adresse dann via LoadLibrary + GetProcAddress holen will)

Delphi-Quellcode:
function WIMGetImageInformation(hImage: THandle; ppvImageInfo: Pointer; pcbImageInfo: PDWORD): BOOL; stdcall;
  external 'DLLName';

// wenn Importname <> Funktionname
function WIMGetImageInformation(hImage: THandle; ppvImageInfo: Pointer; pcbImageInfo: PDWORD): BOOL; stdcall;
  external 'DLLName' name 'ImportName';

// im Delphi-Style
function WIMGetImageInformation(Image: THandle; ImageInfo: PWideChar{Pointer}; ImageInfoSize: PLongWord): LongBool; stdcall;
  external 'DLLName';

function WIMGetImageInformation(Image: THandle; ImageInfo: PWideChar{Pointer}; var ImageInfoSize: LongWord): LongBool; stdcall;
  external 'DLLName';

function WIMGetImageInformation(Image: THandle; out ImageInfo; out ImageInfoSize: LongWord): LongBool; stdcall; // oder VAR statt OUT ... funktioniert Beides
  external 'DLLName';
[edit]
PS: Suchfunktion?
http://www.delphipraxis.net/137479-w...tml#post934938

SlpLow 5. Nov 2013 01:35

AW: Wie, um den Code zu übersetzen C + + bis Delphi
 
Danke! In jedem Fall zeigt Müll ...
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
const
  created: DWORD = 1;
var
  WimHandle: THandle;
  Size: Integer;
  Buffer: PChar;
  Pot: PDWORD;
begin
  WimHandle := WIMCreateFile
    (PWideChar('e:\TestWim\x86\sources\boot.wim'),
    WIM_GENERIC_READ, WIM_OPEN_EXISTING, WIM_FLAG_SHARE_WRITE,
    WIM_COMPRESS_XPRESS, @created);
  Size := 10000;
  GetMem(Buffer, Size);
  Pot := @Size;

  if WIMGetImageInformation(WimHandle, Buffer, Pot) Then
  begin
  Memo1.Lines.Add(Buffer);
// Memo1.Text := String(Buffer);;
  end;
  FreeAndNil(Buffer);
end;

himitsu 5. Nov 2013 02:30

AW: Wie, um den Code zu übersetzen C + + bis Delphi
 
Welche Delphi-Version nutzt du?
(vor D2009 muß es "Müll" liefern, da dein Buffer dort PAnsiChar wäre)

pdwCreationResult ist ein Out-Parameter.
Wieso wird da eine Konstante reingegeben?

Und hast du nachgesehn was dein Code macht?
- was steht in WimHandle
- was in created
- und was in Pot (nach WIMGetImageInformation)

Zitat:

Zitat von WIMCreateFile und WIMGetImageInformation
If the function fails, the return value is NULL. To obtain extended error information, call the GetLastError function

[add]
http://msdn.microsoft.com/en-us/libr.../dd834949.aspx
Lies mal bitte die Beschreibung von ppvImageInfo und den letzten Satz von Remarks.

SlpLow 5. Nov 2013 03:05

AW: Wie, um den Code zu übersetzen C + + bis Delphi
 
Es tut mir leid. Unbequeme zu übersetzen und zu antworten - ich verstehe Ihre Frage, und ich werde nach der Überprüfung den Code zu beantworten.

SlpLow 5. Nov 2013 05:22

AW: Wie, um den Code zu übersetzen C + + bis Delphi
 
1. Müll entfernt, aber wenn du jetzt gehst FreeMem(Buffer), wirft es auf einen Fehler - invalid pointer operation, plus einen Speicherverlust.
Delphi-Quellcode:
unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses WIMGAPI;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
const
  created: DWORD = 1;
var
  FileHandle: THandle;
  dwError: DWORD;
  Size: Integer;
  Buffer: PWideChar;
  Pot: PDWORD;
begin
  InitWIMGAPI;
  FileHandle := WIMCreateFile
    (PWideChar('d:\Wim_Image\x86\sources\install.wim'),
    WIM_GENERIC_READ, WIM_OPEN_EXISTING, WIM_FLAG_SHARE_WRITE,
    WIM_COMPRESS_XPRESS, 0);

  if (FileHandle = 0) then
  begin
    dwError := GetLastError;
    ShowMessage('Error Open ' + IntToStr(GetLastError));
    Exit;
  end
  else
  begin
    Size := 10000;
    GetMem(Buffer, Size);
    Pot := @Size;
    Memo1.Clear;
    if (not WIMGetImageInformation(FileHandle, @Buffer, Pot)) Then
    begin
      dwError := GetLastError;
      ShowMessage('Error Info ' + IntToStr(GetLastError));
      Exit;
    end
    else
    begin
      Memo1.Lines.Add(Buffer);
      WIMCloseHandle(FileHandle);
      FreeMem(Buffer); //invalid pointer operation
    end;
  end;
end;

end.
2. Wie schnell und schön zu analysieren Daten auf alle Bilder
* und ziehen in Memo?
<NAME>Windows 7 HOMEBASIC</NAME> = Windows 7 HOMEBASIC;
<NAME>Windows 7 ULTIMATE</NAME> = Windows 7 ULTIMATE;

SlpLow 5. Nov 2013 06:45

AW: Wie, um den Code zu übersetzen C + + bis Delphi
 
Zitat:

Zitat von greenzed (Beitrag 1234508)
aus c++ zu delphi?

Yes

MrSpock 5. Nov 2013 07:25

AW: Wie, um den Code zu übersetzen C + + bis Delphi
 
Hello SlipSlow,

if you don't speak German, you should write in English and for long term planning either learn German or try to find an English forum. You should not use automatic translation because the translated text is hard to understand and is misleading.

himitsu 5. Nov 2013 09:00

AW: Wie, um den Code zu übersetzen C + + bis Delphi
 
Zitat:

Zitat von WIMGetImageInformation
ppvImageInfo

[out] A pointer to a buffer that receives the address of the XML information about the volume image. When the function returns, this value contains the address of an allocated buffer, containing XML information about the volume image.

pcbImageInfo

[out] A pointer to a variable that specifies the size, in bytes, of the buffer pointed to by the value of the ppvImageInfo parameter.

Remarks

When the function succeeds, then the data describing the image is in Unicode XML format. Use the LocalFree function to free the memory pointed to by the ppvImageInfo parameter when no longer needed.

Delphi-Quellcode:
var
  created: DWORD; // Out-Parameter !!!!!!!!
var
  FileHandle: THandle;
  dwError: DWORD;
  Size: Integer;
  Buffer: PWideChar;
begin
  Memo1.Clear;

  InitWIMGAPI;
  FileHandle := WIMCreateFile(
    //PWideChar('d:\Wim_Image\x86\sources\install.wim'),
    PWideChar('C:\Windows\winsxs\amd64_microsoft-windows-setup-component_31bf3856ad364e35_6.1.7601.17514_none_905283bdc3e1d2d8\FirstUXRes.WIM'),
    WIM_GENERIC_READ, WIM_OPEN_EXISTING, WIM_FLAG_SHARE_WRITE,
    WIM_COMPRESS_XPRESS,
    @created); // or "nil);"

  case created of
    WIM_CREATED_NEW:
      Memo1.Lines.Add('Created New');
    WIM_OPENED_EXISTING:
      Memo1.Lines.Add('Opend Existing');
    //else
    //  Memo1.Lines.Add('Unknown Created Code ' + IntToStr(created));
  end;

  if FileHandle = 0 then
  begin
    dwError := GetLastError;
    Memo1.Lines.Add('Error Open ' + IntToStr(dwError));
  end
  else
  begin
    //Size := 10000;        // Out-Parameter
    //GetMem(Buffer, Size); // Out-Parameter

    if not WIMGetImageInformation(FileHandle, @Buffer, @Size) Then
    begin
      dwError := GetLastError;
      Memo1.Lines.Add('Error Info ' + IntToStr(dwError));
    end
    else
    begin
      Memo1.Lines.Add('Info Size ' + IntToStr(Size));
      Memo1.Lines.Add('');
      Memo1.Lines.Add(Buffer);
      WIMCloseHandle(FileHandle);
      LocalFree(HLOCAL(Buffer)); // allocated by WIMGetImageInformation
    end;
  end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:41 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz