diff options
Diffstat (limited to 'plugins/NewStory/src/utils.cpp')
-rw-r--r-- | plugins/NewStory/src/utils.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
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 <http://www.gnu.org/licenses/>. #include <msapi/comptr.h>
-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<IStream> pStream;
+ HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
+ if (SUCCEEDED(hr))
+ return new Gdiplus::Bitmap(pStream);
+ }
+
+ GlobalFree(hGlobal); // free memory only if the function fails
+ }
+ }
}
}
|