到底是怎么回事?
cannot instantiate abstract class due to following members:
long __stdcall MSXML2::ISAXContentHandler::startPrefixMapping(unsigned short *,int,unsigned short *,int)' : pure virtual function was not defined
出错的地方
DNContent * pMc = new DNContent();
13 个解决方案
#1
什么是纯虚函数??
#2
这个类是一个纯虚基类,其中的startPrefixMapping是纯虚函数,类似如下声明:
long _stdcall startPrefixMapping(unsigned short*, int, unsigned short*, int) = 0;
也就是此函数只有类型声明没有实体,而且继承的类必须重载这个函数!
纯虚基类是不能实例化的,必须自己继承一个类,并将上面的函数重载,声明执行的部分!
如
class myclass:public ISAXContentHandler
{
long _stdcall startPrefixMapping(unsigned short*, int, unsigned short*, int)
{
// do something;
return 0;
}
}
不过这个类看样子是嵌套类,你需要头文件仔细看一下!不过你的类又是一个接口声明,似乎你不应当使用这个类,应该有现成的继承类可以使用!
long _stdcall startPrefixMapping(unsigned short*, int, unsigned short*, int) = 0;
也就是此函数只有类型声明没有实体,而且继承的类必须重载这个函数!
纯虚基类是不能实例化的,必须自己继承一个类,并将上面的函数重载,声明执行的部分!
如
class myclass:public ISAXContentHandler
{
long _stdcall startPrefixMapping(unsigned short*, int, unsigned short*, int)
{
// do something;
return 0;
}
}
不过这个类看样子是嵌套类,你需要头文件仔细看一下!不过你的类又是一个接口声明,似乎你不应当使用这个类,应该有现成的继承类可以使用!
#3
代码如下:
帮帮忙看怎么处理:
DNContent.h
#import <msxml3.dll> raw_interfaces_only // We use this library.
using namespace MSXML2; // and everything for SAX is in this namespace
class DNContent : public ISAXContentHandler
{
public:
// IUnknown
long __stdcall QueryInterface(const struct _GUID &,void ** );
unsigned long __stdcall AddRef(void);
unsigned long __stdcall Release(void);
// Define constructor and destructor.
DNContent();
virtual ~DNContent();
// ISAXContentHandler
virtual HRESULT STDMETHODCALLTYPE putDocumentLocator(
/* [in] */ ISAXLocator __RPC_FAR *pLocator);
virtual HRESULT STDMETHODCALLTYPE startDocument(void);
virtual HRESULT STDMETHODCALLTYPE endDocument(void);
virtual HRESULT STDMETHODCALLTYPE startPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri);
virtual HRESULT STDMETHODCALLTYPE endPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix);
virtual HRESULT STDMETHODCALLTYPE startElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes);
virtual HRESULT STDMETHODCALLTYPE endElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName);
virtual HRESULT STDMETHODCALLTYPE characters(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
virtual HRESULT STDMETHODCALLTYPE ignorableWhitespace(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
virtual HRESULT STDMETHODCALLTYPE processingInstruction(
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData);
virtual HRESULT STDMETHODCALLTYPE skippedEntity(
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName);
// ...and add whatever you like to simplify implementation.
private:
void prt ( wchar_t * pwchFmt, const wchar_t __RPC_FAR *pwchVal,
int cchVal);
};
DNContent.cpp
#include "stdafx.h" // We need the headers...
#include <stdio.h>
#include <stdlib.h>
#include "DNContent.h"
// Usually there is nothing to do in constructors and destructors,
// but if so, do it here.
DNContent::DNContent() {}
DNContent::~DNContent() {}
// Now finish the IUnknown stuff.
// (However, keep in mind that if you want to implement handlers as COM
// objects, you can add more functionality than shown with these
// methods.)
long __stdcall DNContent::QueryInterface(const struct _GUID &,void ** )
{ return 0; }
unsigned long __stdcall DNContent::AddRef() { return 0; }
unsigned long __stdcall DNContent::Release() { return 0; }
// "prt" is a private method.
// SAX does not use it. You don't have to implement it or any other
// private methods.
// This one is just quick print.
void DNContent::prt ( wchar_t * pwchFmt, const wchar_t __RPC_FAR *pwchVal,
int cchVal )
{
static wchar_t val[1000];
cchVal = cchVal>999 ? 999 : cchVal;
wcsncpy( val, pwchVal, cchVal ); val[cchVal] = 0;
wprintf(pwchFmt,val);
}
// Finish the ISAXContentHandler
HRESULT STDMETHODCALLTYPE DNContent::putDocumentLocator(
/* [in] */ ISAXLocator __RPC_FAR *pLocator)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::startDocument(void)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::endDocument(void)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::startElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes)
{
// I want to print the tag name.
prt(L"\n<%s>",pwchLocalName,cchLocalName);
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::endElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::startPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::endPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::characters(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::ignorableWhitespace(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::processingInstruction(
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::skippedEntity(
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName)
{
return S_OK;
}
帮帮忙看怎么处理:
DNContent.h
#import <msxml3.dll> raw_interfaces_only // We use this library.
using namespace MSXML2; // and everything for SAX is in this namespace
class DNContent : public ISAXContentHandler
{
public:
// IUnknown
long __stdcall QueryInterface(const struct _GUID &,void ** );
unsigned long __stdcall AddRef(void);
unsigned long __stdcall Release(void);
// Define constructor and destructor.
DNContent();
virtual ~DNContent();
// ISAXContentHandler
virtual HRESULT STDMETHODCALLTYPE putDocumentLocator(
/* [in] */ ISAXLocator __RPC_FAR *pLocator);
virtual HRESULT STDMETHODCALLTYPE startDocument(void);
virtual HRESULT STDMETHODCALLTYPE endDocument(void);
virtual HRESULT STDMETHODCALLTYPE startPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri);
virtual HRESULT STDMETHODCALLTYPE endPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix);
virtual HRESULT STDMETHODCALLTYPE startElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes);
virtual HRESULT STDMETHODCALLTYPE endElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName);
virtual HRESULT STDMETHODCALLTYPE characters(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
virtual HRESULT STDMETHODCALLTYPE ignorableWhitespace(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
virtual HRESULT STDMETHODCALLTYPE processingInstruction(
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData);
virtual HRESULT STDMETHODCALLTYPE skippedEntity(
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName);
// ...and add whatever you like to simplify implementation.
private:
void prt ( wchar_t * pwchFmt, const wchar_t __RPC_FAR *pwchVal,
int cchVal);
};
DNContent.cpp
#include "stdafx.h" // We need the headers...
#include <stdio.h>
#include <stdlib.h>
#include "DNContent.h"
// Usually there is nothing to do in constructors and destructors,
// but if so, do it here.
DNContent::DNContent() {}
DNContent::~DNContent() {}
// Now finish the IUnknown stuff.
// (However, keep in mind that if you want to implement handlers as COM
// objects, you can add more functionality than shown with these
// methods.)
long __stdcall DNContent::QueryInterface(const struct _GUID &,void ** )
{ return 0; }
unsigned long __stdcall DNContent::AddRef() { return 0; }
unsigned long __stdcall DNContent::Release() { return 0; }
// "prt" is a private method.
// SAX does not use it. You don't have to implement it or any other
// private methods.
// This one is just quick print.
void DNContent::prt ( wchar_t * pwchFmt, const wchar_t __RPC_FAR *pwchVal,
int cchVal )
{
static wchar_t val[1000];
cchVal = cchVal>999 ? 999 : cchVal;
wcsncpy( val, pwchVal, cchVal ); val[cchVal] = 0;
wprintf(pwchFmt,val);
}
// Finish the ISAXContentHandler
HRESULT STDMETHODCALLTYPE DNContent::putDocumentLocator(
/* [in] */ ISAXLocator __RPC_FAR *pLocator)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::startDocument(void)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::endDocument(void)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::startElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes)
{
// I want to print the tag name.
prt(L"\n<%s>",pwchLocalName,cchLocalName);
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::endElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::startPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::endPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::characters(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::ignorableWhitespace(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::processingInstruction(
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::skippedEntity(
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName)
{
return S_OK;
}
#4
另外,namespace是干什么用的?
#5
另:纯虚函数就是一个函数在声明时其后有 = 0;的写法,不可写函数执行体!
#6
谁能给我说说,有关接口的知识?
#7
Holly,从我贴出来的代码能看出问题吗?
#8
我已经重载那些虚函数了
怎么还报错??
怎么还报错??
#9
namespace相当于一个用来识别在不同名字空间相同函数或变量声明的一种新的C++语法,基本上起到了将属于该名字空间的所有声明加一个身份识别!
如:
//mydeclare1.h中:
namespace declare1
{
class myclass{int a;};
void myfunc();
int myvar;
}
//mydeclare2.h中
namespace declare2
{
class myclass{int a;};
void myfunc();
int myvar;
}
//myexec.cpp中
#include "mydeclare1.h"
#include "mydeclare2.h"
...
declare1::myclass a;
declare2::myclass b;
...
此时不会有redefine的错误出现!
你的问题没有明确,不过估计是ISAXContentHandler类中还有一个函数声明为:
virtual
HRESULT STDMETHODCALLTYPE startPrefixMapping(
/* [in] */ wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri) = 0;
请注意没有const,你在将ISAXContentHandler的头文件找来看看!
如:
//mydeclare1.h中:
namespace declare1
{
class myclass{int a;};
void myfunc();
int myvar;
}
//mydeclare2.h中
namespace declare2
{
class myclass{int a;};
void myfunc();
int myvar;
}
//myexec.cpp中
#include "mydeclare1.h"
#include "mydeclare2.h"
...
declare1::myclass a;
declare2::myclass b;
...
此时不会有redefine的错误出现!
你的问题没有明确,不过估计是ISAXContentHandler类中还有一个函数声明为:
virtual
HRESULT STDMETHODCALLTYPE startPrefixMapping(
/* [in] */ wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri) = 0;
请注意没有const,你在将ISAXContentHandler的头文件找来看看!
#10
namespace 是用来区分相同的名字的函数、类或变量的声明的!
如
namespace mydeclare1
{
void myfunc(){}
}
namespace mydeclare2
{
void myfunc(){}
}
....
mydeclare1::myfunc()
mydeclare2::myfunc()
...
如
namespace mydeclare1
{
void myfunc(){}
}
namespace mydeclare2
{
void myfunc(){}
}
....
mydeclare1::myfunc()
mydeclare2::myfunc()
...
#11
namespace 有一点类似于class的声明,就是名字作用域,但它没有class的继承和成员等特性;
如:
namespace MyDeclare1
{
class MyClass
{
int a;
}
void MyFunc(){};
DWORD dwVar;
}
namespace MyDeclare2
{
class MyClass
{
int a;
}
void MyFunc(){};
DWORD dwVar;
}
那么有
MyDeclare1::MyFunc();
MyDeclare2::MyFunc();
虽然有两个MyFunc()但并不导致重定义!因为有了名字空间的识别!
如:
namespace MyDeclare1
{
class MyClass
{
int a;
}
void MyFunc(){};
DWORD dwVar;
}
namespace MyDeclare2
{
class MyClass
{
int a;
}
void MyFunc(){};
DWORD dwVar;
}
那么有
MyDeclare1::MyFunc();
MyDeclare2::MyFunc();
虽然有两个MyFunc()但并不导致重定义!因为有了名字空间的识别!
#12
Sorry,服务器故障,贴多了!
#13
果然,去掉const就好了
可是在 msxml.h中是有const的,另外我发现编译的时候目录下多了一个文件msxml.tlh
每次编译都会改变,它是干什么用的?里面是一些接口的定义,其中也有 ISAXContentHandler的定义,他们怎么就不一样呢??
//////////////msxml.h/////////////////////////////////////
#ifndef __ISAXContentHandler_INTERFACE_DEFINED__
#define __ISAXContentHandler_INTERFACE_DEFINED__
/* interface ISAXContentHandler */
/* [unique][helpstring][uuid][local][object][hidden] */
EXTERN_C const IID IID_ISAXContentHandler;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("1545cdfa-9e4e-4497-a8a4-2bf7d0112c44")
ISAXContentHandler : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE putDocumentLocator(
/* [in] */ ISAXLocator __RPC_FAR *pLocator) = 0;
virtual HRESULT STDMETHODCALLTYPE startDocument( void) = 0;
virtual HRESULT STDMETHODCALLTYPE endDocument( void) = 0;
virtual HRESULT STDMETHODCALLTYPE startPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri) = 0;
virtual HRESULT STDMETHODCALLTYPE endPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix) = 0;
virtual HRESULT STDMETHODCALLTYPE startElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes) = 0;
virtual HRESULT STDMETHODCALLTYPE endElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName) = 0;
virtual HRESULT STDMETHODCALLTYPE characters(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars) = 0;
virtual HRESULT STDMETHODCALLTYPE ignorableWhitespace(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars) = 0;
virtual HRESULT STDMETHODCALLTYPE processingInstruction(
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData) = 0;
virtual HRESULT STDMETHODCALLTYPE skippedEntity(
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName) = 0;
};
#else /* C style interface */
typedef struct ISAXContentHandlerVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *QueryInterface )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ REFIID riid,
/* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
ULONG ( STDMETHODCALLTYPE __RPC_FAR *AddRef )(
ISAXContentHandler __RPC_FAR * This);
ULONG ( STDMETHODCALLTYPE __RPC_FAR *Release )(
ISAXContentHandler __RPC_FAR * This);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *putDocumentLocator )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ ISAXLocator __RPC_FAR *pLocator);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *startDocument )(
ISAXContentHandler __RPC_FAR * This);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *endDocument )(
ISAXContentHandler __RPC_FAR * This);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *startPrefixMapping )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *endPrefixMapping )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *startElement )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *endElement )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *characters )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *ignorableWhitespace )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *processingInstruction )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *skippedEntity )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName);
END_INTERFACE
} ISAXContentHandlerVtbl;
interface ISAXContentHandler
{
CONST_VTBL struct ISAXContentHandlerVtbl __RPC_FAR *lpVtbl;
};
/////////////////msxml.tlh//////////////////////////////
struct __declspec(uuid("1545cdfa-9e4e-4497-a8a4-2bf7d0112c44"))
ISAXContentHandler : IUnknown
{
//
// Raw methods provided by interface
//
virtual HRESULT __stdcall putDocumentLocator (
struct ISAXLocator * pLocator ) = 0;
virtual HRESULT __stdcall startDocument ( ) = 0;
virtual HRESULT __stdcall endDocument ( ) = 0;
virtual HRESULT __stdcall startPrefixMapping (
unsigned short * pwchPrefix,
int cchPrefix,
unsigned short * pwchUri,
......
可是在 msxml.h中是有const的,另外我发现编译的时候目录下多了一个文件msxml.tlh
每次编译都会改变,它是干什么用的?里面是一些接口的定义,其中也有 ISAXContentHandler的定义,他们怎么就不一样呢??
//////////////msxml.h/////////////////////////////////////
#ifndef __ISAXContentHandler_INTERFACE_DEFINED__
#define __ISAXContentHandler_INTERFACE_DEFINED__
/* interface ISAXContentHandler */
/* [unique][helpstring][uuid][local][object][hidden] */
EXTERN_C const IID IID_ISAXContentHandler;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("1545cdfa-9e4e-4497-a8a4-2bf7d0112c44")
ISAXContentHandler : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE putDocumentLocator(
/* [in] */ ISAXLocator __RPC_FAR *pLocator) = 0;
virtual HRESULT STDMETHODCALLTYPE startDocument( void) = 0;
virtual HRESULT STDMETHODCALLTYPE endDocument( void) = 0;
virtual HRESULT STDMETHODCALLTYPE startPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri) = 0;
virtual HRESULT STDMETHODCALLTYPE endPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix) = 0;
virtual HRESULT STDMETHODCALLTYPE startElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes) = 0;
virtual HRESULT STDMETHODCALLTYPE endElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName) = 0;
virtual HRESULT STDMETHODCALLTYPE characters(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars) = 0;
virtual HRESULT STDMETHODCALLTYPE ignorableWhitespace(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars) = 0;
virtual HRESULT STDMETHODCALLTYPE processingInstruction(
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData) = 0;
virtual HRESULT STDMETHODCALLTYPE skippedEntity(
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName) = 0;
};
#else /* C style interface */
typedef struct ISAXContentHandlerVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *QueryInterface )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ REFIID riid,
/* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
ULONG ( STDMETHODCALLTYPE __RPC_FAR *AddRef )(
ISAXContentHandler __RPC_FAR * This);
ULONG ( STDMETHODCALLTYPE __RPC_FAR *Release )(
ISAXContentHandler __RPC_FAR * This);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *putDocumentLocator )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ ISAXLocator __RPC_FAR *pLocator);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *startDocument )(
ISAXContentHandler __RPC_FAR * This);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *endDocument )(
ISAXContentHandler __RPC_FAR * This);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *startPrefixMapping )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *endPrefixMapping )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *startElement )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *endElement )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *characters )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *ignorableWhitespace )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *processingInstruction )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *skippedEntity )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName);
END_INTERFACE
} ISAXContentHandlerVtbl;
interface ISAXContentHandler
{
CONST_VTBL struct ISAXContentHandlerVtbl __RPC_FAR *lpVtbl;
};
/////////////////msxml.tlh//////////////////////////////
struct __declspec(uuid("1545cdfa-9e4e-4497-a8a4-2bf7d0112c44"))
ISAXContentHandler : IUnknown
{
//
// Raw methods provided by interface
//
virtual HRESULT __stdcall putDocumentLocator (
struct ISAXLocator * pLocator ) = 0;
virtual HRESULT __stdcall startDocument ( ) = 0;
virtual HRESULT __stdcall endDocument ( ) = 0;
virtual HRESULT __stdcall startPrefixMapping (
unsigned short * pwchPrefix,
int cchPrefix,
unsigned short * pwchUri,
......
#1
什么是纯虚函数??
#2
这个类是一个纯虚基类,其中的startPrefixMapping是纯虚函数,类似如下声明:
long _stdcall startPrefixMapping(unsigned short*, int, unsigned short*, int) = 0;
也就是此函数只有类型声明没有实体,而且继承的类必须重载这个函数!
纯虚基类是不能实例化的,必须自己继承一个类,并将上面的函数重载,声明执行的部分!
如
class myclass:public ISAXContentHandler
{
long _stdcall startPrefixMapping(unsigned short*, int, unsigned short*, int)
{
// do something;
return 0;
}
}
不过这个类看样子是嵌套类,你需要头文件仔细看一下!不过你的类又是一个接口声明,似乎你不应当使用这个类,应该有现成的继承类可以使用!
long _stdcall startPrefixMapping(unsigned short*, int, unsigned short*, int) = 0;
也就是此函数只有类型声明没有实体,而且继承的类必须重载这个函数!
纯虚基类是不能实例化的,必须自己继承一个类,并将上面的函数重载,声明执行的部分!
如
class myclass:public ISAXContentHandler
{
long _stdcall startPrefixMapping(unsigned short*, int, unsigned short*, int)
{
// do something;
return 0;
}
}
不过这个类看样子是嵌套类,你需要头文件仔细看一下!不过你的类又是一个接口声明,似乎你不应当使用这个类,应该有现成的继承类可以使用!
#3
代码如下:
帮帮忙看怎么处理:
DNContent.h
#import <msxml3.dll> raw_interfaces_only // We use this library.
using namespace MSXML2; // and everything for SAX is in this namespace
class DNContent : public ISAXContentHandler
{
public:
// IUnknown
long __stdcall QueryInterface(const struct _GUID &,void ** );
unsigned long __stdcall AddRef(void);
unsigned long __stdcall Release(void);
// Define constructor and destructor.
DNContent();
virtual ~DNContent();
// ISAXContentHandler
virtual HRESULT STDMETHODCALLTYPE putDocumentLocator(
/* [in] */ ISAXLocator __RPC_FAR *pLocator);
virtual HRESULT STDMETHODCALLTYPE startDocument(void);
virtual HRESULT STDMETHODCALLTYPE endDocument(void);
virtual HRESULT STDMETHODCALLTYPE startPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri);
virtual HRESULT STDMETHODCALLTYPE endPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix);
virtual HRESULT STDMETHODCALLTYPE startElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes);
virtual HRESULT STDMETHODCALLTYPE endElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName);
virtual HRESULT STDMETHODCALLTYPE characters(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
virtual HRESULT STDMETHODCALLTYPE ignorableWhitespace(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
virtual HRESULT STDMETHODCALLTYPE processingInstruction(
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData);
virtual HRESULT STDMETHODCALLTYPE skippedEntity(
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName);
// ...and add whatever you like to simplify implementation.
private:
void prt ( wchar_t * pwchFmt, const wchar_t __RPC_FAR *pwchVal,
int cchVal);
};
DNContent.cpp
#include "stdafx.h" // We need the headers...
#include <stdio.h>
#include <stdlib.h>
#include "DNContent.h"
// Usually there is nothing to do in constructors and destructors,
// but if so, do it here.
DNContent::DNContent() {}
DNContent::~DNContent() {}
// Now finish the IUnknown stuff.
// (However, keep in mind that if you want to implement handlers as COM
// objects, you can add more functionality than shown with these
// methods.)
long __stdcall DNContent::QueryInterface(const struct _GUID &,void ** )
{ return 0; }
unsigned long __stdcall DNContent::AddRef() { return 0; }
unsigned long __stdcall DNContent::Release() { return 0; }
// "prt" is a private method.
// SAX does not use it. You don't have to implement it or any other
// private methods.
// This one is just quick print.
void DNContent::prt ( wchar_t * pwchFmt, const wchar_t __RPC_FAR *pwchVal,
int cchVal )
{
static wchar_t val[1000];
cchVal = cchVal>999 ? 999 : cchVal;
wcsncpy( val, pwchVal, cchVal ); val[cchVal] = 0;
wprintf(pwchFmt,val);
}
// Finish the ISAXContentHandler
HRESULT STDMETHODCALLTYPE DNContent::putDocumentLocator(
/* [in] */ ISAXLocator __RPC_FAR *pLocator)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::startDocument(void)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::endDocument(void)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::startElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes)
{
// I want to print the tag name.
prt(L"\n<%s>",pwchLocalName,cchLocalName);
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::endElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::startPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::endPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::characters(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::ignorableWhitespace(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::processingInstruction(
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::skippedEntity(
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName)
{
return S_OK;
}
帮帮忙看怎么处理:
DNContent.h
#import <msxml3.dll> raw_interfaces_only // We use this library.
using namespace MSXML2; // and everything for SAX is in this namespace
class DNContent : public ISAXContentHandler
{
public:
// IUnknown
long __stdcall QueryInterface(const struct _GUID &,void ** );
unsigned long __stdcall AddRef(void);
unsigned long __stdcall Release(void);
// Define constructor and destructor.
DNContent();
virtual ~DNContent();
// ISAXContentHandler
virtual HRESULT STDMETHODCALLTYPE putDocumentLocator(
/* [in] */ ISAXLocator __RPC_FAR *pLocator);
virtual HRESULT STDMETHODCALLTYPE startDocument(void);
virtual HRESULT STDMETHODCALLTYPE endDocument(void);
virtual HRESULT STDMETHODCALLTYPE startPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri);
virtual HRESULT STDMETHODCALLTYPE endPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix);
virtual HRESULT STDMETHODCALLTYPE startElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes);
virtual HRESULT STDMETHODCALLTYPE endElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName);
virtual HRESULT STDMETHODCALLTYPE characters(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
virtual HRESULT STDMETHODCALLTYPE ignorableWhitespace(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
virtual HRESULT STDMETHODCALLTYPE processingInstruction(
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData);
virtual HRESULT STDMETHODCALLTYPE skippedEntity(
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName);
// ...and add whatever you like to simplify implementation.
private:
void prt ( wchar_t * pwchFmt, const wchar_t __RPC_FAR *pwchVal,
int cchVal);
};
DNContent.cpp
#include "stdafx.h" // We need the headers...
#include <stdio.h>
#include <stdlib.h>
#include "DNContent.h"
// Usually there is nothing to do in constructors and destructors,
// but if so, do it here.
DNContent::DNContent() {}
DNContent::~DNContent() {}
// Now finish the IUnknown stuff.
// (However, keep in mind that if you want to implement handlers as COM
// objects, you can add more functionality than shown with these
// methods.)
long __stdcall DNContent::QueryInterface(const struct _GUID &,void ** )
{ return 0; }
unsigned long __stdcall DNContent::AddRef() { return 0; }
unsigned long __stdcall DNContent::Release() { return 0; }
// "prt" is a private method.
// SAX does not use it. You don't have to implement it or any other
// private methods.
// This one is just quick print.
void DNContent::prt ( wchar_t * pwchFmt, const wchar_t __RPC_FAR *pwchVal,
int cchVal )
{
static wchar_t val[1000];
cchVal = cchVal>999 ? 999 : cchVal;
wcsncpy( val, pwchVal, cchVal ); val[cchVal] = 0;
wprintf(pwchFmt,val);
}
// Finish the ISAXContentHandler
HRESULT STDMETHODCALLTYPE DNContent::putDocumentLocator(
/* [in] */ ISAXLocator __RPC_FAR *pLocator)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::startDocument(void)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::endDocument(void)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::startElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes)
{
// I want to print the tag name.
prt(L"\n<%s>",pwchLocalName,cchLocalName);
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::endElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::startPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::endPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::characters(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::ignorableWhitespace(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::processingInstruction(
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData)
{
return S_OK;
}
HRESULT STDMETHODCALLTYPE DNContent::skippedEntity(
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName)
{
return S_OK;
}
#4
另外,namespace是干什么用的?
#5
另:纯虚函数就是一个函数在声明时其后有 = 0;的写法,不可写函数执行体!
#6
谁能给我说说,有关接口的知识?
#7
Holly,从我贴出来的代码能看出问题吗?
#8
我已经重载那些虚函数了
怎么还报错??
怎么还报错??
#9
namespace相当于一个用来识别在不同名字空间相同函数或变量声明的一种新的C++语法,基本上起到了将属于该名字空间的所有声明加一个身份识别!
如:
//mydeclare1.h中:
namespace declare1
{
class myclass{int a;};
void myfunc();
int myvar;
}
//mydeclare2.h中
namespace declare2
{
class myclass{int a;};
void myfunc();
int myvar;
}
//myexec.cpp中
#include "mydeclare1.h"
#include "mydeclare2.h"
...
declare1::myclass a;
declare2::myclass b;
...
此时不会有redefine的错误出现!
你的问题没有明确,不过估计是ISAXContentHandler类中还有一个函数声明为:
virtual
HRESULT STDMETHODCALLTYPE startPrefixMapping(
/* [in] */ wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri) = 0;
请注意没有const,你在将ISAXContentHandler的头文件找来看看!
如:
//mydeclare1.h中:
namespace declare1
{
class myclass{int a;};
void myfunc();
int myvar;
}
//mydeclare2.h中
namespace declare2
{
class myclass{int a;};
void myfunc();
int myvar;
}
//myexec.cpp中
#include "mydeclare1.h"
#include "mydeclare2.h"
...
declare1::myclass a;
declare2::myclass b;
...
此时不会有redefine的错误出现!
你的问题没有明确,不过估计是ISAXContentHandler类中还有一个函数声明为:
virtual
HRESULT STDMETHODCALLTYPE startPrefixMapping(
/* [in] */ wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri) = 0;
请注意没有const,你在将ISAXContentHandler的头文件找来看看!
#10
namespace 是用来区分相同的名字的函数、类或变量的声明的!
如
namespace mydeclare1
{
void myfunc(){}
}
namespace mydeclare2
{
void myfunc(){}
}
....
mydeclare1::myfunc()
mydeclare2::myfunc()
...
如
namespace mydeclare1
{
void myfunc(){}
}
namespace mydeclare2
{
void myfunc(){}
}
....
mydeclare1::myfunc()
mydeclare2::myfunc()
...
#11
namespace 有一点类似于class的声明,就是名字作用域,但它没有class的继承和成员等特性;
如:
namespace MyDeclare1
{
class MyClass
{
int a;
}
void MyFunc(){};
DWORD dwVar;
}
namespace MyDeclare2
{
class MyClass
{
int a;
}
void MyFunc(){};
DWORD dwVar;
}
那么有
MyDeclare1::MyFunc();
MyDeclare2::MyFunc();
虽然有两个MyFunc()但并不导致重定义!因为有了名字空间的识别!
如:
namespace MyDeclare1
{
class MyClass
{
int a;
}
void MyFunc(){};
DWORD dwVar;
}
namespace MyDeclare2
{
class MyClass
{
int a;
}
void MyFunc(){};
DWORD dwVar;
}
那么有
MyDeclare1::MyFunc();
MyDeclare2::MyFunc();
虽然有两个MyFunc()但并不导致重定义!因为有了名字空间的识别!
#12
Sorry,服务器故障,贴多了!
#13
果然,去掉const就好了
可是在 msxml.h中是有const的,另外我发现编译的时候目录下多了一个文件msxml.tlh
每次编译都会改变,它是干什么用的?里面是一些接口的定义,其中也有 ISAXContentHandler的定义,他们怎么就不一样呢??
//////////////msxml.h/////////////////////////////////////
#ifndef __ISAXContentHandler_INTERFACE_DEFINED__
#define __ISAXContentHandler_INTERFACE_DEFINED__
/* interface ISAXContentHandler */
/* [unique][helpstring][uuid][local][object][hidden] */
EXTERN_C const IID IID_ISAXContentHandler;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("1545cdfa-9e4e-4497-a8a4-2bf7d0112c44")
ISAXContentHandler : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE putDocumentLocator(
/* [in] */ ISAXLocator __RPC_FAR *pLocator) = 0;
virtual HRESULT STDMETHODCALLTYPE startDocument( void) = 0;
virtual HRESULT STDMETHODCALLTYPE endDocument( void) = 0;
virtual HRESULT STDMETHODCALLTYPE startPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri) = 0;
virtual HRESULT STDMETHODCALLTYPE endPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix) = 0;
virtual HRESULT STDMETHODCALLTYPE startElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes) = 0;
virtual HRESULT STDMETHODCALLTYPE endElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName) = 0;
virtual HRESULT STDMETHODCALLTYPE characters(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars) = 0;
virtual HRESULT STDMETHODCALLTYPE ignorableWhitespace(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars) = 0;
virtual HRESULT STDMETHODCALLTYPE processingInstruction(
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData) = 0;
virtual HRESULT STDMETHODCALLTYPE skippedEntity(
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName) = 0;
};
#else /* C style interface */
typedef struct ISAXContentHandlerVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *QueryInterface )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ REFIID riid,
/* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
ULONG ( STDMETHODCALLTYPE __RPC_FAR *AddRef )(
ISAXContentHandler __RPC_FAR * This);
ULONG ( STDMETHODCALLTYPE __RPC_FAR *Release )(
ISAXContentHandler __RPC_FAR * This);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *putDocumentLocator )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ ISAXLocator __RPC_FAR *pLocator);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *startDocument )(
ISAXContentHandler __RPC_FAR * This);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *endDocument )(
ISAXContentHandler __RPC_FAR * This);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *startPrefixMapping )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *endPrefixMapping )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *startElement )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *endElement )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *characters )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *ignorableWhitespace )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *processingInstruction )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *skippedEntity )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName);
END_INTERFACE
} ISAXContentHandlerVtbl;
interface ISAXContentHandler
{
CONST_VTBL struct ISAXContentHandlerVtbl __RPC_FAR *lpVtbl;
};
/////////////////msxml.tlh//////////////////////////////
struct __declspec(uuid("1545cdfa-9e4e-4497-a8a4-2bf7d0112c44"))
ISAXContentHandler : IUnknown
{
//
// Raw methods provided by interface
//
virtual HRESULT __stdcall putDocumentLocator (
struct ISAXLocator * pLocator ) = 0;
virtual HRESULT __stdcall startDocument ( ) = 0;
virtual HRESULT __stdcall endDocument ( ) = 0;
virtual HRESULT __stdcall startPrefixMapping (
unsigned short * pwchPrefix,
int cchPrefix,
unsigned short * pwchUri,
......
可是在 msxml.h中是有const的,另外我发现编译的时候目录下多了一个文件msxml.tlh
每次编译都会改变,它是干什么用的?里面是一些接口的定义,其中也有 ISAXContentHandler的定义,他们怎么就不一样呢??
//////////////msxml.h/////////////////////////////////////
#ifndef __ISAXContentHandler_INTERFACE_DEFINED__
#define __ISAXContentHandler_INTERFACE_DEFINED__
/* interface ISAXContentHandler */
/* [unique][helpstring][uuid][local][object][hidden] */
EXTERN_C const IID IID_ISAXContentHandler;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("1545cdfa-9e4e-4497-a8a4-2bf7d0112c44")
ISAXContentHandler : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE putDocumentLocator(
/* [in] */ ISAXLocator __RPC_FAR *pLocator) = 0;
virtual HRESULT STDMETHODCALLTYPE startDocument( void) = 0;
virtual HRESULT STDMETHODCALLTYPE endDocument( void) = 0;
virtual HRESULT STDMETHODCALLTYPE startPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri) = 0;
virtual HRESULT STDMETHODCALLTYPE endPrefixMapping(
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix) = 0;
virtual HRESULT STDMETHODCALLTYPE startElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes) = 0;
virtual HRESULT STDMETHODCALLTYPE endElement(
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName) = 0;
virtual HRESULT STDMETHODCALLTYPE characters(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars) = 0;
virtual HRESULT STDMETHODCALLTYPE ignorableWhitespace(
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars) = 0;
virtual HRESULT STDMETHODCALLTYPE processingInstruction(
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData) = 0;
virtual HRESULT STDMETHODCALLTYPE skippedEntity(
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName) = 0;
};
#else /* C style interface */
typedef struct ISAXContentHandlerVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *QueryInterface )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ REFIID riid,
/* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
ULONG ( STDMETHODCALLTYPE __RPC_FAR *AddRef )(
ISAXContentHandler __RPC_FAR * This);
ULONG ( STDMETHODCALLTYPE __RPC_FAR *Release )(
ISAXContentHandler __RPC_FAR * This);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *putDocumentLocator )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ ISAXLocator __RPC_FAR *pLocator);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *startDocument )(
ISAXContentHandler __RPC_FAR * This);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *endDocument )(
ISAXContentHandler __RPC_FAR * This);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *startPrefixMapping )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix,
/* [in] */ const wchar_t __RPC_FAR *pwchUri,
/* [in] */ int cchUri);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *endPrefixMapping )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchPrefix,
/* [in] */ int cchPrefix);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *startElement )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName,
/* [in] */ ISAXAttributes __RPC_FAR *pAttributes);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *endElement )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchNamespaceUri,
/* [in] */ int cchNamespaceUri,
/* [in] */ const wchar_t __RPC_FAR *pwchLocalName,
/* [in] */ int cchLocalName,
/* [in] */ const wchar_t __RPC_FAR *pwchQName,
/* [in] */ int cchQName);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *characters )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *ignorableWhitespace )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchChars,
/* [in] */ int cchChars);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *processingInstruction )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchTarget,
/* [in] */ int cchTarget,
/* [in] */ const wchar_t __RPC_FAR *pwchData,
/* [in] */ int cchData);
HRESULT ( STDMETHODCALLTYPE __RPC_FAR *skippedEntity )(
ISAXContentHandler __RPC_FAR * This,
/* [in] */ const wchar_t __RPC_FAR *pwchName,
/* [in] */ int cchName);
END_INTERFACE
} ISAXContentHandlerVtbl;
interface ISAXContentHandler
{
CONST_VTBL struct ISAXContentHandlerVtbl __RPC_FAR *lpVtbl;
};
/////////////////msxml.tlh//////////////////////////////
struct __declspec(uuid("1545cdfa-9e4e-4497-a8a4-2bf7d0112c44"))
ISAXContentHandler : IUnknown
{
//
// Raw methods provided by interface
//
virtual HRESULT __stdcall putDocumentLocator (
struct ISAXLocator * pLocator ) = 0;
virtual HRESULT __stdcall startDocument ( ) = 0;
virtual HRESULT __stdcall endDocument ( ) = 0;
virtual HRESULT __stdcall startPrefixMapping (
unsigned short * pwchPrefix,
int cchPrefix,
unsigned short * pwchUri,
......