FreeRDP
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 
9 int TestLibraryLoadLibrary(int argc, char* argv[])
10 {
11  HINSTANCE library = NULL;
12  LPCSTR SharedLibraryExtension = NULL;
13  CHAR LibraryPath[PATHCCH_MAX_CCH];
14  PCHAR p = NULL;
15  WINPR_UNUSED(argc);
16  WINPR_UNUSED(argv);
17  if (!GetModuleFileNameA(NULL, LibraryPath, PATHCCH_MAX_CCH))
18  {
19  printf("%s: GetModuleFilenameA failed: 0x%08" PRIX32 "\n", __func__, GetLastError());
20  return -1;
21  }
22 
23  /* PathCchRemoveFileSpec is not implemented in WinPR */
24 
25  if (!(p = strrchr(LibraryPath, PathGetSeparatorA(PATH_STYLE_NATIVE))))
26  {
27  printf("%s: Error identifying module directory path\n", __func__);
28  return -1;
29  }
30  *p = 0;
31 
32  NativePathCchAppendA(LibraryPath, PATHCCH_MAX_CCH, "TestLibraryA");
33  SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT);
34  NativePathCchAddExtensionA(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension);
35 
36  printf("%s: Loading Library: '%s'\n", __func__, LibraryPath);
37 
38  if (!(library = LoadLibraryA(LibraryPath)))
39  {
40  printf("%s: LoadLibraryA failure: 0x%08" PRIX32 "\n", __func__, GetLastError());
41  return -1;
42  }
43 
44  if (!FreeLibrary(library))
45  {
46  printf("%s: FreeLibrary failure: 0x%08" PRIX32 "\n", __func__, GetLastError());
47  return -1;
48  }
49 
50  return 0;
51 }