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 = nullptr;
13 LPCSTR SharedLibraryExtension = nullptr;
14 CHAR LibraryPath[PATHCCH_MAX_CCH] = WINPR_C_ARRAY_INIT;
15 PCHAR p = nullptr;
16 WINPR_UNUSED(argc);
17 WINPR_UNUSED(argv);
18 if (!GetModuleFileNameA(nullptr, 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 if (FAILED(NativePathCchAppendA(LibraryPath, PATHCCH_MAX_CCH, "TestLibraryA")))
37 return -1;
38 SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
39 if (FAILED(NativePathCchAddExtensionA(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension)))
40 return -1;
41
42 printf("%s: Loading Library: '%s'\n", __func__, LibraryPath);
43
44 if (!(library = LoadLibraryA(LibraryPath)))
45 {
46 const UINT32 err = GetLastError();
47 const HRESULT herr = HRESULT_FROM_WIN32(err);
48 printf("%s: LoadLibraryA failure: %s - %s [0x%08" PRIX32 "]\n", __func__,
49 NtStatus2Tag(herr), Win32ErrorCode2Tag(err), err);
50 return -1;
51 }
52
53 if (!FreeLibrary(library))
54 {
55 const UINT32 err = GetLastError();
56 const HRESULT herr = HRESULT_FROM_WIN32(err);
57 printf("%s: FreeLibrary failure: %s - %s [0x%08" PRIX32 "]\n", __func__, NtStatus2Tag(herr),
58 Win32ErrorCode2Tag(err), err);
59 return -1;
60 }
61
62 return 0;
63}