开发者

CoCreateInstance - The COM+ registry database detected a system error

In a small test project I have this code:

HRESULT hr = CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_ALL, __uuidof( IXMLDOMDocument ), ( void ** ) & m_pDoc);
if ( hr != S_OK )
{
  thr开发者_C百科ow "MSXML DOM Document could not be created";
}

This compiles and runs without problems. In another project the same code fails with:

hr = 0x80110474 The COM+ registry database detected a system error

Both projects are C++ compiled using Visual Studio 2010. I've been through and compared settings side-by-side between the two projects to try and determine what difference could be causing this issue. So far I can see no reason why the test project runs and the other project fails.

Edit - Full sample code listing:

#include "stdafx.h"
#include <atlbase.h>
#include <atlconv.h>
#include "MsXml.h"
int _tmain(int argc, _TCHAR* argv[])
{
    IXMLDOMDocument* m_pDoc = NULL;
    if(FAILED(CoInitializeEx( 0, COINIT_MULTITHREADED )))
      if(FAILED(CoInitializeEx( 0, COINIT_APARTMENTTHREADED )))
        throw "Could not initialize COM";
    HRESULT hr = CoCreateInstance( CLSID_DOMDocument, NULL, CLSCTX_ALL, __uuidof( IXMLDOMDocument ), ( void ** ) & m_pDoc);
    if ( hr != S_OK )
      throw "MSXML DOM Document could not be created";
    return 0;
}


Found a solution, although not ideal it solved the problem. I created a new project and manually imported the settings.


I've got the same problem with Turbo Delphi: the same code with CoCreateInstance() works in one project and fails in another one with HR=80110474 (COMADMIN_E_REGDB_SYSTEMERR). It was caused by IDE overriding environment variables which are stored in project settings. So it fails only when being runned under IDE (regardless of debugging state). Cleaning up project settings resolves the problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