AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Hilfe beim Übersetzen von C zu Delphi

Hilfe beim Übersetzen von C zu Delphi

Ein Thema von SlpLow · begonnen am 18. Nov 2013 · letzter Beitrag vom 20. Nov 2013
Antwort Antwort
SlpLow

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

Hilfe beim Übersetzen von C zu Delphi

  Alt 18. Nov 2013, 17:47
Hallo liebe! Benötige Hilfe übersetzen bei VC++ zu Delphi!

VC++
....

Delphi-Quellcode:
void EditWIMFile(HANDLE hImg, int imgNum, LPWSTR pName, LPWSTR pDesc)
{
//Get the info and divide it into two strings
WCHAR *ImgInfoBuf, TempString[100];
DWORD ImgInfoBufSize;
WIMGetImageInformation(hImg, (LPVOID *)&ImgInfoBuf, &ImgInfoBufSize);
wsprintf(TempString, TEXT("<IMAGE INDEX=\"%d\">"), imgNum);
WCHAR *StringPointer = wcsstr(ImgInfoBuf, TempString); 
WCHAR *SecondString = wcsstr(++StringPointer, TEXT("<"));
SecondString[-1] = 0; //end the first string 

//Copy the first string to a new buffer and add our extra info
WCHAR *NewInfoBuf = (WCHAR *)LocalAlloc(LPTR, ImgInfoBufSize + 200 * sizeof(WCHAR));
lstrcpy(NewInfoBuf, ImgInfoBuf);
if (*pName) {
wsprintf(TempString, TEXT(" <NAME>%s</NAME>\n  "), pName);
lstrcat(NewInfoBuf, TempString);
}

if (*pDesc) {
if (*pName)
wsprintf(TempString, TEXT("<DESCRIPTION>%s</DESCRIPTION>\n  "), pDesc);
else
wsprintf(TempString, TEXT(" <DESCRIPTION>%s</DESCRIPTION>\n  "), pDesc);
lstrcat(NewInfoBuf, TempString);
}

//Add the second string to the new buffer and reset the info in the file
lstrcat(NewInfoBuf, SecondString);
WIMSetImageInformation(hImg, NewInfoBuf, wcslen(NewInfoBuf) * sizeof(WCHAR));

//Free the storage
LocalFree(ImgInfoBuf);
LocalFree(NewInfoBuf);
}
....

Geändert von SlpLow (19. Nov 2013 um 04:57 Uhr)
  Mit Zitat antworten Zitat
Der schöne Günther

Registriert seit: 6. Mär 2013
6.199 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: Hilfe beim Übersetzen von C zu Delphi

  Alt 18. Nov 2013, 21:04
And which lines are you having problems with?

Also, please consider properly formatting and wrapping your code in <code></code>-tags.

Code:
void EditWIMFile(HANDLE hImg, int imgNum, LPWSTR pName, LPWSTR pDesc) {
   
   //Get the info and divide it into two strings
   WCHAR *ImgInfoBuf, TempString[100];
   DWORD ImgInfoBufSize;
   
   WIMGetImageInformation(
      hImg,
      (LPVOID *)&ImgInfoBuf,
      &ImgInfoBufSize
   );
   
   wsprintf(TempString, TEXT("<IMAGE INDEX=\"%d\">"), imgNum);
   
   WCHAR *StringPointer = wcsstr(ImgInfoBuf, TempString);
   WCHAR *SecondString = wcsstr(++StringPointer, TEXT("<"));
   SecondString[-1] = 0; //end the first string

   //Copy the first string to a new buffer and add our extra info
   WCHAR *NewInfoBuf = (WCHAR *)LocalAlloc(
      LPTR,
      ImgInfoBufSize + 200 * sizeof(WCHAR)
   );
   lstrcpy(NewInfoBuf, ImgInfoBuf);
   
   if (*pName) {
      wsprintf(TempString, TEXT(" <NAME>%s</NAME>\n "), pName);
      lstrcat(NewInfoBuf, TempString);
   }
   
   if (*pDesc) {
      if (*pName)
         wsprintf(TempString, TEXT("<DESCRIPTION>%s</DESCRIPTION>\n "), pDesc);
      else
         wsprintf(TempString, TEXT(" <DESCRIPTION>%s</DESCRIPTION>\n "), pDesc);
      
      lstrcat(NewInfoBuf, TempString);
   }

   //Add the second string to the new buffer and reset the info in the file
   lstrcat(NewInfoBuf, SecondString);
   WIMSetImageInformation(hImg, NewInfoBuf, wcslen(NewInfoBuf) * sizeof(WCHAR));

   //Free the storage
   LocalFree(ImgInfoBuf);
   LocalFree(NewInfoBuf);
}
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

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

AW: Hilfe beim Übersetzen von C zu Delphi

  Alt 18. Nov 2013, 21:21
Über die Suchfunktion kann man auch schon einige fertig übersetzte Delphi-Übersetzungen finden

z.B.
Hier im Forum suchenWIMGetImageInformation

