| 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 by passing a module name |
| 11 | ** without extension but with a trailing dot. |
| 12 | ** |
| 13 | ** |
| 14 | **============================================================*/ |
| 15 | #define UNICODE |
| 16 | #include <palsuite.h> |
| 17 | |
| 18 | int __cdecl main(int argc, char *argv[]) |
| 19 | { |
| 20 | HMODULE ModuleHandle; |
| 21 | int err; |
| 22 | WCHAR *lpModuleName; |
| 23 | char ModuleName[_MAX_FNAME]; |
| 24 | |
| 25 | /* Initialize the PAL environment */ |
| 26 | err = PAL_Initialize(argc, argv); |
| 27 | if(0 != err) |
| 28 | { |
| 29 | return FAIL; |
| 30 | } |
| 31 | |
| 32 | memset(ModuleName, 0, _MAX_FNAME); |
| 33 | |
| 34 | /*Module name without extension but with a trailing dot*/ |
| 35 | #if WIN32 |
| 36 | sprintf_s(ModuleName, _countof(ModuleName),"%s" ,"rotor_pal." ); |
| 37 | #else |
| 38 | sprintf_s(ModuleName, _countof(ModuleName),"%s" ,"librotor_pal." ); |
| 39 | #endif |
| 40 | |
| 41 | /* convert a normal string to a wide one */ |
| 42 | lpModuleName = convert(ModuleName); |
| 43 | |
| 44 | /* load a module */ |
| 45 | ModuleHandle = LoadLibraryW(lpModuleName); |
| 46 | |
| 47 | /* free the memory */ |
| 48 | free(lpModuleName); |
| 49 | |
| 50 | if(NULL != ModuleHandle) |
| 51 | { |
| 52 | Trace("Failed to call LoadLibraryW API for a negative test " |
| 53 | "call LoadLibraryW with module name which does not have " |
| 54 | "extension except a trailing dot, a NULL module handle is" |
| 55 | "expected, but no NULL module handle is returned, " |
| 56 | "error code = %u\n" , GetLastError()); |
| 57 | |
| 58 | /* decrement the reference count of the loaded dll */ |
| 59 | err = FreeLibrary(ModuleHandle); |
| 60 | if(0 == err) |
| 61 | { |
| 62 | Trace("\nFailed to call FreeLibrary API, " |
| 63 | "error code = %u\n" , GetLastError()); |
| 64 | } |
| 65 | |
| 66 | Fail("" ); |
| 67 | } |
| 68 | |
| 69 | PAL_Terminate(); |
| 70 | return PASS; |
| 71 | } |
| 72 | |