1 2 #include "precomp.h" 3 4 static void test_LoadImage_DataFile(void) 5 { 6 static const struct 7 { 8 int result; 9 LPCWSTR file; 10 int res_id; 11 UINT lr; 12 BOOL same_handle; 13 BOOL after_unload; /* LR_SHARED stays valid */ 14 } 15 tests[] = 16 { 17 { 1, L"shell32.dll", 2, 0, 0, 0 }, 18 { 1, L"shell32.dll", 2, LR_SHARED, 1, 1 }, 19 { 0, L"shell32.dll", 0xfff0, 0, 1, 0 }, /* Icon should not exist */ 20 { 1, L"regedit.exe", 100, 0, 0, 0 }, 21 { 1, L"regedit.exe", 100, LR_SHARED, 1, 1 } 22 }; 23 24 SIZE_T i; 25 for (i = 0; i < ARRAY_SIZE(tests); ++i) 26 { 27 HANDLE handle1, handle2; 28 HMODULE hMod = LoadLibraryExW(tests[i].file, NULL, LOAD_LIBRARY_AS_DATAFILE); 29 if (!((SIZE_T)hMod & 3)) 30 { 31 skip("Could not load library as datafile %ls\n", tests[i].file); 32 continue; 33 } 34 35 handle1 = LoadImage(hMod, MAKEINTRESOURCE(tests[i].res_id), IMAGE_ICON, 0, 0, tests[i].lr); 36 ok(!!handle1 == !!tests[i].result, "Failed to load %ls,-%d from %p\n", tests[i].file, tests[i].res_id, hMod); 37 38 handle2 = LoadImage(hMod, MAKEINTRESOURCE(tests[i].res_id), IMAGE_ICON, 0, 0, tests[i].lr); 39 ok(!!(handle1 == handle2) == !!tests[i].same_handle, "Shared handles don't match\n"); 40 41 FreeLibrary(hMod); 42 43 handle1 = LoadImage(hMod, MAKEINTRESOURCE(tests[i].res_id), IMAGE_ICON, 0, 0, tests[i].lr); 44 ok(!!handle1 == !!tests[i].after_unload, "LR_%x handle should %sload after FreeLibrary\n", tests[i].lr, tests[i].after_unload ? "" : "not "); 45 } 46 } 47 48 START_TEST(LoadImage) 49 { 50 char path[MAX_PATH]; 51 PROCESS_INFORMATION pi; 52 STARTUPINFO si; 53 HANDLE handle; 54 55 char **test_argv; 56 int argc = winetest_get_mainargs( &test_argv ); 57 58 /* Now check its behaviour regarding Shared icons/cursors */ 59 handle = LoadImageW( GetModuleHandle(NULL), L"TESTCURSOR", IMAGE_CURSOR, 0, 0, LR_SHARED | LR_DEFAULTSIZE ); 60 ok(handle != 0, "\n"); 61 62 if (argc >= 3) 63 { 64 HANDLE arg; 65 HICON hCopy; 66 HBITMAP hbmp; 67 HDC hdc, hdcScreen; 68 ICONINFO ii; 69 70 sscanf (test_argv[2], "%Iu", (ULONG_PTR*) &arg); 71 72 ok(handle != arg, "Got same handles\n"); 73 74 /* Try copying it */ 75 hCopy = CopyIcon(arg); 76 ok(hCopy != NULL, "\n"); 77 ok(DestroyIcon(hCopy), "\n"); 78 79 hCopy = CopyImage(arg, IMAGE_CURSOR, 0, 0, 0); 80 ok(hCopy != NULL, "\n"); 81 ok(DestroyIcon(hCopy), "\n"); 82 /* Unlike the original, this one is not shared */ 83 ok(!DestroyIcon(hCopy), "\n"); 84 85 hCopy = CopyImage(arg, IMAGE_CURSOR, 0, 0, LR_COPYFROMRESOURCE); 86 ok(hCopy != NULL, "\n"); 87 ok(DestroyIcon(hCopy), "\n"); 88 /* Unlike the original, this one is not shared */ 89 ok(!DestroyIcon(hCopy), "\n"); 90 91 hCopy = CopyImage(arg, IMAGE_CURSOR, 0, 0, LR_COPYFROMRESOURCE | LR_SHARED); 92 ok(hCopy != NULL, "\n"); 93 ok(DestroyIcon(hCopy), "\n"); 94 /* This one is shared */ 95 ok(DestroyIcon(hCopy), "\n"); 96 97 hCopy = CopyImage(arg, IMAGE_CURSOR, 0, 0, LR_SHARED); 98 ok(hCopy != NULL, "\n"); 99 ok(DestroyIcon(hCopy), "DestroyIcon should succeed.\n"); 100 /* This one is shared */ 101 ok(DestroyIcon(hCopy) == 0, "DestroyIcon should fail.\n"); 102 103 /* Try various usual functions */ 104 hdcScreen = CreateDCW(L"DISPLAY", NULL, NULL, NULL); 105 ok(hdcScreen != NULL, "\n"); 106 hdc = CreateCompatibleDC(hdcScreen); 107 ok(hdc != NULL, "\n"); 108 hbmp = CreateCompatibleBitmap(hdcScreen, 64, 64); 109 ok(hbmp != NULL, "\n"); 110 hbmp = SelectObject(hdc, hbmp); 111 ok(hbmp != NULL, "\n"); 112 113 ok(DrawIcon(hdc, 0, 0, arg), "\n"); 114 hbmp = SelectObject(hdc, hbmp); 115 DeleteObject(hbmp); 116 DeleteDC(hdc); 117 DeleteDC(hdcScreen); 118 119 ok(GetIconInfo(arg, &ii), "\n"); 120 ok(ii.hbmMask != NULL, "\n"); 121 DeleteObject(ii.hbmMask); 122 if(ii.hbmColor) DeleteObject(ii.hbmColor); 123 124 /* LOAD_LIBRARY_AS_DATAFILE */ 125 test_LoadImage_DataFile(); 126 127 return; 128 } 129 130 /* Start child process */ 131 sprintf( path, "%s LoadImage %Iu", test_argv[0], (ULONG_PTR)handle ); 132 memset( &si, 0, sizeof(si) ); 133 si.cb = sizeof(si); 134 CreateProcessA( NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi ); 135 WaitForSingleObject (pi.hProcess, INFINITE); 136 } 137