GetResourceBuffer

HGLOBAL GetResourceBuffer(HMODULE hModule, WORD wResourceID, LPCTSTR lpType)
{
	HGLOBAL hRet = NULL;

	if (HRSRC hResInfo = FindResource(hModule, MAKEINTRESOURCE(wResourceID), lpType))
	{
		if (HGLOBAL hRes = LoadResource(hModule, hResInfo))
		{
			if (PVOID lpRes = LockResource(hRes))
			{
				if (hRet = GlobalAlloc(GMEM_FIXED, SizeofResource(hModule, hResInfo)))
				{
					CopyMemory(hRet, lpRes, GlobalSize(hRet));
				}
				UnlockResource(hRes);
			}
			FreeResource(hRes);
		}
	}
	return hRet;
}
ULONG_PTR GetResourceBuffer(HMODULE hModule, LPCTSTR lpType, WORD wResourceID, PVOID lpBuffer, ULONG_PTR nSize)
{
	ULONG_PTR cbOpt = 0;

	if (HRSRC hResInfo = FindResource(hModule, MAKEINTRESOURCE(wResourceID), lpType))
	{
		ULONG_PTR cbResource = SizeofResource(hModule, hResInfo);

		if (nSize >= cbResource)
		{
			if (HGLOBAL hRes = LoadResource(hModule, hResInfo))
			{
				if (PVOID lpRes = LockResource(hRes))
				{
					CopyMemory(lpBuffer, lpRes, cbResource);
					UnlockResource(hRes);
					cbOpt = cbResource;
				}
				FreeResource(hRes);
			}
		}
	}
	return cbOpt;
}


你可能感兴趣的:(GetResourceBuffer)