xml4com.cpp
上传用户:zhuqijet
上传日期:2013-06-25
资源大小:10074k
文件大小:12k
源码类别:

词法分析

开发平台:

Visual C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Xerces" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation, and was
  51.  * originally based on software copyright (c) 1999, International
  52.  * Business Machines, Inc., http://www.ibm.com .  For more information
  53.  * on the Apache Software Foundation, please see
  54.  * <http://www.apache.org/>.
  55.  */
  56. /*
  57.  * $Log: xml4com.cpp,v $
  58.  * Revision 1.2  2002/05/21 19:53:53  tng
  59.  * DOM Reorganization: update include path for the old DOM interface in COM files
  60.  *
  61.  * Revision 1.1.1.1  2002/02/01 22:21:40  peiyongz
  62.  * sane_include
  63.  *
  64.  * Revision 1.6  2001/05/11 13:25:08  tng
  65.  * Copyright update.
  66.  *
  67.  * Revision 1.5  2001/01/19 15:18:39  tng
  68.  * COM Updates by Curt Arnold: changed 1.3 to 1.4, updated the GUID's so
  69.  * both can coexist and fixed a new minor bugs.  Most of the changes involved
  70.  * error reporting, now a DOM defined error will return an HRESULT of
  71.  * 0x80040600 + code and will set an error description to the error name.
  72.  *
  73.  * Revision 1.4  2000/06/19 20:05:59  rahulj
  74.  * Changes for increased conformance and stability. Submitted by
  75.  * Curt.Arnold@hyprotech.com. Verified by Joe Polastre.
  76.  *
  77.  * Revision 1.3  2000/06/03 00:29:04  andyh
  78.  * COM Wrapper changes from Curt Arnold
  79.  *
  80.  * Revision 1.2  2000/03/30 02:00:12  abagchi
  81.  * Initial checkin of working code with Copyright Notice
  82.  *
  83.  */
  84. // xml4com.cpp : Implementation of DLL Exports.
  85. // Note: Proxy/Stub Information
  86. //      To merge the proxy/stub code into the object DLL, add the file
  87. //      dlldatax.c to the project.  Make sure precompiled headers
  88. //      are turned off for this file, and add _MERGE_PROXYSTUB to the
  89. //      defines for the project.
  90. //
  91. //      If you are not running WinNT4.0 or Win95 with DCOM, then you
  92. //      need to remove the following define from dlldatax.c
  93. //      #define _WIN32_WINNT 0x0400
  94. //
  95. //      Further, if you are running MIDL without /Oicf switch, you also
  96. //      need to remove the following define from dlldatax.c.
  97. //      #define USE_STUBLESS_PROXY
  98. //
  99. //      Modify the custom build rule for xml4com.idl by adding the following
  100. //      files to the Outputs.
  101. //          xml4com_p.c
  102. //          dlldata.c
  103. //      To build a separate proxy/stub DLL,
  104. //      run nmake -f xml4comps.mk in the project directory.
  105. #include "stdafx.h"
  106. #include "resource.h"
  107. #include <initguid.h>
  108. #include <xercesc/util/PlatformUtils.hpp>
  109. #include "xml4com.h"
  110. #include <xercesc/dom/deprecated/DOM_DOMException.hpp>
  111. //
  112. //
  113. //    These were extracted from an identifier definition file
  114. //       generated by compiling MSXML.IDL using the MIDL compiler
  115. //        (and removing CLSID_DOMDocument, CLSID_XMLHttpRequest, et al)
  116. //
  117. const IID LIBID_MSXML = {0xd63e0ce2,0xa0a2,0x11d0,{0x9c,0x02,0x00,0xc0,0x4f,0xc9,0x9c,0x8e}};
  118. const IID IID_IXMLDOMImplementation = {0x2933BF8F,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  119. const IID IID_IXMLDOMNode = {0x2933BF80,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  120. const IID IID_IXMLDOMDocumentFragment = {0x3efaa413,0x272f,0x11d2,{0x83,0x6f,0x00,0x00,0xf8,0x7a,0x77,0x82}};
  121. const IID IID_IXMLDOMDocument = {0x2933BF81,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  122. const IID IID_IXMLDOMNodeList = {0x2933BF82,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  123. const IID IID_IXMLDOMNamedNodeMap = {0x2933BF83,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  124. const IID IID_IXMLDOMCharacterData = {0x2933BF84,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  125. const IID IID_IXMLDOMAttribute = {0x2933BF85,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  126. const IID IID_IXMLDOMElement = {0x2933BF86,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  127. const IID IID_IXMLDOMText = {0x2933BF87,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  128. const IID IID_IXMLDOMComment = {0x2933BF88,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  129. const IID IID_IXMLDOMProcessingInstruction = {0x2933BF89,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  130. const IID IID_IXMLDOMCDATASection = {0x2933BF8A,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  131. const IID IID_IXMLDOMDocumentType = {0x2933BF8B,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  132. const IID IID_IXMLDOMNotation = {0x2933BF8C,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  133. const IID IID_IXMLDOMEntity = {0x2933BF8D,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  134. const IID IID_IXMLDOMEntityReference = {0x2933BF8E,0x7B36,0x11d2,{0xB2,0x0E,0x00,0xC0,0x4F,0x98,0x3E,0x60}};
  135. const IID IID_IXMLDOMParseError = {0x3efaa426,0x272f,0x11d2,{0x83,0x6f,0x00,0x00,0xf8,0x7a,0x77,0x82}};
  136. const IID IID_IXTLRuntime = {0x3efaa425,0x272f,0x11d2,{0x83,0x6f,0x00,0x00,0xf8,0x7a,0x77,0x82}};
  137. const IID DIID_XMLDOMDocumentEvents = {0x3efaa427,0x272f,0x11d2,{0x83,0x6f,0x00,0x00,0xf8,0x7a,0x77,0x82}};
  138. const IID IID_IXMLHttpRequest = {0xED8C108D,0x4349,0x11D2,{0x91,0xA4,0x00,0xC0,0x4F,0x79,0x69,0xE8}};
  139. const IID IID_IXMLDSOControl = {0x310afa62,0x0575,0x11d2,{0x9c,0xa9,0x00,0x60,0xb0,0xec,0x3d,0x39}};
  140. const IID IID_IXMLElementCollection = {0x65725580,0x9B5D,0x11d0,{0x9B,0xFE,0x00,0xC0,0x4F,0xC9,0x9C,0x8E}};
  141. const IID IID_IXMLDocument = {0xF52E2B61,0x18A1,0x11d1,{0xB1,0x05,0x00,0x80,0x5F,0x49,0x91,0x6B}};
  142. const IID IID_IXMLDocument2 = {0x2B8DE2FE,0x8D2D,0x11d1,{0xB2,0xFC,0x00,0xC0,0x4F,0xD9,0x15,0xA9}};
  143. const IID IID_IXMLElement = {0x3F7F31AC,0xE15F,0x11d0,{0x9C,0x25,0x00,0xC0,0x4F,0xC9,0x9C,0x8E}};
  144. const IID IID_IXMLElement2 = {0x2B8DE2FF,0x8D2D,0x11d1,{0xB2,0xFC,0x00,0xC0,0x4F,0xD9,0x15,0xA9}};
  145. const IID IID_IXMLAttribute = {0xD4D4A0FC,0x3B73,0x11d1,{0xB2,0xB4,0x00,0xC0,0x4F,0xB9,0x25,0x96}};
  146. const IID IID_IXMLError = {0x948C5AD3,0xC58D,0x11d0,{0x9C,0x0B,0x00,0xC0,0x4F,0xC9,0x9C,0x8E}};
  147. //
  148. //   This file is generated from the type library compilation
  149. //       of xml4com.idl
  150. //
  151. #include "xml4com_i.c"
  152. #include "XMLDOMDocument.h"
  153. #include "XMLHTTPRequest.h"
  154. #ifdef _MERGE_PROXYSTUB
  155. extern "C" HINSTANCE hProxyDll;
  156. #endif
  157. CComModule _Module;
  158. BEGIN_OBJECT_MAP(ObjectMap)
  159. OBJECT_ENTRY(CLSID_DOMDocument, CXMLDOMDocument)
  160. OBJECT_ENTRY(CLSID_XMLHTTPRequest, CXMLHttpRequest)
  161. END_OBJECT_MAP()
  162. /////////////////////////////////////////////////////////////////////////////
  163. // DLL Entry Point
  164. extern "C"
  165. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  166. {
  167.     lpReserved;
  168. #ifdef _MERGE_PROXYSTUB
  169.     if (!PrxDllMain(hInstance, dwReason, lpReserved))
  170.         return FALSE;
  171. #endif
  172.     if (dwReason == DLL_PROCESS_ATTACH)
  173.     {
  174.         _Module.Init(ObjectMap, hInstance, &LIBID_Xerces);
  175.         DisableThreadLibraryCalls(hInstance);
  176. XMLPlatformUtils::Initialize();
  177.     }
  178.     else if (dwReason == DLL_PROCESS_DETACH)
  179.         _Module.Term();
  180.     return TRUE;    // ok
  181. }
  182. /////////////////////////////////////////////////////////////////////////////
  183. // Used to determine whether the DLL can be unloaded by OLE
  184. STDAPI DllCanUnloadNow(void)
  185. {
  186. #ifdef _MERGE_PROXYSTUB
  187.     if (PrxDllCanUnloadNow() != S_OK)
  188.         return S_FALSE;
  189. #endif
  190.     return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  191. }
  192. /////////////////////////////////////////////////////////////////////////////
  193. // Returns a class factory to create an object of the requested type
  194. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  195. {
  196. #ifdef _MERGE_PROXYSTUB
  197.     if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  198.         return S_OK;
  199. #endif
  200.     return _Module.GetClassObject(rclsid, riid, ppv);
  201. }
  202. /////////////////////////////////////////////////////////////////////////////
  203. // DllRegisterServer - Adds entries to the system registry
  204. STDAPI DllRegisterServer(void)
  205. {
  206. #ifdef _MERGE_PROXYSTUB
  207.     HRESULT hRes = PrxDllRegisterServer();
  208.     if (FAILED(hRes))
  209.         return hRes;
  210. #endif
  211.     // registers object, typelib and all interfaces in typelib
  212.     return _Module.RegisterServer(TRUE);
  213. }
  214. /////////////////////////////////////////////////////////////////////////////
  215. // DllUnregisterServer - Removes entries from the system registry
  216. STDAPI DllUnregisterServer(void)
  217. {
  218. #ifdef _MERGE_PROXYSTUB
  219.     PrxDllUnregisterServer();
  220. #endif
  221.     return _Module.UnregisterServer(TRUE);
  222. }
  223. static LPOLESTR Msgs[] =
  224. {
  225. OLESTR("UNDEFINED DOM ERROR"),
  226. OLESTR("INDEX_SIZE_ERR"),   // INDEX_SIZE_ERR =  1
  227. OLESTR("DOMSTRING_SIZE_ERR"),  // DOMSTRING_SIZE_ERR =  2
  228. OLESTR("HIERARCHY_REQUEST_ERR"),   // HIERARCHY_REQUEST_ERR =  3
  229. OLESTR("WRONG_DOCUMENT_ERR"),   // WRONG_DOCUMENT_ERR =  4
  230. OLESTR("INVALID_CHARACTER_ERR"),   // INVALID_CHARACTER_ERR =  5
  231. OLESTR("NO_DATA_ALLOWED_ERR"),   // NO_DATA_ALLOWED_ERR =  6
  232. OLESTR("NO_MODIFICATION_ALLOWED_ERR"),   // NO_MODIFICATION_ALLOWED_ERR =  7
  233. OLESTR("NOT_FOUND_ERR"),   // NOT_FOUND_ERR =  8
  234. OLESTR("NOT_SUPPORTED_ERR"),   // NOT_SUPPORTED_ERR =  9
  235. OLESTR("INUSE_ATTRIBUTE_ERR"),   // INUSE_ATTRIBUTE_ERR =  10
  236. OLESTR("INVALID_STATE_ERR"),   // INVALID_STATE_ERR =  11
  237. OLESTR("SYNTAX_ERR "),   //  SYNTAX_ERR  =  12
  238. OLESTR("INVALID_MODIFICATION_ERR"),   //  INVALID_MODIFICATION_ERR =  13
  239. OLESTR("NAMESPACE_ERR"),   //  NAMESPACE_ERR  =  14
  240. OLESTR("INVALID_ACCESS_ERR") // INVALID_ACCESS_ERR   = 15
  241. };
  242. //
  243. //
  244. //   makes an HRESULT with a code based on the DOM error code
  245. //
  246. HRESULT MakeHRESULT(DOM_DOMException& ex)
  247. {
  248. ICreateErrorInfo* pCErr = NULL;
  249. HRESULT sc = CreateErrorInfo(&pCErr);
  250. if(SUCCEEDED(sc)) {
  251. DOMString msg = ex.msg;
  252. if(msg == NULL)
  253. {
  254. if(ex.code >= DOM_DOMException::INDEX_SIZE_ERR &&
  255. ex.code <= DOM_DOMException::INVALID_ACCESS_ERR)
  256. {
  257. sc = pCErr->SetDescription(Msgs[ex.code]);
  258. }
  259. else
  260. {
  261. sc = pCErr->SetDescription(Msgs[0]);
  262. }
  263. }
  264. else
  265. {
  266. sc = pCErr->SetDescription((BSTR) ex.msg.rawBuffer());
  267. }
  268. IErrorInfo* pErr = NULL;
  269. sc = pCErr->QueryInterface(IID_IErrorInfo,(void**) &pErr);
  270. if(SUCCEEDED(sc))
  271. {
  272. sc = SetErrorInfo(0,pErr);
  273. pErr->Release();
  274. }
  275. pCErr->Release();
  276. }
  277. return 0x80040600 + ex.code;
  278. }