1 
2 #include "precomp.h"
3 
4 START_TEST(CreateIconFromResourceEx)
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",
23                             RT_GROUP_CURSOR);
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     hcur2 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), FALSE, 0x00030000, 0, 0, LR_SHARED);
35     ok(hcur2 != NULL, "\n");
36     ok(hcur2 != hcur1, "\n");
37     hcur1 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), FALSE, 0x00030000, 0, 0, LR_SHARED);
38     ok(hcur1 != NULL, "\n");
39     ok(hcur2 != hcur1, "\n");
40 
41     /* Try to destroy them multiple times (see DestroyCursor test) */
42     ok(DestroyCursor(hcur1), "\n");
43     ok(DestroyCursor(hcur1), "\n");
44     ok(DestroyCursor(hcur2), "\n");
45     ok(DestroyCursor(hcur2), "\n");
46 
47     /* See what happens if we ask for an icon on a cursor resource (directory) */
48     SetLastError(0x0badf00d);
49     hcur1 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), TRUE, 0x00030000, 0, 0, 0);
50     ok(hcur1 == NULL, "\n");
51     err = GetLastError();
52     ok(err == 0x0badf00d, "err: %lu\n", err);
53 
54     /* Same tests, but for cursor resource (not directory) */
55     wResId = LookupIconIdFromDirectoryEx(lpResource, FALSE, 0, 0, 0);
56     ok(wResId != 0, "\n");
57     FreeResource(hResource);
58 
59     hResource = FindResourceA(hMod, MAKEINTRESOURCEA(wResId), RT_CURSOR);
60     ok(hResource != NULL, "\n");
61 
62     hMem = LoadResource(hMod, hResource);
63     ok(hMem != NULL, "\n");
64 
65     lpResource = LockResource(hMem);
66     ok(lpResource != NULL, "\n");
67 
68     /* MSDN states that LR_SHARED permits to not load twice the same cursor again.
69      * But CreateIconFromResourceEx still returns two different handles */
70     hcur2 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), FALSE, 0x00030000, 0, 0, LR_SHARED);
71     ok(hcur2 != NULL, "\n");
72     ok(hcur2 != hcur1, "\n");
73     hcur1 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), FALSE, 0x00030000, 0, 0, LR_SHARED);
74     ok(hcur1 != NULL, "\n");
75     ok(hcur2 != hcur1, "\n");
76 
77     /* Try to destroy them multiple times (see DestroyCursor test) */
78     ok(DestroyCursor(hcur1), "\n");
79     ok(DestroyCursor(hcur1), "\n");
80     ok(DestroyCursor(hcur2), "\n");
81     ok(DestroyCursor(hcur2), "\n");
82 
83     /* See what happens if we ask for an icon on a cursor resource (no directory) */
84     SetLastError(0x0badf00d);
85     hcur1 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), TRUE, 0x00030000, 0, 0, 0);
86     ok(hcur1 == NULL, "\n");
87     err = GetLastError();
88     ok(err == 0x0badf00d, "err: %lu\n", err);
89 }
90