C++ 枚举资源

2021-03-12 06:28

阅读:659

标签:dde   str   manage   code   load   定义   max   ram   source   

// ResourceManager.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include 
#include 

#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++ 枚举资源

标签:dde   str   manage   code   load   定义   max   ram   source   

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


评论


亲,登录后才可以留言!