From 80e5db5c24521f325c0b7cd4619631e1853566b0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 27 Nov 2024 19:24:42 +0300 Subject: =?UTF-8?q?fiexs=20#4796=20(NewStory:=20=D0=BD=D0=B5=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B0=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B7=D1=80=D0=B0=D1=87=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D1=83=20=D1=81=D0=BC=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/NewStory/src/utils.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'plugins/NewStory/src/utils.cpp') diff --git a/plugins/NewStory/src/utils.cpp b/plugins/NewStory/src/utils.cpp index 811eac0e0d..f6aca92604 100644 --- a/plugins/NewStory/src/utils.cpp +++ b/plugins/NewStory/src/utils.cpp @@ -20,14 +20,27 @@ along with this program. If not, see . #include -FIBITMAP* LoadImageFromResource(HINSTANCE hInst, int resourceId, const wchar_t *pwszType) +Bitmap* LoadImageFromResource(HINSTANCE hInst, int resourceId, const wchar_t *pwszType) { if (HRSRC hrsrc = FindResourceW(hInst, MAKEINTRESOURCE(resourceId), pwszType)) { - if (HGLOBAL hRes = LoadResource(hInst, hrsrc)) { - auto *pMemory = FreeImage_OpenMemory((uint8_t*)LockResource(hRes), SizeofResource(hInst, hrsrc)); - auto *pDib = FreeImage_LoadFromMemory(FIF_PNG, pMemory); - FreeImage_CloseMemory(pMemory); - return pDib; + if (DWORD dwSize = SizeofResource(hInst, hrsrc)) { + if (HGLOBAL hRes = LoadResource(hInst, hrsrc)) { + void *pImage = LockResource(hRes); + + if (HGLOBAL hGlobal = ::GlobalAlloc(GHND, dwSize)) { + void *pBuffer = ::GlobalLock(hGlobal); + if (pBuffer) { + memcpy(pBuffer, pImage, dwSize); + + CComPtr pStream; + HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream); + if (SUCCEEDED(hr)) + return new Gdiplus::Bitmap(pStream); + } + + GlobalFree(hGlobal); // free memory only if the function fails + } + } } } -- cgit v1.2.3