描述:
各位,请教一个问题,如下的定义:
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
IPlayer : public IDispatch
{
public:
virtual HRESULT STDMETHODCALLTYPE GenerateID(
BSTR *pbstrSeed) = 0;
virtual HRESULT STDMETHODCALLTYPE getContent(
BSTR *pVal) = 0;
virtual HRESULT STDMETHODCALLTYPE putInfo(
BSTR newVal) = 0;
};
#endif
其中,#ifdef _68K_
#define STDMETHODCALLTYPE __cdecl
#else
#define STDMETHODCALLTYPE __stdcall
#endif
这个定义在winnt.h文件中
我该怎样引用这个IPlayer类呢?直接引用IPlayer aPlayer时,则出现了下面的问题:
E:\VC Debug\Test\Test.cpp(13) : error C2259: 'IPlayer' : cannot instantiate abstract class due to following members:
e::\VC Debug\Test\player.h(1727) : see declaration of 'IPlayer'
E:\VC Debug\Test\Test.cpp(13) : warning C4259: 'long __stdcall IUnknown::QueryInterface(const struct _GUID &,void ** )' : pure virtual function was not defined
c:\program files\microsoft visual studio\vc98\include\unknwn.h(109) : see declaration of 'QueryInterface'
E:\VC Debug\Test\Test.cpp(13) : warning C4259: 'unsigned long __stdcall IUnknown::AddRef(void)' : pure virtual function was not defined
c:\program files\microsoft visual studio\vc98\include\unknwn.h(113) : see declaration of 'AddRef'
E:\VC Debug\Test\Test.cpp(13) : warning C4259: 'unsigned long __stdcall IUnknown::Release(void)' : pure virtual function was not defined
c:\program files\microsoft visual studio\vc98\include\unknwn.h(115) : see declaration of 'Release'
E:\VC Debug\Test\Test.cpp(13) : warning C4259: 'long __stdcall IDispatch::GetTypeInfoCount(unsigned int *)' : pure virtual function was not defined
c:\program files\microsoft visual studio\vc98\include\oaidl.h(2697) : see declaration of 'GetTypeInfoCount'
等等,请各位帮忙看看,像这样的类定义,要怎样引用啊?谢谢大家!
解决方案1:
错误提示不是说得很清楚么:
'IPlayer' : cannot instantiate abstract class due to following members:
IPlayer是虚基类,不能实例化,所以,你可以这样:
1、实现错误提示中提到的几个成员函数
2、再写一个类继承自IPlayer,实现之.
over
这是com接口,com组件的使用分为几个步骤:
1.初始化com库 (CoInitialize)
2.创建com组件(CoCreateInstance)
3.查询接口(比如IPlayer)(可在创建的时候完成即步骤2)
4.使用IPlayer
5.释放IPlayer接口(IPlayer->Release())
6.释放com库(CoUnInitialize)
您可能想查找下面的文章:
- 实现了IDispatch接口的组件和ActiveX控件用起来有什么不同呢?我觉得一样可以用在Web页面上,为什么ActiveX控件还要多实现那么多各种各样
- 实现了IDispatch接口的组建,用vbscript怎么调用?
- IDispatch::Invoke如何通过dispid调用方法?
- 关于idispatch和typelib
- 问个弱弱的问题:得到一个ActiveX控件的IDispatch指针后,如何使用?有没有与CListCtrl相同的ActiveX控件?
- MSFlexGrid有一个Picture属性,是一个IDispatch接口指针,请问如何操作?
- 请教COM,IDispatch相关问题!
- 制作弹出广告拦截器时碰到问题,关于OnNewWindow2IDispatchppDisp,BOOLCancel的
- [关于IDispatch问题]:如何将tlb文件编译进dll中?高分求救
- 请问一下:COM组件(TLB)中使用IDispatch和CoInitialize两种方法有何不同?谢谢啦