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

77 lines
1.8 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;
2012-10-18 23:37:00 +04:00
LPCTSTR SharedLibraryExtension;
TCHAR LibraryPath[PATHCCH_MAX_CCH];
2012-10-05 07:19:05 +04:00
#ifndef _WIN32
char* str;
int length;
LPTSTR BasePath;
2012-10-18 23:37:00 +04:00
str = argv[1];
#ifdef UNICODE
length = MultiByteToWideChar(CP_UTF8, 0, str, strlen(str), NULL, 0);
BasePath = (WCHAR*) malloc((length + 1) * sizeof(WCHAR));
if (!BasePath)
{
_tprintf(_T("Memory allocation failed\n"));
return -1;
}
2012-10-18 23:37:00 +04:00
MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) BasePath, length * sizeof(WCHAR));
BasePath[length] = 0;
#else
BasePath = _strdup(str);
if (!BasePath)
{
printf("Memory allocation failed");
return -1;
}
2012-10-18 23:37:00 +04:00
length = strlen(BasePath);
#endif
CopyMemory(LibraryPath, BasePath, length * sizeof(TCHAR));
LibraryPath[length] = 0;
2012-10-18 23:37:00 +04:00
NativePathCchAppend(LibraryPath, PATHCCH_MAX_CCH, _T("TestLibraryA")); /* subdirectory */
#else /* _WIN32 */
/* On Windows the test libraries are in same folder as the test executable */
GetModuleFileName(NULL, LibraryPath, PATHCCH_MAX_CCH);
PathRemoveFileSpec(LibraryPath);
#endif
2012-10-18 23:37:00 +04:00
NativePathCchAppend(LibraryPath, PATHCCH_MAX_CCH, _T("TestLibraryA")); /* file name without extension */
SharedLibraryExtension = PathGetSharedLibraryExtension(PATH_SHARED_LIB_EXT_WITH_DOT);
NativePathCchAddExtension(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension); /* add shared library extension */
_tprintf(_T("Loading Library: %s\n"), LibraryPath);
library = LoadLibrary(LibraryPath);
2012-10-05 07:19:05 +04:00
if (!library)
{
2012-10-18 23:37:00 +04:00
_tprintf(_T("LoadLibrary failure\n"));
2012-10-05 07:19:05 +04:00
return -1;
}
if (!FreeLibrary(library))
{
2012-10-18 23:37:00 +04:00
_tprintf(_T("FreeLibrary failure\n"));
2012-10-05 07:19:05 +04:00
return -1;
}
return 0;
}