system_lib.cpp 962 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. {
  7. if (strlen(system_path) == 0) {
  8. UINT ret = GetSystemDirectoryA(system_path, MAX_PATH);
  9. if (!ret) {
  10. al_fatal("failed to get system directory :%lu", GetLastError());
  11. return false;
  12. }
  13. }
  14. return true;
  15. }
  16. HMODULE load_system_library(const char *name)
  17. {
  18. if (get_system_path() == false)
  19. return NULL;
  20. char base_path[MAX_PATH] = {0};
  21. strcpy(base_path, system_path);
  22. strcat(base_path, "\\");
  23. strcat(base_path, name);
  24. HMODULE module = GetModuleHandleA(base_path);
  25. if (module)
  26. return module;
  27. module = LoadLibraryA(base_path);
  28. if (!module) {
  29. al_error("failed load system library :%lu", GetLastError());
  30. }
  31. return module;
  32. }
  33. void free_system_library(HMODULE handle)
  34. {
  35. FreeModule(handle);
  36. }
  37. } // namespace am