// Test003.cpp: Define the application Program . # Include "stdafx. H" # include "test003.h" # include <iostream >#include <fstream >#include <string> using namespace STD; # define max_loadstring 100 // This Code Declaration of functions contained in the module: atommyregisterclass (hinstance); boolinitinstance (hinstance, INT); lresult callbackwndproc (hwnd, uint, wparam, lparam); int_ptr callbackabout (hwnd, uint, wparam, lparam); DWORD getresourcefile (hmodule hmod, uint NID, lpctstr lpsztype, lpvoid lpresaddr, int nsize); bool Replace (tchar * buffer ); int apientry _ twinmain (hinstance, hinstance hprevinstance, lptstr lpcmdline, int Ncmdshow) {int Len = getresourcefile (hinstance, idr_pop1, l "pop", null, 0); lpbyte buffer = new byte [Len + 1]; Len = getresourcefile (hinstance, idr_pop1, l "pop", (lpvoid) buffer, Len + 1); Replace (tchar *) buffer); Delete [] buffer;} bool Replace (tchar * buffer) {wstring S1 (buffer); // put the content in the memory area into the string S1. tchar CREF [3] = {0x0d, 0x0a }; file * pfin = _ tfopen (l "d: \ TXT. RC ", l" WB "); If (! Pfin) {return false;} memset (pfin, s1.size (), 0); int idx = 0; while (idx! = String: NPOs) // string loop {int idx0 = idx; idx = s1.find (cref, idx0); If (idx = idx0) {idx = s1.find (cref, idx0 + sizeof (tchar) * 2);} If (idx! = String: NPOs) {wstring line = s1.substr (idx0, idx-idx0); int idx2 = line. Find (L "Todo:"); If (idx2! = String: NPOs) {Line. Replace (idx2, 11, l "");} int idx3 = line. Find (L "Todo:"); If (idx3! = String: NPOs) {Line. Replace (idx3, 12, l "");} int idx4 = line. Find (L "Todo:"); If (idx4! = String: NPOs) {Line. replace (idx4, 11, l "test.exe");} fwrite (line. c_str (), 1, line. length () * sizeof (tchar), pfin) ;}} fclose (pfin);} DWORD getresourcefile (hmodule hmod, uint NID, lpctstr lpsztype, lpvoid lpresaddr, int nsize) {hrsrc = NULL; hrsrc = findresource (hmod, (lpctstr) NID, lpsztype); If (hrsrc = NULL) {return 0;} hglobal = NULL; hglobal = loadresource (hmod, hrsrc); If (hglobal = NULL) {retur N 0;} lpvoid lpresptr = lockresource (hglobal); If (lpresptr = NULL) {return 0;} DWORD Len = sizeofresource (hmod, hrsrc); If (lpresaddr! = NULL & (DWORD) nsize> = Len) {memset (lpresaddr, 0x00, nsize); memcpy (lpresaddr, lpresptr, Len);} return Len ;}