/xbmc/win32/Win32DelayedDllLoad.cpp

http://github.com/xbmc/xbmc · C++ · 84 lines · 60 code · 4 blank · 20 comment · 12 complexity · c175c29de47b2efe6a53cbfc3df4de65 MD5 · raw file

  1. /*
  2. * Copyright (C) 2005-2013 Team XBMC
  3. * http://xbmc.org
  4. *
  5. * This Program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2, or (at your option)
  8. * any later version.
  9. *
  10. * This Program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with XBMC; see the file COPYING. If not, see
  17. * <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #include <DelayImp.h>
  21. #include "DllPaths_win32.h"
  22. #include "filesystem/SpecialProtocol.h"
  23. #include "Application.h"
  24. #include "windowing/WindowingFactory.h"
  25. FARPROC WINAPI delayHookNotifyFunc (unsigned dliNotify, PDelayLoadInfo pdli)
  26. {
  27. switch (dliNotify)
  28. {
  29. case dliNotePreLoadLibrary:
  30. if (stricmp(pdli->szDll, "libmicrohttpd-5.dll") == 0)
  31. {
  32. CStdString strDll = CSpecialProtocol::TranslatePath(DLL_PATH_LIBMICROHTTP);
  33. HMODULE hMod = LoadLibraryEx(strDll.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH);
  34. return (FARPROC)hMod;
  35. }
  36. if (stricmp(pdli->szDll, "ssh.dll") == 0)
  37. {
  38. CStdString strDll = CSpecialProtocol::TranslatePath("special://xbmcbin/system/ssh.dll");
  39. HMODULE hMod = LoadLibraryEx(strDll.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH);
  40. return (FARPROC)hMod;
  41. }
  42. if (stricmp(pdli->szDll, "sqlite3.dll") == 0)
  43. {
  44. CStdString strDll = CSpecialProtocol::TranslatePath("special://xbmcbin/system/sqlite3.dll");
  45. HMODULE hMod = LoadLibraryEx(strDll.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH);
  46. return (FARPROC)hMod;
  47. }
  48. if (stricmp(pdli->szDll, "libsamplerate-0.dll") == 0)
  49. {
  50. CStdString strDll = CSpecialProtocol::TranslatePath("special://xbmcbin/system/libsamplerate-0.dll");
  51. HMODULE hMod = LoadLibraryEx(strDll.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH);
  52. return (FARPROC)hMod;
  53. }
  54. if (stricmp(pdli->szDll, "dnssd.dll") == 0)
  55. {
  56. CStdString strDll = CSpecialProtocol::TranslatePath("special://xbmcbin/system/dnssd.dll");
  57. HMODULE hMod = LoadLibraryEx(strDll.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH);
  58. return (FARPROC)hMod;
  59. }
  60. break;
  61. }
  62. return NULL;
  63. }
  64. FARPROC WINAPI delayHookFailureFunc (unsigned dliNotify, PDelayLoadInfo pdli)
  65. {
  66. switch (dliNotify)
  67. {
  68. case dliFailLoadLib:
  69. g_application.Stop(1);
  70. CStdString strError;
  71. strError.Format("Uh oh, can't load %s, exiting.", pdli->szDll);
  72. MessageBox(NULL, strError.c_str(), "XBMC: Fatal Error", MB_OK|MB_ICONERROR);
  73. exit(1);
  74. break;
  75. }
  76. return NULL;
  77. }
  78. // assign hook functions
  79. PfnDliHook __pfnDliNotifyHook2 = delayHookNotifyFunc;
  80. PfnDliHook __pfnDliFailureHook2 = delayHookFailureFunc;