http://www.delphipraxis.net/137479-w...er-delphi.html
http://www.delphipraxis.net/177393-w...is-delphi.html
Ein Therapeut entspricht 1024 Gigapeut.
  Mit Zitat antworten Zitat
SlpLow

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

AW: Hilfe beim Übersetzen von C zu Delphi

  Alt 19. Nov 2013, 00:02
Versuchte...

Versuchte...
Speichert keine!

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
const
  CR = #13#10;
var
  WimHandle, ImageHandle: THandle;
  Created, ImageIdx: DWORD;
  WimName, MyTemp, pName, pDesc, aall, aa, bb, dd, cc, ns, ds, ErrCode: string;
  ImgInfoBuf, NewInfoBuf: PWideChar;
  pre: Integer;
begin
  InitWIMGAPI;

  WimName := 'd:\Project\sources\install.wim';
  ImageIdx := 1;
  MyTemp := 'd:\Project\Temp';
  pName := 'Windows 7 HOMEBASIC (x64)';
  pDesc := 'Windows 7 HOMEBASIC (x64) AllDrivers';

  // Open file
  WimHandle := WIMCreateFile(PWideChar(WimName), WIM_GENERIC_READ,
    WIM_OPEN_EXISTING, WIM_FLAG_SHARE_WRITE, WIM_COMPRESS_XPRESS, @Created);

  if WimHandle = 0 then
  begin
    ShowMessage('Error Open ' + IntToStr(GetLastError));
    Exit;
  end
  else
  begin
    // Set temp
    if (not WIMSetTemporaryPath(WimHandle, PWideChar(MyTemp))) then
    begin
      ShowMessage('Error set temp ' + IntToStr(GetLastError));
      Exit;
    end
    else
    begin
      // Load image
      ImageHandle := WIMLoadImage(WimHandle, ImageIdx);

      if ImageHandle = 0 then
      begin
        ShowMessage('Error load image ' + IntToStr(GetLastError));
        Exit;
      end
      else
      begin
        if (not WIMGetImageInformation(ImageHandle, @ImgInfoBuf, @pre)) then
        begin
          ShowMessage('Error get info ' + IntToStr(GetLastError));
          Exit;
        end
        else
        begin
          aall := ImgInfoBuf;
          Memo1.Lines.Clear;
          // Parsing
          bb := '<IMAGE INDEX="' + IntToStr(ImageIdx) + '">';
          aa := Copy(aall, 1, Pos(bb, aall) - 1);
          bb := '<NAME>';
          aa := Copy(aall, 1, Pos(bb, aall) - 1);
          bb := '<FLAGS>';
          cc := ' ' + Copy(aall, Pos(bb, aall), Length(aall));
          ns := '<NAME>' + pName + '</NAME>' + CR;
          ds := ' <DESCRIPTION>' + pDesc + '</DESCRIPTION>' + CR;
          aall := aa + ns + ds + cc;
          NewInfoBuf := PWideChar(aall);
          // if (not WIMGetImageInformation(ImageHandle, @ImgInfoBuf, @pre)) then
          if (not WIMSetImageInformation(ImageHandle, ImgInfoBuf, pre)) then
          begin
            ShowMessage('Error set info ' + IntToStr(GetLastError));
            Exit;
          end
          else
            Memo1.Lines.Add(aall);
        end;
      end;
    end;
  end;
  WIMCloseHandle(ImageHandle);
  WIMCloseHandle(WimHandle);
end;

Geändert von SlpLow (19. Nov 2013 um 04:58 Uhr)
  Mit Zitat antworten Zitat
SlpLow

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

AW: Hilfe beim Übersetzen von C zu Delphi

  Alt 19. Nov 2013, 07:07
Delphi-Quellcode:
function SysErrorMessageEx(ErrorCode: Longint): string;
var
  Len: Integer;
  Buffer: array [0 .. 4095] of char;
begin
  Len := FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM or
    FORMAT_MESSAGE_IGNORE_INSERTS, nil, ErrorCode, 0, Buffer,
    SizeOf(Buffer), nil);
  SetString(result, Buffer, Len);
  if (Len = 0) then
    result := Format('Code: ' + IntToStr(GetLastError) + ' - ' +
      SysErrorMessage(GetLastError), [SysErrorMessage(GetLastError)]);
  result := Format('Code: ' + IntToStr(GetLastError) + ' - ' +
    SysErrorMessage(GetLastError), [ErrorCode, result]);
end;

.....
NewInfoBuf := PWideChar(aall);
if (not WIMSetImageInformation(ImageHandle, NewInfoBuf, pre)) then
begin
  ErrCode:=SysErrorMessageEx(GetLastError);
  ShowMessage('Error set info ' + ErrCode);
  Exit;
end
  else....
Failed to parse the requested XML data!

Was mache ich hier falsch?

Geändert von SlpLow (19. Nov 2013 um 07:22 Uhr)
  Mit Zitat antworten Zitat
SlpLow

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

AW: Hilfe beim Übersetzen von C zu Delphi

  Alt 19. Nov 2013, 22:32
Windows was unable to parse the requested XML data!
  Mit Zitat antworten Zitat
Antwort Antwort

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 06:42 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz