4 #include <winpr/path.h>
5 #include <winpr/tchar.h>
6 #include <winpr/windows.h>
7 #include <winpr/library.h>
9 typedef int (*TEST_AB_FN)(
int a,
int b);
11 int TestLibraryGetProcAddress(
int argc,
char* argv[])
16 HINSTANCE library = NULL;
17 TEST_AB_FN pFunctionA = NULL;
18 TEST_AB_FN pFunctionB = NULL;
19 LPCSTR SharedLibraryExtension = NULL;
20 CHAR LibraryPath[PATHCCH_MAX_CCH];
24 if (!GetModuleFileNameA(NULL, LibraryPath, PATHCCH_MAX_CCH))
26 printf(
"%s: GetModuleFilenameA failed: 0x%08" PRIX32
"\n", __func__, GetLastError());
32 if (!(p = strrchr(LibraryPath, PathGetSeparatorA(PATH_STYLE_NATIVE))))
34 printf(
"%s: Error identifying module directory path\n", __func__);
39 NativePathCchAppendA(LibraryPath, PATHCCH_MAX_CCH,
"TestLibraryA");
40 SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
41 NativePathCchAddExtensionA(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension);
42 printf(
"%s: Loading Library: '%s'\n", __func__, LibraryPath);
44 if (!(library = LoadLibraryA(LibraryPath)))
46 printf(
"%s: LoadLibraryA failure: 0x%08" PRIX32
"\n", __func__, GetLastError());
50 if (!(pFunctionA = GetProcAddressAs(library,
"FunctionA", TEST_AB_FN)))
52 printf(
"%s: GetProcAddress failure (FunctionA)\n", __func__);
56 if (!(pFunctionB = GetProcAddressAs(library,
"FunctionB", TEST_AB_FN)))
58 printf(
"%s: GetProcAddress failure (FunctionB)\n", __func__);
68 printf(
"%s: pFunctionA call failed\n", __func__);
78 printf(
"%s: pFunctionB call failed\n", __func__);
82 if (!FreeLibrary(library))
84 printf(
"%s: FreeLibrary failure: 0x%08" PRIX32
"\n", __func__, GetLastError());