class ATL_NO_VTABLE CFinalCal:
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<CFinalCal, &CLSID_FinalCal>,
public IDispatchImpl<IFinalCal, &IID_IFinalCal, &LIBID_FinalCom>
{
public:
CFinalCal()
{
}DECLARE_REGISTRY_RESOURCEID(IDR_FinalCal)
DECLARE_PROTECT_FINAL_CONSTRUCT()BEGIN_COM_MAP(CFinalCal)
COM_INTERFACE_ENTRY(IFinalCal)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()public:
STDMETHOD(Add)(/*[in]*/ int nOp1,/*[in]*/ int nOp2,/*[out,retval]*/ int *pret);
STDMETHOD(Sub)(/*[in]*/ int nOp1,/*[in]*/ int nOp2,/*[out,retval]*/ int *pret);
};#endif 上面这个类 编译时出现错误
c:\work\project\EX5\FinalCom\FinalCom\FinalCal.h(14): error C2970: 'ATL::IDispatchImpl' : template parameter 'plibid' : 'LIBID_FinalCom' : an expression involving objects with internal linkage cannot be used as a non-type argument
c:\work\project\EX5\FinalCom\FinalCom\FinalCal.h(14): error C2970: 'ATL::IDispatchImpl' : template parameter 'piid' : 'IID_IFinalCal' : an expression involving objects with internal linkage cannot be used as a non-type argument
c:\work\project\EX5\FinalCom\FinalCom\FinalCal.h(13): error C2970: 'ATL::CComCoClass' : template parameter 'pclsid' : 'CLSID_FinalCal' : an expression involving objects with internal linkage cannot be used as a non-type argument
而CLSID_FinalCal的定义是通过.idl文件MIDl编译出来的一个.c文件来定义的。
如下:#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \
        const type name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}#endif !_MIDL_USE_GUIDDEF_MIDL_DEFINE_GUID(IID, IID_IFinalCal,0x63c830b3,0x0340,0x4f92,0xa7,0xb9,0xdf,0xa5,0xd7,0x9e,0xe9,0x4f);
MIDL_DEFINE_GUID(IID, LIBID_FinalCom,0xDC823CBF,0xD3EF,0x4F3C,0x83,0xE5,0x27,0x89,0x57,0x1A,0xCF,0x8A);
MIDL_DEFINE_GUID(CLSID, CLSID_FinalCal,0xd714ac8a,0xab2f,0x4faa,0xa6,0x85,0x53,0x78,0xc6,0xf1,0x91,0xd3);
请问有什么办法解决这个参数的问题吗?

解决方案 »

  1.   

    在编译的时候,出现的错误。
    我查了下MSDN,这个错误是
    'class' : template parameter 'param' : 'arg' : an expression involving objects with internal linkage cannot be used as a non-type argumentYou cannot use the name or address of a static variable as a template argument. The template class expects a const value that can be evaluated at compile time.The following sample generates C2970:意思就是模板参数不能使用静态变量。
    而'CLSID_FinalCal'在 _i.c文件中定义的就是如上。而这个文件是MIDL自动生成的。是不是编译器设置问题啊?-----
    ------------------------------------------------------------------------
    是你ide问题
    能具体说明一下吗?
      

  2.   

    有时候用微软的怪GUID宏会导致编译出错,你不要用宏MIDL_DEFINE_GUID,直接用const GUID name = 试试
      

  3.   

    这个定义LSID 文件是自动生成的。改不了阿
      

  4.   

    c++默认const类型为static,加入extern "C"就可以了,
    找到 CLSID_FinalCal,和 IID_FinalCal 的定义,在前面加入extern "C"
      

  5.   

    c++默认const类型为static,加入extern "C"就可以了,
    找到 CLSID_FinalCal,和 IID_FinalCal 的定义,在前面加入extern "C"------------------------------------------------------------------在你的提示下,我修改了我的include 文件;
    出现了下面的问题,这个问题我不知道是什么么问题?FinalCom error PRJ0019: A tool returned an error code from "Performing registration"
    FinalCom warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
    看了 error log 
    如下:
    @echo off
    regsvr32 /s /c "c:\work\project\Ex5\FinalCom\FinalCom\Debug\FinalCom.dll"
    if errorlevel 1 goto VCReportError
    goto VCEnd
    :VCReportError
    echo Project : error PRJ0019: A tool returned an error code from "Performing registration"
    exit 1
    :VCEnd
    ]
    Creating command line "c:\work\project\Ex5\FinalCom\FinalCom\Debug\BAT000038.bat"
      

  6.   

    不要在头文件里面 include "XXX_i.c"
      

  7.   

    建议你用ATL重建你的工程,说不定这些问题都没了。
      

  8.   

    在头文件中包含  xxx_i.h 就可以了吧 , VS2010 就是这样的。不过我曾经在VC 6 中碰到过,实在不行 在你的 类定义文件中  加上 extern CLSID_FinalCal 吧,编译的时候编译器在动态连编  _i.c 文件