1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | /*============================================================= |
6 | ** |
7 | ** Source: loadlibraryw.c |
8 | ** |
9 | ** Purpose: Negative test the LoadLibraryW API. |
10 | ** Call LoadLibraryW with a not exist module Name |
11 | ** |
12 | ** |
13 | **============================================================*/ |
14 | #define UNICODE |
15 | #include <palsuite.h> |
16 | |
17 | int __cdecl main(int argc, char *argv[]) |
18 | { |
19 | HMODULE ModuleHandle; |
20 | int err; |
21 | WCHAR *pwModuleName; |
22 | const char *pModuleName = "Not-exist-module-name" ; |
23 | |
24 | /* Initialize the PAL environment */ |
25 | err = PAL_Initialize(argc, argv); |
26 | if(0 != err) |
27 | { |
28 | return FAIL; |
29 | } |
30 | |
31 | /* convert a normal string to a wide one */ |
32 | pwModuleName = convert((char *)pModuleName); |
33 | |
34 | |
35 | /*try to load a not exist module */ |
36 | ModuleHandle = LoadLibraryW(pwModuleName); |
37 | |
38 | /* free the memory */ |
39 | free(pwModuleName); |
40 | |
41 | if(NULL != ModuleHandle) |
42 | { |
43 | Trace("Failed to call LoadLibraryW with a not exist mudule name, " |
44 | "a NULL module handle is expected, but no NULL module handle " |
45 | "is returned, error code=%u\n" , GetLastError()); |
46 | |
47 | /* decrement the reference count of the loaded module */ |
48 | err = FreeLibrary(ModuleHandle); |
49 | if(0 == err) |
50 | { |
51 | Trace("\nFailed to all FreeLibrary API to decrement " |
52 | "the reference count of the loaded module, " |
53 | "error code = %u\n" , GetLastError()); |
54 | |
55 | } |
56 | |
57 | Fail("" ); |
58 | } |
59 | |
60 | PAL_Terminate(); |
61 | return PASS; |
62 | } |
63 | |