0

为什么下面的片段

#include <atlcom.h>
...
class FormRegionWrapper;
...
// Errorsource :
typedef IDispEventSimpleImpl
        <2, FormRegionWrapper, &__uuidof(FormRegionEvents)> 
        FormRegionEventSink;

会给我以下错误:

// Error ouput:     
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. 
             Note: C++ does not support default-int

?!?

(片段取自此处:为 Outlook 2010 构建 C++插件)。我的环境:MS Visual Studio 2012 Professional 和 Windows 7-64。

PS 1:关于 IDispEventSimpleImpl 的帮助说明如下:

// Help IDispEventSimpleImpl Class  : This class provides implementations of 
// the IDispatch methods, without getting type information from a type library.
//    template <
//      UINT nID,
//      class T,
//      const IID* pdiid
//    >
//    class ATL_NO_VTABLE IDispEventSimpleImpl :
//      public _IDispEventLocator<nID, pdiid>
//
// Requirements
// -------------------
// Header: atlcom.h
4

2 回答 2

1

您是否包含atlcom.h以便IDispEventSimpleImpl定义模板?模板声明中使用的其他类的声明(我假设是你写的)是否可用?而且我认为前向定义FormRegionWrapper还不够,您可以尝试包含该类的声明,以便该模板可以看到吗?

更新

不确定这是否会有很大帮助,但我用FormRegionWrapper.h下面的colde替换了源代码(来自MSDN页面的示例IDispEventSimpleImpl

#pragma once

#include "stdafx.h"
#include <vector>
#include <algorithm>

_ATL_FUNC_INFO Event1Info1 = { CC_CDECL, VT_EMPTY, 1, { VT_I4 } };

class CEventHandler;

typedef IDispEventSimpleImpl <1234, CEventHandler, &__uuidof(IDispatch)> 
DummySink;

class CEventHandler : public DummySink

{
public:
    BEGIN_SINK_MAP(CEventHandler)
        SINK_ENTRY_INFO(1234, __uuidof(IDispatch), 1, OnEvent1, &Event1Info1)
    END_SINK_MAP()
    void __stdcall  OnEvent1(LONG l)
    {
        //ATLASSERT(l == 445533);
        if (l != 445533)
            OutputDebugString(L"l is not 445533\n");
    }
    HRESULT Advise1234(IUnknown * punk) {
        return IDispEventSimpleImpl<1234, CEventHandler, &__uuidof(IDispatch)>::DispEventAdvise(punk);
    }
};

如果这有效,您可以放心地假设模板被正确包含。

于 2012-11-07T09:38:24.707 回答
0

在 FormRegionWrapper.h 中的 #include 指令之后添加这一行:

使用命名空间 ATL;

于 2014-03-08T11:21:42.603 回答