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
Thema durchsuchen
Ansicht
Themen-Optionen

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.110 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
Online

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.130 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
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  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
Der schöne Günther

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

AW: Hilfe beim Übersetzen von C zu Delphi

  Alt 19. Nov 2013, 23:04
Altough I personally find your text processing extremely difficult to understand, it produces perfectly valid XML output. At least on some random WIM xml file I found on the interwebs.

I bet your error hails from your 'pre' parameter. When you call WIMGetImageInformation , you're storing the buffer size of the returned XML data. When later writing your modified data by WIMSetImageInformation , you're passing the exact same size. This cannot be right. According to MSDN, you'll have to pass the size (in Bytes) of your new xml block. I'm not sure if the trailing '\0' for termination is counted or not.
  Mit Zitat antworten Zitat
SlpLow

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

AW: Hilfe beim Übersetzen von C zu Delphi

  Alt 20. Nov 2013, 01:37
Danke! Ich gab ein beispiel aus VC++, um es elegant.
Die Frage war, indem PChar variablen - pName := PChar('Windows 7 HOMEBASIC (x64)').
Und entfernen CR (#13#10) gelöst.

Geändert von SlpLow (20. Nov 2013 um 01:47 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort


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 16:39 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