AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Wie, um den Code zu übersetzen C + + bis Delphi

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

Ein Thema von SlpLow · begonnen am 4. Nov 2013 · letzter Beitrag vom 5. Nov 2013
Antwort Antwort
Seite 1 von 2  1 2   
SlpLow

Registriert seit: 4. Nov 2013
28 Beiträge
 
#1

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

  Alt 4. Nov 2013, 20:09
(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;

Geändert von SlpLow ( 5. Nov 2013 um 00:30 Uhr)
  Mit Zitat antworten Zitat
greenzed

Registriert seit: 5. Nov 2013
1 Beiträge
 
#2

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

  Alt 5. Nov 2013, 01:04
aus c++ zu delphi?
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.014 Beiträge
 
Delphi 12 Athens
 
#3

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

  Alt 5. Nov 2013, 01:17
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 'DLLNamename '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
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu ( 5. Nov 2013 um 01:37 Uhr)
  Mit Zitat antworten Zitat
SlpLow

Registriert seit: 4. Nov 2013
28 Beiträge
 
#4

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

  Alt 5. Nov 2013, 02:35
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;
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.014 Beiträge
 
Delphi 12 Athens
 
#5

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

  Alt 5. Nov 2013, 03:30
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 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.
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu ( 5. Nov 2013 um 03:36 Uhr)
  Mit Zitat antworten Zitat
SlpLow

Registriert seit: 4. Nov 2013
28 Beiträge
 
#6

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

  Alt 5. Nov 2013, 04:05
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.
  Mit Zitat antworten Zitat
SlpLow

Registriert seit: 4. Nov 2013
28 Beiträge
 
#7

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

  Alt 5. Nov 2013, 06:22
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;

Geändert von SlpLow ( 5. Nov 2013 um 06:44 Uhr)
  Mit Zitat antworten Zitat
SlpLow

Registriert seit: 4. Nov 2013
28 Beiträge
 
#8

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

  Alt 5. Nov 2013, 07:45
aus c++ zu delphi?
Yes
  Mit Zitat antworten Zitat
Benutzerbild von MrSpock
MrSpock
(Co-Admin)

Registriert seit: 7. Jun 2002
Ort: Owingen
5.865 Beiträge
 
Delphi 2010 Professional
 
#9

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

  Alt 5. Nov 2013, 08:25
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.
Albert
Live long and prosper


MrSpock
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.014 Beiträge
 
Delphi 12 Athens
 
#10

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

  Alt 5. Nov 2013, 10:00
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;
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2   

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:43 Uhr.
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