[USBSTOR]
[reactos.git] / rostests / apitests / user32 / CreateIconFromResourceEx.c
1
2 #include <apitest.h>
3
4 #include <winuser.h>
5 #include <wingdi.h>
6
7 START_TEST(CreateIconFromResourceEx)
8 {
9 HCURSOR hcur1, hcur2;
10 HMODULE hMod;
11 HRSRC hResource; // handle to FindResource
12 HRSRC hMem; // handle to LoadResource
13 BYTE *lpResource; // pointer to resource data
14 DWORD err;
15 int wResId;
16
17 hMod = GetModuleHandle(NULL);
18 ok(hMod != NULL, "\n");
19 /* Create a shared cursor */
20 hcur1 = LoadCursor(hMod, "TESTCURSOR");
21 ok(hcur1 != NULL, "\n");
22
23 /* Create it manually using CreateIconFromResourceEx */
24 hResource = FindResourceA(hMod,
25 "TESTCURSOR",
26 RT_GROUP_CURSOR);
27 ok(hResource != NULL, "\n");
28
29 hMem = LoadResource(hMod, hResource);
30 ok(hMem != NULL, "\n");
31
32 lpResource = LockResource(hMem);
33 ok(lpResource != NULL, "\n");
34
35 /* MSDN states that LR_SHARED permits to not load twice the same cursor again.
36 * But CreateIconFromResourceEx still returns two different handles */
37 hcur2 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), FALSE, 0x00030000, 0, 0, LR_SHARED);
38 ok(hcur2 != NULL, "\n");
39 ok(hcur2 != hcur1, "\n");
40 hcur1 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), FALSE, 0x00030000, 0, 0, LR_SHARED);
41 ok(hcur1 != NULL, "\n");
42 ok(hcur2 != hcur1, "\n");
43
44 /* Try to destroy them multiple times (see DestroyCursor test) */
45 ok(DestroyCursor(hcur1), "\n");
46 ok(DestroyCursor(hcur1), "\n");
47 ok(DestroyCursor(hcur2), "\n");
48 ok(DestroyCursor(hcur2), "\n");
49
50 /* See what happens if we ask for an icon on a cursor resource (directory) */
51 SetLastError(0x0badf00d);
52 hcur1 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), TRUE, 0x00030000, 0, 0, 0);
53 ok(hcur1 == NULL, "\n");
54 err = GetLastError();
55 ok(err == 0x0badf00d, "err: %lu\n", err);
56
57 /* Same tests, but for cursor resource (not directory) */
58 wResId = LookupIconIdFromDirectoryEx(lpResource, FALSE, 0, 0, 0);
59 ok(wResId != 0, "\n");
60 FreeResource(hResource);
61
62 hResource = FindResourceA(hMod, MAKEINTRESOURCEA(wResId), RT_CURSOR);
63 ok(hResource != NULL, "\n");
64
65 hMem = LoadResource(hMod, hResource);
66 ok(hMem != NULL, "\n");
67
68 lpResource = LockResource(hMem);
69 ok(lpResource != NULL, "\n");
70
71 /* MSDN states that LR_SHARED permits to not load twice the same cursor again.
72 * But CreateIconFromResourceEx still returns two different handles */
73 hcur2 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), FALSE, 0x00030000, 0, 0, LR_SHARED);
74 ok(hcur2 != NULL, "\n");
75 ok(hcur2 != hcur1, "\n");
76 hcur1 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), FALSE, 0x00030000, 0, 0, LR_SHARED);
77 ok(hcur1 != NULL, "\n");
78 ok(hcur2 != hcur1, "\n");
79
80 /* Try to destroy them multiple times (see DestroyCursor test) */
81 ok(DestroyCursor(hcur1), "\n");
82 ok(DestroyCursor(hcur1), "\n");
83 ok(DestroyCursor(hcur2), "\n");
84 ok(DestroyCursor(hcur2), "\n");
85
86 /* See what happens if we ask for an icon on a cursor resource (no directory) */
87 SetLastError(0x0badf00d);
88 hcur1 = CreateIconFromResourceEx(lpResource, SizeofResource(hMod, hResource), TRUE, 0x00030000, 0, 0, 0);
89 ok(hcur1 == NULL, "\n");
90 err = GetLastError();
91 ok(err == 0x0badf00d, "err: %lu\n", err);
92 }