-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadpic.cpp
62 lines (49 loc) · 1.28 KB
/
loadpic.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "loadpic.h"
IPicture * LoadPic(LPCTSTR lpName, LPCTSTR lpType, HMODULE hInst)
{
HRSRC hResInfo;
HANDLE hRes;
LPSTR lpRes = NULL;
IPicture * m_pPicture = NULL;
// Find the resource
hResInfo = FindResource(hInst, lpName, lpType);
if (hResInfo == NULL)
return 0;
// Load the resource
hRes = LoadResource(hInst, hResInfo);
if (hRes == NULL)
return 0;
// Lock the resource
lpRes = (char*)LockResource(hRes);
if (lpRes != NULL)
{
int nSize = SizeofResource(hInst, hResInfo);
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, nSize);
void* pData = GlobalLock(hGlobal);
memcpy(pData, lpRes, nSize);
GlobalUnlock(hGlobal);
IStream* pStream = NULL;
if (CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) == S_OK)
{
if (OleLoadPicture(pStream, nSize, FALSE, IID_IPicture, (LPVOID *)&m_pPicture) != S_OK)
{
m_pPicture = NULL;
}
pStream->Release();
}
UnlockResource(hRes);
}
// Free the resource
FreeResource(hRes);
return m_pPicture;
}
HRESULT IPicture_getHandle(IPicture * pPicture, OLE_HANDLE * pHandle)
{
if (pPicture) return pPicture->get_Handle(pHandle);
return E_POINTER;
}
ULONG IPicture_Release(IPicture * pPicture)
{
if (pPicture) return pPicture->Release();
return 0;
}