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 = NULL;
 
   18  TEST_AB_FN pFunctionA = NULL;
 
   19  TEST_AB_FN pFunctionB = NULL;
 
   20  LPCSTR SharedLibraryExtension = NULL;
 
   21  CHAR LibraryPath[PATHCCH_MAX_CCH] = { 0 };
 
   25  if (!GetModuleFileNameA(NULL, 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  NativePathCchAppendA(LibraryPath, PATHCCH_MAX_CCH, 
"TestLibraryA");
 
   44  SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
 
   45  NativePathCchAddExtensionA(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension);
 
   46  printf(
"%s: Loading Library: '%s'\n", __func__, LibraryPath);
 
   48  if (!(library = LoadLibraryA(LibraryPath)))
 
   50    const UINT32 err = GetLastError();
 
   51    const HRESULT herr = HRESULT_FROM_WIN32(err);
 
   52    printf(
"%s: LoadLibraryA failure: %s - %s [0x%08" PRIX32 
"]\n", __func__,
 
   53           NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
 
   57  if (!(pFunctionA = GetProcAddressAs(library, 
"FunctionA", TEST_AB_FN)))
 
   59    const UINT32 err = GetLastError();
 
   60    const HRESULT herr = HRESULT_FROM_WIN32(err);
 
   61    printf(
"%s: GetProcAddress failure (FunctionA) %s - %s [0x%08" PRIX32 
"]\n", __func__,
 
   62           NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
 
   66  if (!(pFunctionB = GetProcAddressAs(library, 
"FunctionB", TEST_AB_FN)))
 
   68    const UINT32 err = GetLastError();
 
   69    const HRESULT herr = HRESULT_FROM_WIN32(err);
 
   70    printf(
"%s: GetProcAddress failure (FunctionB) %s - %s [0x%08" PRIX32 
"]\n", __func__,
 
   71           NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
 
   81    printf(
"%s: pFunctionA call failed\n", __func__);
 
   91    printf(
"%s: pFunctionB call failed\n", __func__);
 
   95  if (!FreeLibrary(library))
 
   97    const UINT32 err = GetLastError();
 
   98    const HRESULT herr = HRESULT_FROM_WIN32(err);
 
   99    printf(
"%s: FreeLibrary failure: %s - %s [0x%08" PRIX32 
"]\n", __func__, NtStatus2Tag(herr),
 
  100           Win32ErrorCode2Tag(err), err);