zoukankan      html  css  js  c++  java
  • C++ 枚举资源

    // ResourceManager.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include <Windows.h>
    #include <atlconv.h>
    
    #define LANGUAGEID 1033
    char deadCode[] = "0xDEADC0DE";
    unsigned int error = 0;
    
    BOOL EnumNames(HANDLE hModule, LPCTSTR lpType, LPTSTR lpName, LONG lParam)
    {
    
        return TRUE; 
    }
    
    BOOL EnumTypesFunc(HANDLE hModule, LPWSTR lpType, LONG lParam)
    {
          EnumResourceNames((HINSTANCE)hModule, 
            lpType, 
            (ENUMRESNAMEPROC)EnumNames, 
            lParam); 
    
        return TRUE; 
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        USES_CONVERSION;
    
        char currentPath[MAX_PATH];
        GetCurrentDirectoryA(MAX_PATH, currentPath);
        lstrcatA(currentPath, "\stub.exe");
    
        HANDLE 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("MYFILE"), 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));
    
        EnumResourceTypes(LoadLibrary(A2W(currentPath)),
            (ENUMRESTYPEPROC)EnumTypesFunc,
            NULL);//(LONG)&m_Infos);
    
        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;
    }
  • 相关阅读:
    [CC-STREETTA]The Street
    [CF115E]Linear Kingdom Races
    [洛谷P3987]我永远喜欢珂朵莉~
    [POI2012]Squarks
    [TC6194]AllWoundUp
    [CF434D]Nanami's Power Plant
    [CF126D]Fibonacci Sums/[BJOI2012]最多的方案
    [HZOI 2016]我们爱数数
    [COGS2427][HZOI 2016]seq
    Ynoi2018 天降之物
  • 原文地址:https://www.cnblogs.com/nanfei/p/14091364.html
Copyright © 2011-2022 走看看