Merge remote branch 'mine/ext-python'
[vuplus_xbmc] / xbmc / win32 / Win32DelayedDllLoad.cpp
1 /*
2  *      Copyright (C) 2005-2010 Team XBMC
3  *      http://www.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, write to
17  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18  *  http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21
22 #include <DelayImp.h>
23 #include "DllPaths_win32.h"
24 #include "filesystem/SpecialProtocol.h"
25 #include "Application.h"
26 #include "windowing/WindowingFactory.h"
27
28 FARPROC WINAPI delayHookNotifyFunc (unsigned dliNotify, PDelayLoadInfo pdli)
29 {
30   switch (dliNotify)
31   {
32     case dliNotePreLoadLibrary:
33       if (stricmp(pdli->szDll, "libmicrohttpd-5.dll") == 0)
34       {
35         CStdString strDll = CSpecialProtocol::TranslatePath(DLL_PATH_LIBMICROHTTP);
36         HMODULE hMod = LoadLibraryEx(strDll.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH);
37         return (FARPROC)hMod;
38       }
39       if (stricmp(pdli->szDll, "ssh.dll") == 0)
40       {
41         CStdString strDll = CSpecialProtocol::TranslatePath("special://xbmcbin/system/ssh.dll");
42         HMODULE hMod = LoadLibraryEx(strDll.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH);
43         return (FARPROC)hMod;
44       }
45       if (stricmp(pdli->szDll, "sqlite3.dll") == 0)
46       {
47         CStdString strDll = CSpecialProtocol::TranslatePath("special://xbmcbin/system/sqlite3.dll");
48         HMODULE hMod = LoadLibraryEx(strDll.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH);
49         return (FARPROC)hMod;
50       }
51       if (stricmp(pdli->szDll, "libsamplerate-0.dll") == 0)
52       {
53         CStdString strDll = CSpecialProtocol::TranslatePath("special://xbmcbin/system/libsamplerate-0.dll");
54         HMODULE hMod = LoadLibraryEx(strDll.c_str(), 0, LOAD_WITH_ALTERED_SEARCH_PATH);
55         return (FARPROC)hMod;
56       }
57       break;
58   }
59   return NULL;
60 }
61
62 FARPROC WINAPI delayHookFailureFunc (unsigned dliNotify, PDelayLoadInfo pdli)
63 {
64   switch (dliNotify)
65   {
66     case dliFailLoadLib:
67       g_application.Stop(1);
68       CStdString strError;
69       strError.Format("Uh oh, can't load %s, exiting.", pdli->szDll);
70       MessageBox(NULL, strError.c_str(), "XBMC: Fatal Error", MB_OK|MB_ICONERROR);
71       exit(1);
72       break;
73   }
74   return NULL;
75 }
76
77 // assign hook functions
78 PfnDliHook __pfnDliNotifyHook2 = delayHookNotifyFunc;
79 PfnDliHook __pfnDliFailureHook2 = delayHookFailureFunc;