![]() |
Hilfe beim Übersetzen von C zu Delphi
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); } |
AW: Hilfe beim Übersetzen von C zu Delphi
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); } |
AW: Hilfe beim Übersetzen von C zu Delphi
Über die Suchfunktion kann man auch schon einige fertig übersetzte Delphi-Übersetzungen finden :zwinker:
z.B. ![]() ![]() ![]() |
AW: Hilfe beim Übersetzen von C zu Delphi
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; |
AW: Hilfe beim Übersetzen von C zu Delphi
Delphi-Quellcode:
Failed to parse the requested XML data!
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.... Was mache ich hier falsch? |
AW: Hilfe beim Übersetzen von C zu Delphi
Windows was unable to parse the requested XML data!
|
AW: Hilfe beim Übersetzen von C zu Delphi
Altough I personally find your text processing extremely difficult to understand, it produces perfectly valid XML output. At least on
![]() I bet your error hails from your 'pre' parameter. When you call
Delphi-Quellcode:
, you're storing the buffer size of the returned XML data. When later writing your modified data by
WIMGetImageInformation
Delphi-Quellcode:
, you're passing the exact same size. This cannot be right.
WIMSetImageInformation
![]() |
AW: Hilfe beim Übersetzen von C zu Delphi
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. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:21 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