5#include <winpr/tchar.h>
6#include <winpr/windows.h>
7#include <winpr/library.h>
10int TestLibraryLoadLibrary(
int argc,
char* argv[])
12 HINSTANCE library =
nullptr;
13 LPCSTR SharedLibraryExtension =
nullptr;
14 CHAR LibraryPath[PATHCCH_MAX_CCH] = WINPR_C_ARRAY_INIT;
18 if (!GetModuleFileNameA(
nullptr, LibraryPath, PATHCCH_MAX_CCH))
20 const UINT32 err = GetLastError();
21 const HRESULT herr = HRESULT_FROM_WIN32(err);
22 printf(
"%s: GetModuleFilenameA failed: %s - %s [0x%08" PRIX32
"]\n", __func__,
23 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
29 if (!(p = strrchr(LibraryPath, PathGetSeparatorA(PATH_STYLE_NATIVE))))
31 printf(
"%s: Error identifying module directory path\n", __func__);
36 if (FAILED(NativePathCchAppendA(LibraryPath, PATHCCH_MAX_CCH,
"TestLibraryA")))
38 SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
39 if (FAILED(NativePathCchAddExtensionA(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension)))
42 printf(
"%s: Loading Library: '%s'\n", __func__, LibraryPath);
44 if (!(library = LoadLibraryA(LibraryPath)))
46 const UINT32 err = GetLastError();
47 const HRESULT herr = HRESULT_FROM_WIN32(err);
48 printf(
"%s: LoadLibraryA failure: %s - %s [0x%08" PRIX32
"]\n", __func__,
49 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
53 if (!FreeLibrary(library))
55 const UINT32 err = GetLastError();
56 const HRESULT herr = HRESULT_FROM_WIN32(err);
57 printf(
"%s: FreeLibrary failure: %s - %s [0x%08" PRIX32
"]\n", __func__, NtStatus2Tag(herr),
58 Win32ErrorCode2Tag(err), err);