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;
    }
  • 相关阅读:
    SPOJ VJudge QTREE
    LCA 在线倍增法 求最近公共祖先
    Codevs 2370 小机房的树
    51Nod-1632-B君的连通
    51Nod--1100-斜率最大
    51Nod-1276-岛屿的数量
    51Nod-1270-数组的最大代价
    poj
    hihocoder Week136 -- 优化延迟
    poj-1035-Spell Checker
  • 原文地址:https://www.cnblogs.com/nanfei/p/14091364.html
Copyright © 2011-2022 走看看