ole32: Fix crash when calling CreateStorage on read only storage.
[wine] / dlls / msxml3 / main.c
1 /*
2  *    MSXML Class Factory
3  *
4  * Copyright 2002 Lionel Ulmer
5  * Copyright 2005 Mike McCormack
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #define COBJMACROS
26
27 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winuser.h"
31 #include "ole2.h"
32 #include "msxml.h"
33 #include "msxml2.h"
34
35 #include "wine/debug.h"
36 #include "wine/library.h"
37
38 #include "msxml_private.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
41
42 HRESULT WINAPI DllCanUnloadNow(void)
43 {
44     FIXME("\n");
45     return S_FALSE;
46 }
47
48
49 void* libxslt_handle = NULL;
50 #ifdef SONAME_LIBXSLT
51 # define DECL_FUNCPTR(f) typeof(f) * p##f = NULL
52 DECL_FUNCPTR(xsltApplyStylesheet);
53 DECL_FUNCPTR(xsltCleanupGlobals);
54 DECL_FUNCPTR(xsltFreeStylesheet);
55 DECL_FUNCPTR(xsltParseStylesheetDoc);
56 # undef MAKE_FUNCPTR
57 #endif
58
59 static void init_libxslt(void)
60 {
61 #ifdef SONAME_LIBXSLT
62     void (*pxsltInit)(void); /* Missing in libxslt <= 1.1.14 */
63
64     libxslt_handle = wine_dlopen(SONAME_LIBXSLT, RTLD_NOW, NULL, 0);
65     if (!libxslt_handle)
66         return;
67
68 #define LOAD_FUNCPTR(f, needed) if ((p##f = wine_dlsym(libxslt_handle, #f, NULL, 0)) == NULL && needed) { WARN("Can't find symbol %s\n", #f); goto sym_not_found; }
69     LOAD_FUNCPTR(xsltInit, 0);
70     LOAD_FUNCPTR(xsltApplyStylesheet, 1);
71     LOAD_FUNCPTR(xsltCleanupGlobals, 1);
72     LOAD_FUNCPTR(xsltFreeStylesheet, 1);
73     LOAD_FUNCPTR(xsltParseStylesheetDoc, 1);
74 #undef LOAD_FUNCPTR
75
76     if (pxsltInit)
77         pxsltInit();
78     return;
79
80  sym_not_found:
81     wine_dlclose(libxslt_handle, NULL, 0);
82     libxslt_handle = NULL;
83 #endif
84 }
85
86
87 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
88 {
89     switch(fdwReason)
90     {
91     case DLL_PROCESS_ATTACH:
92 #ifdef HAVE_LIBXML2
93         xmlInitParser();
94
95         /* Set the default indent character to a single tab,
96            for this thread and as default for new threads */
97         xmlTreeIndentString = "\t";
98         xmlThrDefTreeIndentString("\t");
99 #endif
100         init_libxslt();
101         DisableThreadLibraryCalls(hInstDLL);
102         break;
103     case DLL_PROCESS_DETACH:
104 #ifdef SONAME_LIBXSLT
105         if (libxslt_handle)
106         {
107             pxsltCleanupGlobals();
108             wine_dlclose(libxslt_handle, NULL, 0);
109             libxslt_handle = NULL;
110         }
111 #endif
112 #ifdef HAVE_LIBXML2
113         xmlCleanupParser();
114 #endif
115         release_typelib();
116         break;
117     }
118     return TRUE;
119 }