quartz: Fix discontinuities in wave parser.
[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
24 #define COBJMACROS
25
26 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "ole2.h"
31 #include "msxml.h"
32 #include "msxml2.h"
33
34 #include "wine/debug.h"
35
36 #include "msxml_private.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
39
40 static HINSTANCE hInstance;
41 static ITypeLib *typelib;
42 static ITypeInfo *typeinfos[LAST_tid];
43
44 static REFIID tid_ids[] = {
45     &IID_IXMLDOMAttribute,
46     &IID_IXMLDOMCDATASection,
47     &IID_IXMLDOMComment,
48     &IID_IXMLDOMDocument2,
49     &IID_IXMLDOMDocumentFragment,
50     &IID_IXMLDOMElement,
51     &IID_IXMLDOMEntityReference,
52     &IID_IXMLDOMImplementation,
53     &IID_IXMLDOMNamedNodeMap,
54     &IID_IXMLDOMNodeList,
55     &IID_IXMLDOMParseError,
56     &IID_IXMLDOMProcessingInstruction,
57     &IID_IXMLDOMSchemaCollection,
58     &IID_IXMLDOMText,
59     &IID_IXMLElement,
60     &IID_IXMLDOMDocument,
61     &IID_IVBSAXAttributes,
62     &IID_IVBSAXContentHandler,
63     &IID_IVBSAXDeclHandler,
64     &IID_IVBSAXDTDHandler,
65     &IID_IVBSAXEntityResolver,
66     &IID_IVBSAXErrorHandler,
67     &IID_IVBSAXLexicalHandler,
68     &IID_IVBSAXLocator,
69     &IID_IVBSAXXMLFilter,
70     &IID_IVBSAXXMLReader,
71     &IID_IMXAttributes,
72     &IID_IMXReaderControl,
73     &IID_IMXWriter,
74 };
75
76 HRESULT get_typeinfo(enum tid_t tid, ITypeInfo **typeinfo)
77 {
78     HRESULT hres;
79
80     if(!typelib) {
81         ITypeLib *tl;
82
83         hres = LoadRegTypeLib(&LIBID_MSXML2, 3, 0, LOCALE_SYSTEM_DEFAULT, &tl);
84         if(FAILED(hres)) {
85             ERR("LoadRegTypeLib failed: %08x\n", hres);
86             return hres;
87         }
88
89         if(InterlockedCompareExchangePointer((void**)&typelib, tl, NULL))
90             ITypeLib_Release(tl);
91     }
92
93     if(!typeinfos[tid]) {
94         ITypeInfo *typeinfo;
95
96         hres = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &typeinfo);
97         if(FAILED(hres)) {
98             ERR("GetTypeInfoOfGuid failed: %08x\n", hres);
99             return hres;
100         }
101
102         if(InterlockedCompareExchangePointer((void**)(typeinfos+tid), typeinfo, NULL))
103             ITypeInfo_Release(typeinfo);
104     }
105
106     *typeinfo = typeinfos[tid];
107
108     ITypeInfo_AddRef(typeinfos[tid]);
109     return S_OK;
110 }
111
112 static CRITICAL_SECTION MSXML3_typelib_cs;
113 static CRITICAL_SECTION_DEBUG MSXML3_typelib_cs_debug =
114 {
115     0, 0, &MSXML3_typelib_cs,
116     { &MSXML3_typelib_cs_debug.ProcessLocksList,
117       &MSXML3_typelib_cs_debug.ProcessLocksList },
118       0, 0, { (DWORD_PTR)(__FILE__ ": MSXML3_typelib_cs") }
119 };
120 static CRITICAL_SECTION MSXML3_typelib_cs = { &MSXML3_typelib_cs_debug, -1, 0, 0, 0, 0 };
121
122 ITypeLib *get_msxml3_typelib( LPWSTR *path )
123 {
124     static WCHAR msxml3_path[MAX_PATH];
125
126     EnterCriticalSection( &MSXML3_typelib_cs );
127
128     if (!typelib)
129     {
130         TRACE("loading typelib\n");
131
132         if (GetModuleFileNameW( hInstance, msxml3_path, MAX_PATH ))
133             LoadTypeLib( msxml3_path, &typelib );
134     }
135
136     LeaveCriticalSection( &MSXML3_typelib_cs );
137
138     if (path)
139         *path = msxml3_path;
140
141     if (typelib)
142         ITypeLib_AddRef( typelib );
143
144     return typelib;
145 }
146
147 static void process_detach(void)
148 {
149     if(typelib) {
150         unsigned i;
151
152         for(i=0; i < sizeof(typeinfos)/sizeof(*typeinfos); i++)
153             if(typeinfos[i])
154                 ITypeInfo_Release(typeinfos[i]);
155
156         ITypeLib_Release(typelib);
157     }
158 }
159
160 HRESULT WINAPI DllCanUnloadNow(void)
161 {
162     FIXME("\n");
163     return S_FALSE;
164 }
165
166 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
167 {
168     switch(fdwReason)
169     {
170     case DLL_PROCESS_ATTACH:
171 #ifdef HAVE_LIBXML2
172         xmlInitParser();
173 #endif
174         hInstance = hInstDLL;
175         DisableThreadLibraryCalls(hInstDLL);
176         break;
177     case DLL_PROCESS_DETACH:
178 #ifdef HAVE_LIBXML2
179         xmlCleanupParser();
180         process_detach();
181 #endif
182         break;
183     }
184     return TRUE;
185 }