首页 > 编程语言 > 详细

C++ 枚举资源

时间:2020-12-05 22:50:23      阅读:42      评论:0      收藏:0      [点我收藏+]
// 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;
}

 

C++ 枚举资源

原文:https://www.cnblogs.com/nanfei/p/14091364.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!