Einzelnen Beitrag anzeigen

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