system_lib.cpp 883 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "system_lib.h"
  2. #include "log_helper.h"
  3. namespace am {
  4. static char system_path[260] = { 0 };
  5. static bool get_system_path() {
  6. if (strlen(system_path) == 0) {
  7. UINT ret = GetSystemDirectoryA(system_path, MAX_PATH);
  8. if (!ret) {
  9. al_fatal("failed to get system directory :%lu", GetLastError());
  10. return false;
  11. }
  12. }
  13. return true;
  14. }
  15. HMODULE load_system_library(const char * name)
  16. {
  17. if (get_system_path() == false) return NULL;
  18. char base_path[MAX_PATH] = { 0 };
  19. strcpy(base_path, system_path);
  20. strcat(base_path, "\\");
  21. strcat(base_path, name);
  22. HMODULE module = GetModuleHandleA(base_path);
  23. if (module)
  24. return module;
  25. module = LoadLibraryA(base_path);
  26. if (!module) {
  27. al_error("failed load system library :%lu", GetLastError());
  28. }
  29. return module;
  30. }
  31. void free_system_library(HMODULE handle)
  32. {
  33. FreeModule(handle);
  34. }
  35. }