c++ 寫入並讀取資原始檔
阿新 • • 發佈:2020-12-05
// ResourceManager.cpp : 定義控制檯應用程式的入口點。 // #include "stdafx.h" #include <Windows.h> #include <atlconv.h> #define LANGUAGEID 1033 HANDLE hUpdate; char currentPath[MAX_PATH]; char deadCode[] = "0xDEADC0DE"; unsigned int error = 0; int _tmain(int argc, _TCHAR* argv[]) { USES_CONVERSION; GetCurrentDirectoryA(MAX_PATH, currentPath); lstrcatA(currentPath,"\\stub.exe"); hUpdate = BeginUpdateResourceW(A2W(currentPath), FALSE); if(hUpdate == NULL) { MessageBox(0, L"BeginUpdateResource failed.", 0, MB_OK+MB_ICONERROR); error = 1; } if(UpdateResourceW(hUpdate, RT_STRING, TEXT("CURRENT"), LANGUAGEID, &deadCode, 11) == FALSE) { MessageBox(0, L"UpdateResource failed.", 0, MB_OK+MB_ICONERROR); error = 1; } if(EndUpdateResourceW(hUpdate, FALSE) == FALSE) { MessageBox(0, L"EndUpdateResource failed.", 0, MB_OK+MB_ICONERROR); error = 1; } HMODULE hFile = LoadLibrary(A2W(currentPath)); HRSRC hRes= FindResourceExW(hFile, RT_STRING, TEXT("CURRENT"), LANGUAGEID); if(hRes) { char *charData = (char*)LockResource(LoadResource(hFile,hRes)); printf("%s",charData); } if(error == 0) { MessageBox(0, L"stub.exe - Resource added.", L"Info", 0); return EXIT_SUCCESS; } else { MessageBox(0, L"stub.exe - Adding resource failed.", L"Info", 0); return EXIT_FAILURE; } return 0; }