FreeRDP
Loading...
Searching...
No Matches
TestLibraryLoadLibrary.c
1
2#include <stdio.h>
3#include <winpr/crt.h>
4#include <winpr/path.h>
5#include <winpr/tchar.h>
6#include <winpr/windows.h>
7#include <winpr/library.h>
8#include <winpr/nt.h>
9
10int TestLibraryLoadLibrary(int argc, char* argv[])
11{
12 HINSTANCE library = NULL;
13 LPCSTR SharedLibraryExtension = NULL;
14 CHAR LibraryPath[PATHCCH_MAX_CCH] = { 0 };
15 PCHAR p = NULL;
16 WINPR_UNUSED(argc);
17 WINPR_UNUSED(argv);
18 if (!GetModuleFileNameA(NULL, LibraryPath, PATHCCH_MAX_CCH))
19 {
20 const UINT32 err = GetLastError();
21 const HRESULT herr = HRESULT_FROM_WIN32(err);
22 printf("%s: GetModuleFilenameA failed: %s - %s [0x%08" PRIX32 "]\n", __func__,
23 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
24 return -1;
25 }
26
27 /* PathCchRemoveFileSpec is not implemented in WinPR */
28
29 if (!(p = strrchr(LibraryPath, PathGetSeparatorA(PATH_STYLE_NATIVE))))
30 {
31 printf("%s: Error identifying module directory path\n", __func__);
32 return -1;
33 }
34 *p = 0;
35
36 NativePathCchAppendA(LibraryPath, PATHCCH_MAX_CCH, "TestLibraryA");
37 SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
38 NativePathCchAddExtensionA(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension);
39
40 printf("%s: Loading Library: '%s'\n", __func__, LibraryPath);
41
42 if (!(library = LoadLibraryA(LibraryPath)))
43 {
44 const UINT32 err = GetLastError();
45 const HRESULT herr = HRESULT_FROM_WIN32(err);
46 printf("%s: LoadLibraryA failure: %s - %s [0x%08" PRIX32 "]\n", __func__,
47 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
48 return -1;
49 }
50
51 if (!FreeLibrary(library))
52 {
53 const UINT32 err = GetLastError();
54 const HRESULT herr = HRESULT_FROM_WIN32(err);
55 printf("%s: FreeLibrary failure: %s - %s [0x%08" PRIX32 "]\n", __func__, NtStatus2Tag(herr),
56 Win32ErrorCode2Tag(err), err);
57 return -1;
58 }
59
60 return 0;
61}