zoukankan      html  css  js  c++  java
  • c++ 写入并读取资源文件

    // ResourceManager.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include <Windows.h>
    #include <atlconv.h>
    
    #define LANGUAGEID 1033
    
    HANDLE hUpdate;
    char currentPath[MAX_PATH];
    char deadCode[] = "0xDEADC0DE";
    unsigned int error = 0;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        USES_CONVERSION;
    
        GetCurrentDirectoryA(MAX_PATH, currentPath);
        lstrcatA(currentPath, "\stub.exe");
    
        
    
        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("CURRENT"), 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));
        HRSRC hRes = FindResourceExW(hFile, RT_STRING, TEXT("CURRENT"), LANGUAGEID);
        if(hRes)
        {
            char *charData = (char*)LockResource(LoadResource(hFile,hRes));
            printf("%s",charData);
        }
    
        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;
    }
  • 相关阅读:
    hive之external table创建
    hive之managed table创建
    Ubuntu下hadoop1.0.4安装过程
    hadoop相关Exception
    ASP.NET 数据访问类 SQLSERVER
    ASP.NET中Cookie编程的基础知识
    SourceForge上的好东西(.Net)
    ASP.NET生成高质量缩略图通用函数(c#代码)
    Sql Server实用操作小技巧集合
    分页SQL Server存储过程
  • 原文地址:https://www.cnblogs.com/nanfei/p/14090892.html
Copyright © 2011-2022 走看看