| 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: Positive test the LoadLibrary API. |
| 10 | ** Call LoadLibrary to map a module into the calling |
| 11 | ** process address space(DLL file) |
| 12 | ** |
| 13 | ** |
| 14 | **============================================================*/ |
| 15 | #define UNICODE |
| 16 | #include <palsuite.h> |
| 17 | /* SHLEXT is defined only for Unix variants */ |
| 18 | |
| 19 | #if defined(SHLEXT) |
| 20 | #define ModuleName "librotor_pal"SHLEXT |
| 21 | #else |
| 22 | #define ModuleName "rotor_pal.dll" |
| 23 | #endif |
| 24 | |
| 25 | int __cdecl main(int argc, char *argv[]) |
| 26 | { |
| 27 | HMODULE ModuleHandle; |
| 28 | int err; |
| 29 | WCHAR *lpModuleName; |
| 30 | |
| 31 | /* Initialize the PAL environment */ |
| 32 | err = PAL_Initialize(argc, argv); |
| 33 | if(0 != err) |
| 34 | { |
| 35 | ExitProcess(FAIL); |
| 36 | } |
| 37 | |
| 38 | /* convert a normal string to a wide one */ |
| 39 | lpModuleName = convert(ModuleName); |
| 40 | |
| 41 | /* load a module */ |
| 42 | ModuleHandle = LoadLibrary(lpModuleName); |
| 43 | |
| 44 | /* free the memory */ |
| 45 | free(lpModuleName); |
| 46 | |
| 47 | if(!ModuleHandle) |
| 48 | { |
| 49 | Fail("Failed to call LoadLibrary API!\n" ); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | /* decrement the reference count of the loaded dll */ |
| 54 | err = FreeLibrary(ModuleHandle); |
| 55 | if(0 == err) |
| 56 | { |
| 57 | Fail("\nFailed to all FreeLibrary API!\n" ); |
| 58 | } |
| 59 | |
| 60 | PAL_Terminate(); |
| 61 | return PASS; |
| 62 | } |
| 63 | |