// Copyright (c) 2020 Lv Decai, Shenzhen, China.// Filename: ResourceUtility.cpp// Version: 1.0// Release date: 2020年10月11日// License: MIT (http://opensource.org/licenses/MIT)#include "StdAfx.h"#include "ResourceUtility.h"NAMESPACE_BEGIN;// ȡõǰģHMODULE GetModuleHandle(){PVOID pReturnAddress = NULL;PVOID pAddress = NULL;PVOID pBase = NULL;MEMORY_BASIC_INFORMATION mbi = { 0 };#ifndef _WIN64__asm{mov eax, [ebp + 4]mov pReturnAddress, eax}#endifwhile (TRUE){if (!VirtualQuery(pAddress, &mbi, sizeof(mbi)))break;if (pReturnAddress >= mbi.BaseAddress&& pReturnAddress < (char*) mbi.BaseAddress + mbi.RegionSize){pBase = mbi.AllocationBase;break;}pAddress = (PVOID) ((DWORD_PTR) mbi.BaseAddress + mbi.RegionSize);}return (HMODULE) pBase;}// Դstring ResourceUtility::LoadResource(HINSTANCE hInstance, PCTSTR sResourceType, int iResourceId){AFX_MANAGE_STATE(AfxGetStaticModuleState());// ԴHRSRC hrsrc = FindResource(hInstance, MAKEINTRESOURCE(iResourceId), sResourceType);if (hrsrc == NULL){return "";}// ȷԴСDWORD iLength = SizeofResource(hInstance, hrsrc);// ԴHGLOBAL hGlobal = ::LoadResource(hInstance, hrsrc);if (hGlobal == NULL){return "";}return string((char*) LockResource(hGlobal), iLength);}// ӵǰģԴstring ResourceUtility::LoadResource(PCTSTR sResourceType, int iResourceId){return LoadResource(GetModuleHandle(), sResourceType, iResourceId);}NAMESPACE_END;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。