ReactOS 0.4.15-dev-8131-g4988de4
CreateIconFromResourceEx.c File Reference
#include "precomp.h"
Include dependency graph for CreateIconFromResourceEx.c:

Go to the source code of this file.

Functions

 START_TEST (CreateIconFromResourceEx)
 

Function Documentation

◆ START_TEST()

START_TEST ( CreateIconFromResourceEx  )

Definition at line 4 of file CreateIconFromResourceEx.c.

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 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}
#define ok(value,...)
Definition: atltest.h:57
#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
#define err(...)
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GetModuleHandle
Definition: winbase.h:3827
HICON HCURSOR
Definition: windef.h:299
BOOL WINAPI DestroyCursor(_In_ HCURSOR)
Definition: cursoricon.c:2720
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:5812
#define LR_SHARED
Definition: winuser.h:1100
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
unsigned char BYTE
Definition: xxhash.c:193