5#include <winpr/tchar.h>
6#include <winpr/windows.h>
7#include <winpr/library.h>
10int TestLibraryLoadLibrary(
int argc,
char* argv[])
12 HINSTANCE library = NULL;
13 LPCSTR SharedLibraryExtension = NULL;
14 CHAR LibraryPath[PATHCCH_MAX_CCH] = { 0 };
18 if (!GetModuleFileNameA(NULL, 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 NativePathCchAppendA(LibraryPath, PATHCCH_MAX_CCH,
"TestLibraryA");
37 SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
38 NativePathCchAddExtensionA(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension);
40 printf(
"%s: Loading Library: '%s'\n", __func__, LibraryPath);
42 if (!(library = LoadLibraryA(LibraryPath)))
44 const UINT32 err = GetLastError();
45 const HRESULT herr = HRESULT_FROM_WIN32(err);
46 printf(
"%s: LoadLibraryA failure: %s - %s [0x%08" PRIX32
"]\n", __func__,
47 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
51 if (!FreeLibrary(library))
53 const UINT32 err = GetLastError();
54 const HRESULT herr = HRESULT_FROM_WIN32(err);
55 printf(
"%s: FreeLibrary failure: %s - %s [0x%08" PRIX32
"]\n", __func__, NtStatus2Tag(herr),
56 Win32ErrorCode2Tag(err), err);