6#include <winpr/tchar.h>
7#include <winpr/windows.h>
8#include <winpr/library.h>
11typedef int (*TEST_AB_FN)(
int a,
int b);
13int TestLibraryGetProcAddress(
int argc,
char* argv[])
18 HINSTANCE library =
nullptr;
19 TEST_AB_FN pFunctionA =
nullptr;
20 TEST_AB_FN pFunctionB =
nullptr;
21 LPCSTR SharedLibraryExtension =
nullptr;
22 CHAR LibraryPath[MAX_PATH] = WINPR_C_ARRAY_INIT;
26 if (!GetModuleFileNameA(
nullptr, LibraryPath, ARRAYSIZE(LibraryPath)))
28 const UINT32 err = GetLastError();
29 const HRESULT herr = HRESULT_FROM_WIN32(err);
30 printf(
"%s: GetModuleFilenameA failed: %s - %s [0x%08" PRIX32
"]\n", __func__,
31 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
37 if (!(p = strrchr(LibraryPath, PathGetSeparatorA(PATH_STYLE_NATIVE))))
39 printf(
"%s: Error identifying module directory path\n", __func__);
44 if (FAILED(NativePathCchAppendA(LibraryPath, ARRAYSIZE(LibraryPath),
"TestLibraryA")))
46 SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
47 if (FAILED(NativePathCchAddExtensionA(LibraryPath, ARRAYSIZE(LibraryPath),
48 SharedLibraryExtension)))
50 printf(
"%s: Loading Library: '%s'\n", __func__, LibraryPath);
52 if (!(library = LoadLibraryA(LibraryPath)))
54 const UINT32 err = GetLastError();
55 const HRESULT herr = HRESULT_FROM_WIN32(err);
56 printf(
"%s: LoadLibraryA failure: %s - %s [0x%08" PRIX32
"]\n", __func__,
57 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
61 if (!(pFunctionA = GetProcAddressAs(library,
"FunctionA", TEST_AB_FN)))
63 const UINT32 err = GetLastError();
64 const HRESULT herr = HRESULT_FROM_WIN32(err);
65 printf(
"%s: GetProcAddress failure (FunctionA) %s - %s [0x%08" PRIX32
"]\n", __func__,
66 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
70 if (!(pFunctionB = GetProcAddressAs(library,
"FunctionB", TEST_AB_FN)))
72 const UINT32 err = GetLastError();
73 const HRESULT herr = HRESULT_FROM_WIN32(err);
74 printf(
"%s: GetProcAddress failure (FunctionB) %s - %s [0x%08" PRIX32
"]\n", __func__,
75 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
85 printf(
"%s: pFunctionA call failed\n", __func__);
95 printf(
"%s: pFunctionB call failed\n", __func__);
99 if (!FreeLibrary(library))
101 const UINT32 err = GetLastError();
102 const HRESULT herr = HRESULT_FROM_WIN32(err);
103 printf(
"%s: FreeLibrary failure: %s - %s [0x%08" PRIX32
"]\n", __func__, NtStatus2Tag(herr),
104 Win32ErrorCode2Tag(err), err);