这个是BC++的代码<br><br>那位大哥帮忙转化成Delphi的啊<br><br>bool UpdateResFromFile(char* filename, UINT resType, UINT resID, DWORD buffersize, char* destModule)<br>{<br> HANDLE hFile;<br> hFile = CreateFile(filename, <br> GENERIC_READ, // open for reading <br> FILE_SHARE_READ, // share for reading <br> NULL, // no security <br> OPEN_EXISTING, // existing file only <br> FILE_ATTRIBUTE_NORMAL, // normal file <br> NULL); // no attr. template <br><br> if (hFile == INVALID_HANDLE_VALUE) <br> { <br> cout<<"Could not open file."; <br> }<br><br> char* Data = new char[buffersize];<br> DWORD dwBytes;<br> BOOL result = ReadFile(hFile, (void*)Data, buffersize, &dwBytes, NULL);<br> CloseHandle(hFile);<br><br> HANDLE hUpdateRes;<br> hUpdateRes = BeginUpdateResource(destModule, FALSE); <br> if (hUpdateRes == NULL) <br> { <br> cout<<"Could not open file for writing."; <br> } <br><br> result = UpdateResource(hUpdateRes, // update resource handle <br> resType, <br> MAKEINTRESOURCE(resID), <br> MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), // neutral language<br> (void*)Data, // ptr to resource info <br> dwBytes); // size of resource info. <br> if (result == FALSE) <br> { <br> cout<<"Could not add resource."; <br> } <br><br> // Write changes to FOOT.EXE and then close it. <br> if (!EndUpdateResource(hUpdateRes, FALSE)) <br> { <br> cout<<"Could not write changes to file."; <br> } <br><br> delete Data;<br> return result;<br>}<br><br>// 用法, 如下是将外部的earth.bmp以200的ID号、RT_BITMAP的类型写入“foo.exe”<br>// 开的缓冲的大小为900000<br>ERRORCHECK(UpdateResFromFile("earth.bmp", RT_BITMAP, 200, 900000, "foo.exe"
);