2012-10-05 02:57:32 +04:00
|
|
|
|
|
|
|
#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>
|
2012-10-05 02:57:32 +04:00
|
|
|
#include <winpr/windows.h>
|
2012-10-05 22:45:54 +04:00
|
|
|
#include <winpr/library.h>
|
2012-10-05 02:57:32 +04:00
|
|
|
|
|
|
|
int TestLibraryLoadLibrary(int argc, char* argv[])
|
|
|
|
{
|
2012-10-05 07:19:05 +04:00
|
|
|
HINSTANCE library;
|
2016-06-10 14:10:39 +03:00
|
|
|
LPCSTR SharedLibraryExtension;
|
|
|
|
CHAR LibraryPath[PATHCCH_MAX_CCH];
|
|
|
|
PCHAR p;
|
2021-07-29 11:18:52 +03:00
|
|
|
WINPR_UNUSED(argc);
|
|
|
|
WINPR_UNUSED(argv);
|
2016-06-10 14:10:39 +03:00
|
|
|
if (!GetModuleFileNameA(NULL, LibraryPath, PATHCCH_MAX_CCH))
|
2015-04-03 17:21:01 +03:00
|
|
|
{
|
2023-07-27 10:02:03 +03:00
|
|
|
printf("%s: GetModuleFilenameA failed: 0x%08" PRIX32 "\n", __func__, GetLastError());
|
2015-04-03 17:21:01 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2016-06-10 14:10:39 +03:00
|
|
|
|
|
|
|
/* PathCchRemoveFileSpec is not implemented in WinPR */
|
|
|
|
|
|
|
|
if (!(p = strrchr(LibraryPath, PathGetSeparatorA(PATH_STYLE_NATIVE))))
|
2015-06-17 23:08:02 +03:00
|
|
|
{
|
2023-07-27 10:02:03 +03:00
|
|
|
printf("%s: Error identifying module directory path\n", __func__);
|
2015-06-17 23:08:02 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2016-06-10 14:10:39 +03:00
|
|
|
*p = 0;
|
2015-06-17 23:08:02 +03:00
|
|
|
|
2016-06-10 14:10:39 +03:00
|
|
|
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
|
|
|
|
2023-07-27 10:02:03 +03:00
|
|
|
printf("%s: Loading Library: '%s'\n", __func__, LibraryPath);
|
2012-10-05 07:19:05 +04:00
|
|
|
|
2016-06-10 14:10:39 +03:00
|
|
|
if (!(library = LoadLibraryA(LibraryPath)))
|
2012-10-05 07:19:05 +04:00
|
|
|
{
|
2023-07-27 10:02:03 +03:00
|
|
|
printf("%s: LoadLibraryA failure: 0x%08" PRIX32 "\n", __func__, GetLastError());
|
2012-10-05 07:19:05 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FreeLibrary(library))
|
|
|
|
{
|
2023-07-27 10:02:03 +03:00
|
|
|
printf("%s: FreeLibrary failure: 0x%08" PRIX32 "\n", __func__, GetLastError());
|
2012-10-05 07:19:05 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-05 02:57:32 +04:00
|
|
|
return 0;
|
|
|
|
}
|