码迷,mamicode.com
首页 > 编程语言 > 详细

C++ 枚举资源

时间:2020-12-10 10:50:22      阅读:5      评论:0      收藏:0      [点我收藏+]

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

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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!