2

我在尝试将基于 directshow 的直播播放器编写为 ActiveX 控件时遇到了问题。

我首先用VS2010(VC++类)创建了一个MFC ActiveX控件项目,并在控件上附加了一个对话框,然后用一个简单的html页面对其进行了测试。

到目前为止它运行良好,但是当我尝试使用 CComPtr 添加一些 directshow 代码时,编译器显示以下错误(我还附上了行号和文件):

29  IntelliSense: CComPtr is not a template   (CIceBaseLivestreamPlayerCore.h, Line 37)
30  IntelliSense: CComPtr is not a template   (CIceBaseLivestreamPlayerCore.h, Line 38)
31  IntelliSense: CComPtr is not a template   (CIceBaseLivestreamPlayerCore.h, Line 44)
32  IntelliSense: CComPtr is not a template   (CIceBaseLivestreamPlayerCore.h, Line 44)
33  IntelliSense: CComPtr is not a template   (CIceBaseLivestreamPlayerCore.h, Line 47)
34  IntelliSense: CComPtr is not a template   (CIceBaseLivestreamPlayerCore.h, Line 48)
35  IntelliSense: CComPtr is not a template   (CIceBaseLivestreamPlayerCore.h, Line 49)
36  IntelliSense: CComPtr is not a template   (CIcePlayAndSaveAXCore.h, Line 19)
37  IntelliSense: CComPtr is not a template   (CIcePlayAndSaveAXCore.h, Line 20)
38  IntelliSense: CComPtr is not a template   (CIcePlayAndSaveAXCore.h, Line 21)
39  IntelliSense: CComPtr is not a template   (CIcePlayAndSaveAXCore.h, Line 22)
Error   2   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   (CIceBaseLivestreamPlayerCore.h, Line 37)
Error   5   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   (CIceBaseLivestreamPlayerCore.h, Line 38)
Error   14  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   (CIcePlayAndSaveAXCore.h, Line 19)
Error   17  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   (CIcePlayAndSaveAXCore.h, Line 20)
Error   20  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   (CIcePlayAndSaveAXCore.h, Line 21)
Error   23  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   (CIcePlayAndSaveAXCore.h, Line 22)
Error   25  error C2614: 'CIcePlayAndSaveAXCore' : illegal member initialization: 'm_vInfTee' is not a base or member   (CIcePlayAndSaveAXCore.h, Line 9)
Error   27  error C2614: 'CIcePlayAndSaveAXCore' : illegal member initialization: 'm_fileWriter' is not a base or member   (CIcePlayAndSaveAXCore.h, Line 9)
Error   28  error C2614: 'CIcePlayAndSaveAXCore' : illegal member initialization: 'm_AVIMux' is not a base or member   (CIcePlayAndSaveAXCore.h, Line 9)
Error   26  error C2614: 'CIcePlayAndSaveAXCore' : illegal member initialization: 'm_aInfTee' is not a base or member   (CIcePlayAndSaveAXCore.h, Line 9)
Error   12  error C2614: 'CIceBaseLivestreamPlayerCore' : illegal member initialization: 'm_pGraph' is not a base or member   (CIceBaseLivestreamPlayerCore.h, Line 18)
Error   11  error C2614: 'CIceBaseLivestreamPlayerCore' : illegal member initialization: 'm_pControl' is not a base or member   (CIceBaseLivestreamPlayerCore.h, Line 18)
Error   3   error C2238: unexpected token(s) preceding ';'   (CIceBaseLivestreamPlayerCore.h, Line 37)
Error   6   error C2238: unexpected token(s) preceding ';'   (CIceBaseLivestreamPlayerCore.h, Line 38)
Error   15  error C2238: unexpected token(s) preceding ';'   (CIcePlayAndSaveAXCore.h, Line 19)
Error   18  error C2238: unexpected token(s) preceding ';'   (CIcePlayAndSaveAXCore.h, Line 20)
Error   21  error C2238: unexpected token(s) preceding ';'   (CIcePlayAndSaveAXCore.h, Line 21)
Error   24  error C2238: unexpected token(s) preceding ';'   (CIcePlayAndSaveAXCore.h, Line 22)
Error   1   error C2143: syntax error : missing ';' before '<'   (CIceBaseLivestreamPlayerCore.h, Line 37)
Error   4   error C2143: syntax error : missing ';' before '<'   (CIceBaseLivestreamPlayerCore.h, Line 38)
Error   13  error C2143: syntax error : missing ';' before '<'   (CIcePlayAndSaveAXCore.h, Line 19)
Error   16  error C2143: syntax error : missing ';' before '<'   (CIcePlayAndSaveAXCore.h, Line 20)
Error   19  error C2143: syntax error : missing ';' before '<'   (CIcePlayAndSaveAXCore.h, Line 21)
Error   22  error C2143: syntax error : missing ';' before '<'   (CIcePlayAndSaveAXCore.h, Line 22)
Error   7   error C2061: syntax error : identifier 'CComPtr'   (CIceBaseLivestreamPlayerCore.h, Line 44)
Error   8   error C2061: syntax error : identifier 'CComPtr'   (CIceBaseLivestreamPlayerCore.h, Line 47)
Error   9   error C2061: syntax error : identifier 'CComPtr'   (CIceBaseLivestreamPlayerCore.h, Line 48)
Error   10  error C2061: syntax error : identifier 'CComPtr'   (CIceBaseLivestreamPlayerCore.h, Line 49)

