更改版本資訊測試

來源:互聯網
上載者:User
// Test003.cpp : 定義應用程式的進入點。#include "stdafx.h"#include "Test003.h"#include <iostream>#include <fstream>#include <string>using namespace std;#define MAX_LOADSTRING 100 //此代碼模組中包含的函數的前向聲明:ATOMMyRegisterClass(HINSTANCE 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,                     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); //將記憶體地區中的內容放入字串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 )//字串迴圈{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 hRSrc = NULL;hRSrc = FindResource(hMod,(LPCTSTR)nID, lpszType);if(hRSrc == NULL){return 0;}HGLOBAL hGlobal = NULL;hGlobal = LoadResource(hMod, hRSrc);if(hGlobal == NULL){return 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;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.