2 * Unit tests for module/DLL/library API
4 * Copyright (c) 2004 Eric Pouech
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/test.h"
24 static DWORD (WINAPI *pGetDllDirectoryA)(DWORD,LPSTR);
25 static DWORD (WINAPI *pGetDllDirectoryW)(DWORD,LPWSTR);
26 static BOOL (WINAPI *pSetDllDirectoryA)(LPCSTR);
27 static BOOL (WINAPI *pGetModuleHandleExA)(DWORD,LPCSTR,HMODULE*);
28 static BOOL (WINAPI *pGetModuleHandleExW)(DWORD,LPCWSTR,HMODULE*);
30 static BOOL is_unicode_enabled = TRUE;
32 static BOOL cmpStrAW(const char* a, const WCHAR* b, DWORD lenA, DWORD lenB)
36 DWORD len = MultiByteToWideChar( AreFileApisANSI() ? CP_ACP : CP_OEMCP, 0,
37 a, lenA, aw, sizeof(aw) / sizeof(aw[0]) );
38 if (len != lenB) return FALSE;
39 return memcmp(aw, b, len * sizeof(WCHAR)) == 0;
42 static void testGetModuleFileName(const char* name)
47 DWORD len1A, len1W = 0, len2A, len2W = 0;
49 hMod = (name) ? GetModuleHandle(name) : NULL;
51 /* first test, with enough space in buffer */
52 memset(bufA, '-', sizeof(bufA));
53 SetLastError(0xdeadbeef);
54 len1A = GetModuleFileNameA(hMod, bufA, sizeof(bufA));
55 ok(GetLastError() == ERROR_SUCCESS ||
56 broken(GetLastError() == 0xdeadbeef), /* <= XP SP3 */
57 "LastError was not reset: %u\n", GetLastError());
58 ok(len1A > 0, "Getting module filename for handle %p\n", hMod);
60 if (is_unicode_enabled)
62 memset(bufW, '-', sizeof(bufW));
63 SetLastError(0xdeadbeef);
64 len1W = GetModuleFileNameW(hMod, bufW, sizeof(bufW) / sizeof(WCHAR));
65 ok(GetLastError() == ERROR_SUCCESS ||
66 broken(GetLastError() == 0xdeadbeef), /* <= XP SP3 */
67 "LastError was not reset: %u\n", GetLastError());
68 ok(len1W > 0, "Getting module filename for handle %p\n", hMod);
71 ok(len1A == strlen(bufA), "Unexpected length of GetModuleFilenameA (%d/%d)\n", len1A, lstrlenA(bufA));
73 if (is_unicode_enabled)
75 ok(len1W == lstrlenW(bufW), "Unexpected length of GetModuleFilenameW (%d/%d)\n", len1W, lstrlenW(bufW));
76 ok(cmpStrAW(bufA, bufW, len1A, len1W), "Comparing GetModuleFilenameAW results\n");
79 /* second test with a buffer too small */
80 memset(bufA, '-', sizeof(bufA));
81 len2A = GetModuleFileNameA(hMod, bufA, len1A / 2);
82 ok(len2A > 0, "Getting module filename for handle %p\n", hMod);
84 if (is_unicode_enabled)
86 memset(bufW, '-', sizeof(bufW));
87 len2W = GetModuleFileNameW(hMod, bufW, len1W / 2);
88 ok(len2W > 0, "Getting module filename for handle %p\n", hMod);
89 ok(cmpStrAW(bufA, bufW, len2A, len2W), "Comparing GetModuleFilenameAW results with buffer too small\n" );
90 ok(len1W / 2 == len2W, "Correct length in GetModuleFilenameW with buffer too small (%d/%d)\n", len1W / 2, len2W);
93 ok(len1A / 2 == len2A ||
94 len1A / 2 == len2A + 1, /* Win9x */
95 "Correct length in GetModuleFilenameA with buffer too small (%d/%d)\n", len1A / 2, len2A);
98 static void testGetModuleFileName_Wrong(void)
101 WCHAR bufW[MAX_PATH];
103 /* test wrong handle */
104 if (is_unicode_enabled)
107 ok(GetModuleFileNameW((void*)0xffffffff, bufW, sizeof(bufW) / sizeof(WCHAR)) == 0, "Unexpected success in module handle\n");
108 ok(bufW[0] == '*', "When failing, buffer shouldn't be written to\n");
112 ok(GetModuleFileNameA((void*)0xffffffff, bufA, sizeof(bufA)) == 0, "Unexpected success in module handle\n");
114 bufA[0] == 0 /* Win9x */,
115 "When failing, buffer shouldn't be written to\n");
118 static void testLoadLibraryA(void)
120 HMODULE hModule, hModule1;
123 SetLastError(0xdeadbeef);
124 hModule = LoadLibraryA("kernel32.dll");
125 ok( hModule != NULL, "kernel32.dll should be loadable\n");
126 ok( GetLastError() == 0xdeadbeef, "GetLastError should be 0xdeadbeef but is %d\n", GetLastError());
128 fp = GetProcAddress(hModule, "CreateFileA");
129 ok( fp != NULL, "CreateFileA should be there\n");
130 ok( GetLastError() == 0xdeadbeef, "GetLastError should be 0xdeadbeef but is %d\n", GetLastError());
132 SetLastError(0xdeadbeef);
133 hModule1 = LoadLibraryA("kernel32 ");
134 /* Only winNT does this */
135 if (GetLastError() != ERROR_DLL_NOT_FOUND)
137 ok( hModule1 != NULL, "\"kernel32 \" should be loadable\n");
138 ok( GetLastError() == 0xdeadbeef, "GetLastError should be 0xdeadbeef but is %d\n", GetLastError());
139 ok( hModule == hModule1, "Loaded wrong module\n");
140 FreeLibrary(hModule1);
142 FreeLibrary(hModule);
145 static void testNestedLoadLibraryA(void)
147 static const char dllname[] = "shell32.dll";
148 char path1[MAX_PATH], path2[MAX_PATH];
149 HMODULE hModule1, hModule2, hModule3;
151 /* This is not really a Windows conformance test, but more a Wine
152 * regression test. Wine's builtin dlls can be loaded from multiple paths,
153 * and this test tries to make sure that Wine does not get confused and
154 * really unloads the Unix .so file at the right time. Failure to do so
155 * will result in the dll being unloadable.
156 * This test must be done with a dll that can be unloaded, which means:
157 * - it must not already be loaded
158 * - it must not have a 16-bit counterpart
160 GetWindowsDirectory(path1, sizeof(path1));
161 strcat(path1, "\\system\\");
162 strcat(path1, dllname);
163 hModule1 = LoadLibraryA(path1);
166 /* We must be on Windows NT, so we cannot test */
170 GetWindowsDirectory(path2, sizeof(path2));
171 strcat(path2, "\\system32\\");
172 strcat(path2, dllname);
173 hModule2 = LoadLibraryA(path2);
176 /* We must be on Windows 9x, so we cannot test */
177 ok(FreeLibrary(hModule1), "FreeLibrary() failed\n");
181 /* The first LoadLibrary() call may have registered the dll under the
182 * system32 path. So load it, again, under the '...\system\...' path so
183 * Wine does not immediately notice that it is already loaded.
185 hModule3 = LoadLibraryA(path1);
186 ok(hModule3 != NULL, "LoadLibrary(%s) failed\n", path1);
188 /* Now fully unload the dll */
189 ok(FreeLibrary(hModule3), "FreeLibrary() failed\n");
190 ok(FreeLibrary(hModule2), "FreeLibrary() failed\n");
191 ok(FreeLibrary(hModule1), "FreeLibrary() failed\n");
192 ok(GetModuleHandle(dllname) == NULL, "%s was not fully unloaded\n", dllname);
194 /* Try to load the dll again, if refcounting is ok, this should work */
195 hModule1 = LoadLibraryA(path1);
196 ok(hModule1 != NULL, "LoadLibrary(%s) failed\n", path1);
197 if (hModule1 != NULL)
198 ok(FreeLibrary(hModule1), "FreeLibrary() failed\n");
201 static void testLoadLibraryA_Wrong(void)
205 /* Try to load a nonexistent dll */
206 SetLastError(0xdeadbeef);
207 hModule = LoadLibraryA("non_ex_pv.dll");
208 ok( !hModule, "non_ex_pv.dll should be not loadable\n");
209 ok( GetLastError() == ERROR_MOD_NOT_FOUND || GetLastError() == ERROR_DLL_NOT_FOUND,
210 "Expected ERROR_MOD_NOT_FOUND or ERROR_DLL_NOT_FOUND (win9x), got %d\n", GetLastError());
213 FreeLibrary(hModule);
216 static void testGetProcAddress_Wrong(void)
220 SetLastError(0xdeadbeef);
221 fp = GetProcAddress(NULL, "non_ex_call");
222 ok( !fp, "non_ex_call should not be found\n");
223 ok( GetLastError() == ERROR_PROC_NOT_FOUND || GetLastError() == ERROR_INVALID_HANDLE,
224 "Expected ERROR_PROC_NOT_FOUND or ERROR_INVALID_HANDLE(win9x), got %d\n", GetLastError());
226 SetLastError(0xdeadbeef);
227 fp = GetProcAddress((HMODULE)0xdeadbeef, "non_ex_call");
228 ok( !fp, "non_ex_call should not be found\n");
229 ok( GetLastError() == ERROR_MOD_NOT_FOUND || GetLastError() == ERROR_INVALID_HANDLE,
230 "Expected ERROR_MOD_NOT_FOUND or ERROR_INVALID_HANDLE(win9x), got %d\n", GetLastError());
233 static void testLoadLibraryEx(void)
240 hfile = CreateFileA("testfile.dll", GENERIC_READ | GENERIC_WRITE,
241 FILE_SHARE_READ | FILE_SHARE_WRITE,
242 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
243 ok(hfile != INVALID_HANDLE_VALUE, "Expected a valid file handle\n");
245 /* NULL lpFileName */
246 if (is_unicode_enabled)
248 SetLastError(0xdeadbeef);
249 hmodule = LoadLibraryExA(NULL, NULL, 0);
250 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
251 ok(GetLastError() == ERROR_MOD_NOT_FOUND ||
252 GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */
253 "Expected ERROR_MOD_NOT_FOUND or ERROR_INVALID_PARAMETER, got %d\n",
257 win_skip("NULL filename crashes on WinMe\n");
259 /* empty lpFileName */
260 SetLastError(0xdeadbeef);
261 hmodule = LoadLibraryExA("", NULL, 0);
262 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
263 ok(GetLastError() == ERROR_MOD_NOT_FOUND ||
264 GetLastError() == ERROR_DLL_NOT_FOUND, /* win9x */
265 "Expected ERROR_MOD_NOT_FOUND or ERROR_DLL_NOT_FOUND, got %d\n",
268 /* hFile is non-NULL */
269 SetLastError(0xdeadbeef);
270 hmodule = LoadLibraryExA("testfile.dll", hfile, 0);
271 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
274 ok(GetLastError() == ERROR_SHARING_VIOLATION ||
275 GetLastError() == ERROR_INVALID_PARAMETER || /* win2k3 */
276 GetLastError() == ERROR_FILE_NOT_FOUND, /* win9x */
277 "Unexpected last error, got %d\n", GetLastError());
280 SetLastError(0xdeadbeef);
281 hmodule = LoadLibraryExA("testfile.dll", (HANDLE)0xdeadbeef, 0);
282 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
285 ok(GetLastError() == ERROR_SHARING_VIOLATION ||
286 GetLastError() == ERROR_INVALID_PARAMETER || /* win2k3 */
287 GetLastError() == ERROR_FILE_NOT_FOUND, /* win9x */
288 "Unexpected last error, got %d\n", GetLastError());
291 /* try to open a file that is locked */
292 SetLastError(0xdeadbeef);
293 hmodule = LoadLibraryExA("testfile.dll", NULL, 0);
294 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
297 ok(GetLastError() == ERROR_SHARING_VIOLATION ||
298 GetLastError() == ERROR_FILE_NOT_FOUND, /* win9x */
299 "Expected ERROR_SHARING_VIOLATION or ERROR_FILE_NOT_FOUND, got %d\n",
303 /* lpFileName does not matter */
304 if (is_unicode_enabled)
306 SetLastError(0xdeadbeef);
307 hmodule = LoadLibraryExA(NULL, hfile, 0);
308 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
309 ok(GetLastError() == ERROR_MOD_NOT_FOUND ||
310 GetLastError() == ERROR_INVALID_PARAMETER, /* win2k3 */
311 "Expected ERROR_MOD_NOT_FOUND or ERROR_INVALID_PARAMETER, got %d\n",
317 /* load empty file */
318 SetLastError(0xdeadbeef);
319 hmodule = LoadLibraryExA("testfile.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
320 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
323 ok(GetLastError() == ERROR_FILE_INVALID ||
324 GetLastError() == ERROR_BAD_FORMAT, /* win9x */
325 "Expected ERROR_FILE_INVALID or ERROR_BAD_FORMAT, got %d\n",
329 DeleteFileA("testfile.dll");
331 GetSystemDirectoryA(path, MAX_PATH);
332 if (path[lstrlenA(path) - 1] != '\\')
333 lstrcatA(path, "\\");
334 lstrcatA(path, "kernel32.dll");
336 /* load kernel32.dll with an absolute path */
337 SetLastError(0xdeadbeef);
338 hmodule = LoadLibraryExA(path, NULL, LOAD_LIBRARY_AS_DATAFILE);
339 ok(hmodule != 0, "Expected valid module handle\n");
340 ok(GetLastError() == 0xdeadbeef ||
341 GetLastError() == ERROR_SUCCESS, /* win9x */
342 "Expected 0xdeadbeef or ERROR_SUCCESS, got %d\n", GetLastError());
344 /* try invalid file handle */
345 SetLastError(0xdeadbeef);
346 hmodule = LoadLibraryExA(path, (HANDLE)0xdeadbeef, 0);
347 if (!hmodule) /* succeeds on xp and older */
348 ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
350 CloseHandle(hmodule);
352 /* load kernel32.dll with no path */
353 SetLastError(0xdeadbeef);
354 hmodule = LoadLibraryExA("kernel32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
355 ok(hmodule != 0, "Expected valid module handle\n");
356 ok(GetLastError() == 0xdeadbeef ||
357 GetLastError() == ERROR_SUCCESS, /* win9x */
358 "Expected 0xdeadbeef or ERROR_SUCCESS, got %d\n", GetLastError());
360 CloseHandle(hmodule);
362 GetCurrentDirectoryA(MAX_PATH, path);
363 if (path[lstrlenA(path) - 1] != '\\')
364 lstrcatA(path, "\\");
365 lstrcatA(path, "kernel32.dll");
367 /* load kernel32.dll with an absolute path that does not exist */
368 SetLastError(0xdeadbeef);
369 hmodule = LoadLibraryExA(path, NULL, LOAD_LIBRARY_AS_DATAFILE);
372 ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
374 ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
375 broken(GetLastError() == ERROR_INVALID_HANDLE), /* nt4 */
376 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
378 /* Free the loaded dll when its the first time this dll is loaded
379 in process - First time should pass, second fail */
380 SetLastError(0xdeadbeef);
381 hmodule = LoadLibraryExA("comctl32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
382 ok(hmodule != 0, "Expected valid module handle\n");
384 SetLastError(0xdeadbeef);
385 ret = FreeLibrary(hmodule);
386 ok(ret, "Expected to be able to free the module, failed with %d\n", GetLastError());
387 SetLastError(0xdeadbeef);
388 ret = FreeLibrary(hmodule);
389 ok(!ret, "Unexpected ability to free the module, failed with %d\n", GetLastError());
391 CloseHandle(hmodule);
395 static void testGetDllDirectory(void)
397 CHAR bufferA[MAX_PATH];
398 WCHAR bufferW[MAX_PATH];
401 static const char *dll_directories[] =
406 "Q:\\A\\Long\\Path with spaces that\\probably\\doesn't exist!",
408 const int test_count = sizeof(dll_directories) / sizeof(dll_directories[0]);
410 if (!pGetDllDirectoryA || !pGetDllDirectoryW)
412 win_skip("GetDllDirectory not available\n");
415 if (!pSetDllDirectoryA)
417 win_skip("SetDllDirectoryA not available\n");
421 for (i = 0; i < test_count; i++)
423 length = strlen(dll_directories[i]);
424 if (!pSetDllDirectoryA(dll_directories[i]))
426 skip("i=%d, SetDllDirectoryA failed\n", i);
430 /* no buffer, determine length */
431 ret = pGetDllDirectoryA(0, NULL);
432 ok(ret == length + 1, "Expected %u, got %u\n", length + 1, ret);
434 ret = pGetDllDirectoryW(0, NULL);
435 ok(ret == length + 1, "Expected %u, got %u\n", length + 1, ret);
437 /* buffer of exactly the right size */
438 bufferA[length] = 'A';
439 bufferA[length + 1] = 'A';
440 ret = pGetDllDirectoryA(length + 1, bufferA);
441 ok(ret == length, "i=%d, Expected %u, got %u\n", i, length, ret);
442 ok(bufferA[length + 1] == 'A', "i=%d, Buffer overflow\n", i);
443 ok(strcmp(bufferA, dll_directories[i]) == 0, "i=%d, Wrong path returned: '%s'\n", i, bufferA);
445 bufferW[length] = 'A';
446 bufferW[length + 1] = 'A';
447 ret = pGetDllDirectoryW(length + 1, bufferW);
448 ok(ret == length, "i=%d, Expected %u, got %u\n", i, length, ret);
449 ok(bufferW[length + 1] == 'A', "i=%d, Buffer overflow\n", i);
450 ok(cmpStrAW(dll_directories[i], bufferW, length, length),
451 "i=%d, Wrong path returned: %s\n", i, wine_dbgstr_w(bufferW));
454 * the A version always null-terminates the buffer,
455 * the W version doesn't do it on some platforms */
457 ret = pGetDllDirectoryA(0, bufferA);
458 ok(ret == length + 1, "i=%d, Expected %u, got %u\n", i, length + 1, ret);
459 ok(bufferA[0] == 0, "i=%d, Buffer not null terminated\n", i);
462 ret = pGetDllDirectoryW(0, bufferW);
463 ok(ret == length + 1, "i=%d, Expected %u, got %u\n", i, length + 1, ret);
464 ok(bufferW[0] == 0 || /* XP, 2003 */
465 broken(bufferW[0] == 'A'), "i=%d, Buffer overflow\n", i);
467 /* buffer just one too short */
469 ret = pGetDllDirectoryA(length, bufferA);
470 ok(ret == length + 1, "i=%d, Expected %u, got %u\n", i, length + 1, ret);
471 ok(bufferA[0] == 0, "i=%d, Buffer not null terminated\n", i);
474 ret = pGetDllDirectoryW(length, bufferW);
475 ok(ret == length + 1, "i=%d, Expected %u, got %u\n", i, length + 1, ret);
476 ok(bufferW[0] == 0 || /* XP, 2003 */
477 broken(bufferW[0] == 'A'), "i=%d, Buffer overflow\n", i);
481 /* crashes on win8 */
482 /* no buffer, but too short length */
483 ret = pGetDllDirectoryA(length, NULL);
484 ok(ret == length + 1, "i=%d, Expected %u, got %u\n", i, length + 1, ret);
486 ret = pGetDllDirectoryW(length, NULL);
487 ok(ret == length + 1, "i=%d, Expected %u, got %u\n", i, length + 1, ret);
491 /* unset whatever we did so following tests won't be affected */
492 pSetDllDirectoryA(NULL);
495 static void init_pointers(void)
497 HMODULE hKernel32 = GetModuleHandleA("kernel32.dll");
499 #define MAKEFUNC(f) (p##f = (void*)GetProcAddress(hKernel32, #f))
500 MAKEFUNC(GetDllDirectoryA);
501 MAKEFUNC(GetDllDirectoryW);
502 MAKEFUNC(SetDllDirectoryA);
503 MAKEFUNC(GetModuleHandleExA);
504 MAKEFUNC(GetModuleHandleExW);
508 static void testGetModuleHandleEx(void)
510 static const WCHAR kernel32W[] = {'k','e','r','n','e','l','3','2',0};
511 static const WCHAR nosuchmodW[] = {'n','o','s','u','c','h','m','o','d',0};
514 HMODULE mod, mod_kernel32;
516 if (!pGetModuleHandleExA || !pGetModuleHandleExW)
518 win_skip( "GetModuleHandleEx not available\n" );
522 SetLastError( 0xdeadbeef );
523 ret = pGetModuleHandleExA( 0, NULL, NULL );
524 error = GetLastError();
525 ok( !ret, "unexpected success\n" );
526 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
528 SetLastError( 0xdeadbeef );
529 ret = pGetModuleHandleExA( 0, "kernel32", NULL );
530 error = GetLastError();
531 ok( !ret, "unexpected success\n" );
532 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
534 SetLastError( 0xdeadbeef );
535 mod = (HMODULE)0xdeadbeef;
536 ret = pGetModuleHandleExA( 0, "kernel32", &mod );
537 ok( ret, "unexpected failure %u\n", GetLastError() );
538 ok( mod != (HMODULE)0xdeadbeef, "got %p\n", mod );
541 SetLastError( 0xdeadbeef );
542 mod = (HMODULE)0xdeadbeef;
543 ret = pGetModuleHandleExA( 0, "nosuchmod", &mod );
544 error = GetLastError();
545 ok( !ret, "unexpected success\n" );
546 ok( error == ERROR_MOD_NOT_FOUND, "got %u\n", error );
547 ok( mod == NULL, "got %p\n", mod );
549 SetLastError( 0xdeadbeef );
550 ret = pGetModuleHandleExW( 0, NULL, NULL );
551 error = GetLastError();
552 ok( !ret, "unexpected success\n" );
553 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
555 SetLastError( 0xdeadbeef );
556 ret = pGetModuleHandleExW( 0, kernel32W, NULL );
557 error = GetLastError();
558 ok( !ret, "unexpected success\n" );
559 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
561 SetLastError( 0xdeadbeef );
562 mod = (HMODULE)0xdeadbeef;
563 ret = pGetModuleHandleExW( 0, kernel32W, &mod );
564 ok( ret, "unexpected failure %u\n", GetLastError() );
565 ok( mod != (HMODULE)0xdeadbeef, "got %p\n", mod );
568 SetLastError( 0xdeadbeef );
569 mod = (HMODULE)0xdeadbeef;
570 ret = pGetModuleHandleExW( 0, nosuchmodW, &mod );
571 error = GetLastError();
572 ok( !ret, "unexpected success\n" );
573 ok( error == ERROR_MOD_NOT_FOUND, "got %u\n", error );
574 ok( mod == NULL, "got %p\n", mod );
576 SetLastError( 0xdeadbeef );
577 ret = pGetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, NULL, NULL );
578 error = GetLastError();
579 ok( !ret, "unexpected success\n" );
580 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
582 SetLastError( 0xdeadbeef );
583 ret = pGetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, "kernel32", NULL );
584 error = GetLastError();
585 ok( !ret, "unexpected success\n" );
586 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
588 SetLastError( 0xdeadbeef );
589 mod = (HMODULE)0xdeadbeef;
590 ret = pGetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, "kernel32", &mod );
591 ok( ret, "unexpected failure %u\n", GetLastError() );
592 ok( mod != (HMODULE)0xdeadbeef, "got %p\n", mod );
594 SetLastError( 0xdeadbeef );
595 mod = (HMODULE)0xdeadbeef;
596 ret = pGetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, "nosuchmod", &mod );
597 error = GetLastError();
598 ok( !ret, "unexpected success\n" );
599 ok( error == ERROR_MOD_NOT_FOUND, "got %u\n", error );
600 ok( mod == NULL, "got %p\n", mod );
602 SetLastError( 0xdeadbeef );
603 ret = pGetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, NULL, NULL );
604 error = GetLastError();
605 ok( !ret, "unexpected success\n" );
606 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
608 SetLastError( 0xdeadbeef );
609 ret = pGetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, kernel32W, NULL );
610 error = GetLastError();
611 ok( !ret, "unexpected success\n" );
612 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
614 SetLastError( 0xdeadbeef );
615 mod = (HMODULE)0xdeadbeef;
616 ret = pGetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, kernel32W, &mod );
617 ok( ret, "unexpected failure %u\n", GetLastError() );
618 ok( mod != (HMODULE)0xdeadbeef, "got %p\n", mod );
620 SetLastError( 0xdeadbeef );
621 mod = (HMODULE)0xdeadbeef;
622 ret = pGetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, nosuchmodW, &mod );
623 error = GetLastError();
624 ok( !ret, "unexpected success\n" );
625 ok( error == ERROR_MOD_NOT_FOUND, "got %u\n", error );
626 ok( mod == NULL, "got %p\n", mod );
628 mod_kernel32 = LoadLibraryA( "kernel32" );
630 SetLastError( 0xdeadbeef );
631 ret = pGetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, NULL, NULL );
632 error = GetLastError();
633 ok( !ret, "unexpected success\n" );
634 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
636 SetLastError( 0xdeadbeef );
637 ret = pGetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCSTR)mod_kernel32, NULL );
638 error = GetLastError();
639 ok( !ret, "unexpected success\n" );
640 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
642 SetLastError( 0xdeadbeef );
643 mod = (HMODULE)0xdeadbeef;
644 ret = pGetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCSTR)mod_kernel32, &mod );
645 ok( ret, "unexpected failure %u\n", GetLastError() );
646 ok( mod == mod_kernel32, "got %p\n", mod );
649 SetLastError( 0xdeadbeef );
650 mod = (HMODULE)0xdeadbeef;
651 ret = pGetModuleHandleExA( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCSTR)0xbeefdead, &mod );
652 error = GetLastError();
653 ok( !ret, "unexpected success\n" );
654 ok( error == ERROR_MOD_NOT_FOUND, "got %u\n", error );
655 ok( mod == NULL, "got %p\n", mod );
657 SetLastError( 0xdeadbeef );
658 ret = pGetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, NULL, NULL );
659 error = GetLastError();
660 ok( !ret, "unexpected success\n" );
661 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
663 SetLastError( 0xdeadbeef );
664 ret = pGetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)mod_kernel32, NULL );
665 error = GetLastError();
666 ok( !ret, "unexpected success\n" );
667 ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error );
669 SetLastError( 0xdeadbeef );
670 mod = (HMODULE)0xdeadbeef;
671 ret = pGetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)mod_kernel32, &mod );
672 ok( ret, "unexpected failure %u\n", GetLastError() );
673 ok( mod == mod_kernel32, "got %p\n", mod );
676 SetLastError( 0xdeadbeef );
677 mod = (HMODULE)0xdeadbeef;
678 ret = pGetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)0xbeefdead, &mod );
679 error = GetLastError();
680 ok( !ret, "unexpected success\n" );
681 ok( error == ERROR_MOD_NOT_FOUND, "got %u\n", error );
682 ok( mod == NULL, "got %p\n", mod );
684 FreeLibrary( mod_kernel32 );
689 WCHAR filenameW[MAX_PATH];
691 /* Test if we can use GetModuleFileNameW */
693 SetLastError(0xdeadbeef);
694 GetModuleFileNameW(NULL, filenameW, MAX_PATH);
695 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
697 win_skip("GetModuleFileNameW not existing on this platform, skipping W-calls\n");
698 is_unicode_enabled = FALSE;
703 testGetModuleFileName(NULL);
704 testGetModuleFileName("kernel32.dll");
705 testGetModuleFileName_Wrong();
707 testGetDllDirectory();
710 testNestedLoadLibraryA();
711 testLoadLibraryA_Wrong();
712 testGetProcAddress_Wrong();
714 testGetModuleHandleEx();