5#include <winpr/tchar.h>
6#include <winpr/windows.h>
7#include <winpr/library.h>
10typedef int (*TEST_AB_FN)(
int a,
int b);
12int TestLibraryGetProcAddress(
int argc,
char* argv[])
17 HINSTANCE library =
nullptr;
18 TEST_AB_FN pFunctionA =
nullptr;
19 TEST_AB_FN pFunctionB =
nullptr;
20 LPCSTR SharedLibraryExtension =
nullptr;
21 CHAR LibraryPath[PATHCCH_MAX_CCH] = WINPR_C_ARRAY_INIT;
25 if (!GetModuleFileNameA(
nullptr, LibraryPath, PATHCCH_MAX_CCH))
27 const UINT32 err = GetLastError();
28 const HRESULT herr = HRESULT_FROM_WIN32(err);
29 printf(
"%s: GetModuleFilenameA failed: %s - %s [0x%08" PRIX32
"]\n", __func__,
30 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
36 if (!(p = strrchr(LibraryPath, PathGetSeparatorA(PATH_STYLE_NATIVE))))
38 printf(
"%s: Error identifying module directory path\n", __func__);
43 if (FAILED(NativePathCchAppendA(LibraryPath, PATHCCH_MAX_CCH,
"TestLibraryA")))
45 SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
46 if (FAILED(NativePathCchAddExtensionA(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension)))
48 printf(
"%s: Loading Library: '%s'\n", __func__, LibraryPath);
50 if (!(library = LoadLibraryA(LibraryPath)))
52 const UINT32 err = GetLastError();
53 const HRESULT herr = HRESULT_FROM_WIN32(err);
54 printf(
"%s: LoadLibraryA failure: %s - %s [0x%08" PRIX32
"]\n", __func__,
55 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
59 if (!(pFunctionA = GetProcAddressAs(library,
"FunctionA", TEST_AB_FN)))
61 const UINT32 err = GetLastError();
62 const HRESULT herr = HRESULT_FROM_WIN32(err);
63 printf(
"%s: GetProcAddress failure (FunctionA) %s - %s [0x%08" PRIX32
"]\n", __func__,
64 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
68 if (!(pFunctionB = GetProcAddressAs(library,
"FunctionB", TEST_AB_FN)))
70 const UINT32 err = GetLastError();
71 const HRESULT herr = HRESULT_FROM_WIN32(err);
72 printf(
"%s: GetProcAddress failure (FunctionB) %s - %s [0x%08" PRIX32
"]\n", __func__,
73 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
83 printf(
"%s: pFunctionA call failed\n", __func__);
93 printf(
"%s: pFunctionB call failed\n", __func__);
97 if (!FreeLibrary(library))
99 const UINT32 err = GetLastError();
100 const HRESULT herr = HRESULT_FROM_WIN32(err);
101 printf(
"%s: FreeLibrary failure: %s - %s [0x%08" PRIX32
"]\n", __func__, NtStatus2Tag(herr),
102 Win32ErrorCode2Tag(err), err);