所有这些错误似乎都表明 CComPtr 有一些奇怪的地方,但我不知道出了什么问题。

我在 stdafx.h 的底部添加了两个头文件,如下所示:

#include <streams.h>
#include <atlbase.h>

我将列出部分我的 CIceBaseLivestreamPlayerCore.h 和 CIcePlayAndSaveAXCore.h 如下,上述错误中涉及的所有行都包括在内。

CIceBaseLivestreamPlayerCore.h:

#pragma once
#include "stdafx.h"

class CIceBaseLivestreamPlayerCore
{
...
15  CIceBaseLivestreamPlayerCore():
16  ..., m_pGraph(NULL), m_pControl(NULL),
17  ...
18  { ; }
...
37  CComPtr<IGraphBuilder>          m_pGraph;
38  CComPtr<IMediaControl>          m_pControl;
...
44  HRESULT ConnectFilters(CComPtr<IBaseFilter> pIn,  CComPtr<IBaseFilter> pOut, const AM_MEDIA_TYPE& mType);
...
47  HRESULT MatchPin(CComPtr<IPin>, PIN_DIRECTION, BOOL, BOOL*);
48  HRESULT IsPinConnected(CComPtr<IPin>, BOOL*);
49  HRESULT IsPinDirection(CComPtr<IPin>, PIN_DIRECTION, BOOL*);
};

CIcePlayAndSaveAXCore.h:

#pragma once
#include "CIceBaseLivestreamPlayerCore.h"

class CIcePlayAndSaveAXCore : public CIceBaseLivestreamPlayerCore
{
...
7   CIcePlayAndSaveAXCore() :
8   m_AVIMux(NULL), m_fileWriter(NULL), m_aInfTee(NULL), m_vInfTee(NULL)
9   { ; }
...
19  CComPtr<IBaseFilter> m_AVIMux;
20  CComPtr<IBaseFilter> m_fileWriter;
21  CComPtr<IBaseFilter> m_aInfTee;
22  CComPtr<IBaseFilter> m_vInfTee;
};

我的项目的其他依赖项是“strmbasd.lib;winmm.lib;uuid.lib;”。

就是这样..希望有人能给我如何解决它的答案,或者只是给我任何建议或建议作为我应该做的方向。

任何帮助表示赞赏。

这是我第一次发布英语问题(虽然我不是母语人士..),所以请让我知道我在提问时是否有任何遗失或做错了什么。

非常感谢。:)

4

1 回答 1

7

经过多次尝试,我终于找到了问题并解决了。

我想我应该把结果放在这里,因为可能有人有同样的问题,并且不知道如何像我一样解决它。我不知道回答我自己的问题是否违反了stackoverflow的礼仪,所以我将不接受这个答案。

正如我所说,我#define <atlbase.h>已将stdafx.h. 但是因为我正在制作一个 MFC ActiveX 控件项目,IDE (VS 2010) 会自动在我stdafx.h#define _ATL_NO_AUTOMATIC_NAMESPACE.

而我们#include <atlbase.h>平时使用的时候,编译器会using namespace ATL默认执行,但是这条#define _ATL_NO_AUTOMATIC_NAMESPACE语句取消了这个行为,导致了我的编译器所说的命名冲突。

所以,在这种情况下,只要使用ATL::CComPtrfor 声明或直接使用using ATL::CComPtr出现 CComPtr 的语句,就可以消除这个编译错误。

于 2013-10-09T06:06:34.983 回答