//Windows Api
#include <windows.h>
//C Standard Library
#include <tchar.h>
//C++ Standard Library
#include <string>
typedef std::basic_string<TCHAR> tstring;
bool FsUpdataResource(const tstring& FilePath, const std::string& ResourceData, WORD wResourceID, LPCTSTR lpType)
{
?? ?bool bRte = false;
?? ?do
?? ?{
?? ??? ?HANDLE ?hResource = ::BeginUpdateResource(FilePath.c_str(), FALSE);
?? ??? ?if (!hResource) {
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?if (::UpdateResource(hResource, lpType, MAKEINTRESOURCE(wResourceID),
?? ??? ??? ?MAKELCID(MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_DEFAULT),
?? ??? ??? ?(LPVOID)ResourceData.c_str(), (DWORD)ResourceData.size()) == FALSE)
?? ??? ?{
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?if (::EndUpdateResource(hResource, FALSE) == FALSE) {
?? ??? ??? ?DWORD dw = GetLastError();
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?bRte = true;
?? ?} while (false);
?? ?return bRte;
}
int main()
{
?? ?tstring FilePath = _T("test.dll");
?? ?std::string ResourceData;
?? ?//ReadFile To ResourceData
?? ?//...
?? ?#define IDR_DLL1 152
?? ?//From resource.h
?? ?//...
?? ?if (FsUpdataResource(FilePath, ResourceData, IDR_DLL1, _T("DLL")))
?? ?{
?? ??? ?printf("FsUpdataResource Sucess\r\n");
?? ?}
?? ?system("pause");
? ? return 0;
}
|