FreeRDP/winpr/libwinpr/library/test/TestLibraryLoadLibrary.c

52 lines
1.3 KiB
C
Raw Normal View History

#include <stdio.h>
#include <winpr/crt.h>
2012-10-18 23:37:00 +04:00
#include <winpr/path.h>
2012-10-05 07:19:05 +04:00
#include <winpr/tchar.h>
#include <winpr/windows.h>
2012-10-05 22:45:54 +04:00
#include <winpr/library.h>
int TestLibraryLoadLibrary(int argc, char* argv[])
{
2012-10-05 07:19:05 +04:00
HINSTANCE library;
LPCSTR SharedLibraryExtension;
CHAR LibraryPath[PATHCCH_MAX_CCH];
PCHAR p;
2021-07-29 11:18:52 +03:00
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
if (!GetModuleFileNameA(NULL, LibraryPath, PATHCCH_MAX_CCH))
{
printf("%s: GetModuleFilenameA failed: 0x%08" PRIX32 "\n", __func__, GetLastError());
return -1;
}
/* PathCchRemoveFileSpec is not implemented in WinPR */
if (!(p = strrchr(LibraryPath, PathGetSeparatorA(PATH_STYLE_NATIVE))))
{
printf("%s: Error identifying module directory path\n", __func__);
return -1;
}
*p = 0;
NativePathCchAppendA(LibraryPath, PATHCCH_MAX_CCH, "TestLibraryA");
SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
NativePathCchAddExtensionA(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension);
2012-10-18 23:37:00 +04:00
printf("%s: Loading Library: '%s'\n", __func__, LibraryPath);
2012-10-05 07:19:05 +04:00
if (!(library = LoadLibraryA(LibraryPath)))
2012-10-05 07:19:05 +04:00
{
printf("%s: LoadLibraryA failure: 0x%08" PRIX32 "\n", __func__, GetLastError());
2012-10-05 07:19:05 +04:00
return -1;
}
if (!FreeLibrary(library))
{
printf("%s: FreeLibrary failure: 0x%08" PRIX32 "\n", __func__, GetLastError());
2012-10-05 07:19:05 +04:00
return -1;
}
return 0;
}