运行msdn上的例子碰到错误,no GUID has been associated with this object, 不知道什么原因,请教~

rambooo 2008-07-07 04:49:20
运行msdn上的例子碰到错误,
Error 1 error C2787: 'DOMDocument60' : no GUID has been associated with this object f:\learning\c_c++_c#\experiment_main\msxml\msxml\msxml.cpp 43

不知道什么原因,请教~


// LoadDomRaw.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <objbase.h>
#include <msxml6.h>

// Macro that calls a COM method returning HRESULT value:
#define HRCALL(a, errmsg) \
do { \
hr = (a); \
if (FAILED(hr)) { \
dprintf( "%s:%d HRCALL Failed: %s\n 0x%.8x = %s\n", \
__FILE__, __LINE__, errmsg, hr, #a ); \
goto clean; \
} \
} while (0)

// Helper function that put output in stdout and debug window
// in Visual Studio:
void dprintf( char * format, ...)
{
static char buf[1024];
va_list args;
va_start( args, format );
vsprintf_s( buf, format, args );
va_end( args);
OutputDebugStringA( buf);
printf("%s", buf);
}

// Helper function to create a DOM instance:
IXMLDOMDocument * DomFromCOM()
{
HRESULT hr;
IXMLDOMDocument *pxmldoc = NULL;

HRCALL( CoCreateInstance(__uuidof(DOMDocument60),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(IXMLDOMDocument),
(void**)&pxmldoc),
"Create a new DOMDocument");

HRCALL( pxmldoc->put_async(VARIANT_FALSE),
"should never fail");
HRCALL( pxmldoc->put_validateOnParse(VARIANT_FALSE),
"should never fail");
HRCALL( pxmldoc->put_resolveExternals(VARIANT_FALSE),
"should never fail");

return pxmldoc;
clean:
if (pxmldoc)
{
pxmldoc->Release();
}
return NULL;
}


int _tmain(int argc, _TCHAR* argv[])
{
IXMLDOMDocument *pXMLDom=NULL;
IXMLDOMParseError *pXMLErr=NULL;
BSTR bstr = NULL;
VARIANT_BOOL status;
VARIANT var;
HRESULT hr;

CoInitialize(NULL);

pXMLDom = DomFromCOM();
if (!pXMLDom) goto clean;

VariantInit(&var);
V_BSTR(&var) = SysAllocString(L"stocks.xml");
V_VT(&var) = VT_BSTR;
HRCALL(pXMLDom->load(var, &status), "");

if (status!=VARIANT_TRUE) {
HRCALL(pXMLDom->get_parseError(&pXMLErr),"");
HRCALL(pXMLErr->get_reason(&bstr),"");
dprintf("Failed to load DOM from stocks.xml. %S\n",
bstr);
goto clean;
}
HRCALL(pXMLDom->get_xml(&bstr), "");
dprintf("XML DOM loaded from stocks.xml:\n%S\n",bstr);

clean:
if (bstr) SysFreeString(bstr);
if (&var) VariantClear(&var);
if (pXMLErr) pXMLErr->Release();
if (pXMLDom) pXMLDom->Release();

CoUninitialize();
return 0;
}

...全文
358 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
shaq001 2008-07-19
  • 打赏
  • 举报
回复
参考这篇:
http://www.pcreview.co.uk/forums/thread-1429635.php
jy01807853 2008-07-08
  • 打赏
  • 举报
回复

//楼主只要你不在VC6上编译就没问题

// LoadDomRaw.cpp : Defines the entry point for the console application.
//

#include <objbase.h>
#include <msxml6.h>
#include <stdio.h>
#include <tchar.h>



// Macro that calls a COM method returning HRESULT value:
#define HRCALL(a, errmsg) \
do { \
hr = (a); \
if (FAILED(hr)) { \
dprintf( "%s:%d HRCALL Failed: %s\n 0x%.8x = %s\n", \
__FILE__, __LINE__, errmsg, hr, #a ); \
goto clean; \
} \
} while (0)

// Helper function that put output in stdout and debug window
// in Visual Studio:
void dprintf( char * format, ...)
{
static char buf[1024];
va_list args;
va_start( args, format );
vsprintf_s( buf, format, args );
va_end( args);
OutputDebugStringA( buf);
printf("%s", buf);
}

// Helper function to create a DOM instance:
IXMLDOMDocument * DomFromCOM()
{
HRESULT hr;
IXMLDOMDocument *pxmldoc = NULL;

HRCALL( CoCreateInstance(__uuidof(DOMDocument60),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(IXMLDOMDocument),
(void**)&pxmldoc),
"Create a new DOMDocument");

HRCALL( pxmldoc->put_async(VARIANT_FALSE),
"should never fail");
HRCALL( pxmldoc->put_validateOnParse(VARIANT_FALSE),
"should never fail");
HRCALL( pxmldoc->put_resolveExternals(VARIANT_FALSE),
"should never fail");

return pxmldoc;
clean:
if (pxmldoc)
{
pxmldoc->Release();
}
return NULL;
}


int _tmain(int argc, _TCHAR* argv[])
{
IXMLDOMDocument *pXMLDom=NULL;
IXMLDOMParseError *pXMLErr=NULL;
BSTR bstr = NULL;
VARIANT_BOOL status;
VARIANT var;
HRESULT hr;

CoInitialize(NULL);

pXMLDom = DomFromCOM();
if (!pXMLDom) goto clean;

VariantInit(&var);
V_BSTR(&var) = SysAllocString(L"stocks.xml");
V_VT(&var) = VT_BSTR;
HRCALL(pXMLDom->load(var, &status), "");

if (status!=VARIANT_TRUE) {
HRCALL(pXMLDom->get_parseError(&pXMLErr),"");
HRCALL(pXMLErr->get_reason(&bstr),"");
dprintf("Failed to load DOM from stocks.xml. %S\n",
bstr);
goto clean;
}
HRCALL(pXMLDom->get_xml(&bstr), "");
dprintf("XML DOM loaded from stocks.xml:\n%S\n",bstr);

clean:
if (bstr) SysFreeString(bstr);
if (&var) VariantClear(&var);
if (pXMLErr) pXMLErr->Release();
if (pXMLDom) pXMLDom->Release();

CoUninitialize();
return 0;
}

iu_81 2008-07-07
  • 打赏
  • 举报
回复
由于<shlobj.h>文件同vc6.0下不同
leo201592 2008-07-07
  • 打赏
  • 举报
回复
DOMDocument60哪里定义的啊? 或则你的组件没有注册。

64,676

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