6#include <winpr/tchar.h>
7#include <winpr/windows.h>
8#include <winpr/library.h>
11int TestLibraryLoadLibrary(
int argc,
char* argv[])
13 HINSTANCE library =
nullptr;
14 LPCSTR SharedLibraryExtension =
nullptr;
15 CHAR LibraryPath[MAX_PATH] = WINPR_C_ARRAY_INIT;
19 if (!GetModuleFileNameA(
nullptr, LibraryPath, ARRAYSIZE(LibraryPath)))
21 const UINT32 err = GetLastError();
22 const HRESULT herr = HRESULT_FROM_WIN32(err);
23 printf(
"%s: GetModuleFilenameA failed: %s - %s [0x%08" PRIX32
"]\n", __func__,
24 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
30 if (!(p = strrchr(LibraryPath, PathGetSeparatorA(PATH_STYLE_NATIVE))))
32 printf(
"%s: Error identifying module directory path\n", __func__);
37 if (FAILED(NativePathCchAppendA(LibraryPath, ARRAYSIZE(LibraryPath),
"TestLibraryA")))
39 SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
40 if (FAILED(NativePathCchAddExtensionA(LibraryPath, ARRAYSIZE(LibraryPath),
41 SharedLibraryExtension)))
44 printf(
"%s: Loading Library: '%s'\n", __func__, LibraryPath);
46 if (!(library = LoadLibraryA(LibraryPath)))
48 const UINT32 err = GetLastError();
49 const HRESULT herr = HRESULT_FROM_WIN32(err);
50 printf(
"%s: LoadLibraryA failure: %s - %s [0x%08" PRIX32
"]\n", __func__,
51 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
55 if (!FreeLibrary(library))
57 const UINT32 err = GetLastError();
58 const HRESULT herr = HRESULT_FROM_WIN32(err);
59 printf(
"%s: FreeLibrary failure: %s - %s [0x%08" PRIX32
"]\n", __func__, NtStatus2Tag(herr),
60 Win32ErrorCode2Tag(err), err);