宋
宋阳
Unregistered / Unconfirmed
GUEST, unregistred user!
在DELPHI中如何写入WIM镜像的名称及WIM镜像的描述<br>以下VC++的两个代码片断,在DELPHI如何实现写入WIM镜像的INFO?<br>片断1<br>void EditWIMFile(HANDLE hImg, int imgNum, LPWSTR pName, LPWSTR pDesc)<br>{<br> //Get the info and divide it into two strings<br> WCHAR *ImgInfoBuf, TempString[100];<br> DWORD ImgInfoBufSize;<br> WIMGetImageInformation(hImg, (LPVOID *)&ImgInfoBuf, &ImgInfoBufSize);<br> wsprintf(TempString, TEXT("<IMAGE INDEX=/"%d/">", imgNum); <br> WCHAR *StringPointer = wcsstr(ImgInfoBuf, TempString); <br> WCHAR *SecondString = wcsstr(++StringPointer, TEXT("<"); <br> SecondString[-1] = 0; //end the first string <br><br> //Copy the first string to a new buffer and add our extra info<br> WCHAR *NewInfoBuf = (WCHAR *)LocalAlloc(LPTR, ImgInfoBufSize + 200 * sizeof(WCHAR));<br> lstrcpy(NewInfoBuf, ImgInfoBuf);<br> if (*pName) {<br> wsprintf(TempString, TEXT(" <NAME>%s</NAME>/n ", pName);<br> lstrcat(NewInfoBuf, TempString); <br> }<br> if (*pDesc) {<br> if (*pName)<br> wsprintf(TempString, TEXT("<DESCRIPTION>%s</DESCRIPTION>/n ", pDesc);<br> else<br> wsprintf(TempString, TEXT(" <DESCRIPTION>%s</DESCRIPTION>/n ", pDesc);<br> lstrcat(NewInfoBuf, TempString); <br> }<br><br> //Add the second string to the new buffer and reset the info in the file<br> lstrcat(NewInfoBuf, SecondString);<br> WIMSetImageInformation(hImg, NewInfoBuf, wcslen(NewInfoBuf) * sizeof(WCHAR));<br><br> //Free the storage<br> LocalFree(ImgInfoBuf);<br> LocalFree(NewInfoBuf);<br>}<br>片断2<br>void __fastcall TMycallback::Aeditnewwimfile(HANDLE hImg, int imgNum, AnsiString pName, AnsiString pDesc)<br>{<br>AnsiString aall, aa, bb, cc, dd;<br>wchar_t *ImgInfoBuf, *NewInfoBuf;<br>DWORD ImgInfoBufSize;<br>int pre;<br><br>ImgInfoBuf = new wchar_t[20000];<br>WIMGetImageInformation(hImg, (LPVOID *)&ImgInfoBuf, &ImgInfoBufSize);<br>aall = String(WideCharToString(ImgInfoBuf));<br>bb = String("<IMAGE INDEX=/"" + String(imgNum) + "/">"<br>aa = String(aall.SubString(1, aall.Pos(bb) - 1)); <br>pre = aa.Length() + bb.Length(); <br>dd = String(aall.SubString(pre + 1, aall.Length() - pre)); <br><br>aall = String(aa) + String(bb);<br>aall += String("/n <NAME>" + pName + "</NAME>"<br>aall += String("/n <DESCRIPTION>" + pDesc + "</DESCRIPTION>"<br>aall += String(dd);<br><br>NewInfoBuf = new wchar_t[20000];<br>aall.WideChar(NewInfoBuf,aall.WideCharBufSize()); <br>WIMSetImageInformation(hImg, &NewInfoBuf, /*aall.Length()*/wcslen(NewInfoBuf) * sizeof(WCHAR));<br>}