ReactOS 0.4.17-dev-1421-g4623072
CreateIconFromResourceEx.c
Go to the documentation of this file.
1
2#include "precomp.h"
3
5{
6 HCURSOR hcur1, hcur2;
7 HMODULE hMod;
8 HRSRC hResource; // handle to FindResource
9 HRSRC hMem; // handle to LoadResource
10 BYTE *lpResource; // pointer to resource data
11 DWORD err;
12 int wResId;
13
14 hMod = GetModuleHandle(NULL);
15 ok(hMod != NULL, "\n");
16 /* Create a shared cursor */
17 hcur1 = LoadCursor(hMod, "TESTCURSOR");
18 ok(hcur1 != NULL, "\n");
19
20 /* Create it manually using CreateIconFromResourceEx */
21 hResource = FindResourceA(hMod,
22 "TESTCURSOR",
24 ok(hResource != NULL, "\n");
25
26 hMem = LoadResource(hMod, hResource);
27 ok(hMem != NULL, "\n");
28
29 lpResource = LockResource(hMem);
30 ok(lpResource != NULL, "\n");
31
32 /* MSDN states that LR_SHARED permits to not load twice the same cursor again.
33 * But CreateIconFromResourceEx still returns two different handles.
34 * This is most likely because it has no HINSTANCE nor module path to look up. */
35 hcur2 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), FALSE, 0x00030000, 0, 0, LR_SHARED);
36 ok(hcur2 != NULL, "\n");
37 ok(hcur2 != hcur1, "\n");
38 hcur1 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), FALSE, 0x00030000, 0, 0, LR_SHARED);
39 ok(hcur1 != NULL, "\n");
40 ok(hcur2 != hcur1, "\n");
41
42 /* Try to destroy them multiple times (see DestroyCursor test) */
43 ok(DestroyCursor(hcur1), "\n");
44 ok(DestroyCursor(hcur1), "\n");
45 ok(DestroyCursor(hcur2), "\n");
46 ok(DestroyCursor(hcur2), "\n");
47
48 /* See what happens if we ask for an icon on a cursor resource (directory) */
49 SetLastError(0x0badf00d);
50 hcur1 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), TRUE, 0x00030000, 0, 0, 0);
51 ok(hcur1 == NULL, "\n");
52 err = GetLastError();
53 ok(err == 0x0badf00d, "err: %lu\n", err);
54
55 /* Same tests, but for cursor resource (not directory) */
56 wResId = LookupIconIdFromDirectoryEx(lpResource, FALSE, 0, 0, 0);
57 ok(wResId != 0, "\n");
58 FreeResource(hResource);
59
60 hResource = FindResourceA(hMod, MAKEINTRESOURCEA(wResId), RT_CURSOR);
61 ok(hResource != NULL, "\n");
62
63 hMem = LoadResource(hMod, hResource);
64 ok(hMem != NULL, "\n");
65
66 lpResource = LockResource(hMem);
67 ok(lpResource != NULL, "\n");
68
69 /* MSDN states that LR_SHARED permits to not load twice the same cursor again.
70 * But CreateIconFromResourceEx still returns two different handles */
71 hcur2 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), FALSE, 0x00030000, 0, 0, LR_SHARED);
72 ok(hcur2 != NULL, "\n");
73 ok(hcur2 != hcur1, "\n");
74 hcur1 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), FALSE, 0x00030000, 0, 0, LR_SHARED);
75 ok(hcur1 != NULL, "\n");
76 ok(hcur2 != hcur1, "\n");
77
78 /* Try to destroy them multiple times (see DestroyCursor test) */
79 ok(DestroyCursor(hcur1), "\n");
80 ok(DestroyCursor(hcur1), "\n");
81 ok(DestroyCursor(hcur2), "\n");
82 ok(DestroyCursor(hcur2), "\n");
83
84 /* See what happens if we ask for an icon on a cursor resource (no directory) */
85 SetLastError(0x0badf00d);
86 hcur1 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), TRUE, 0x00030000, 0, 0, 0);
87 ok(hcur1 == NULL, "\n");
88 err = GetLastError();
89 ok(err == 0x0badf00d, "err: %lu\n", err);
90}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define SetLastError(x)
Definition: compat.h:752
BOOL WINAPI FreeResource(HGLOBAL handle)
Definition: res.c:559
HRSRC WINAPI FindResourceA(HMODULE hModule, LPCSTR name, LPCSTR type)
Definition: res.c:155
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
unsigned long DWORD
Definition: ntddk_ex.h:95
#define RT_GROUP_CURSOR
Definition: pedump.c:374
#define RT_CURSOR
Definition: pedump.c:363
BOOL WINAPI DestroyCursor(_In_ HCURSOR)
Definition: cursoricon.c:3093
HICON WINAPI CreateIconFromResourceEx(_In_reads_bytes_(dwResSize) PBYTE presbits, _In_ DWORD dwResSize, _In_ BOOL fIcon, _In_ DWORD dwVer, _In_ int cxDesired, _In_ int cyDesired, _In_ UINT Flags)
int WINAPI LookupIconIdFromDirectoryEx(_In_reads_bytes_(sizeof(NEWHEADER)) PBYTE, _In_ BOOL, _In_ int, _In_ int, _In_ UINT)
#define LoadCursor
Definition: winuser.h:5978
#define LR_SHARED
Definition: winuser.h:1111
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
#define err(...)
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GetModuleHandle
Definition: winbase.h:3550
HICON HCURSOR
Definition: windef.h:99
unsigned char BYTE
Definition: xxhash.c:193