建立atl组件,刚创建一个new ATL object 就编译出错!
EGIN_COM_MAP(CCatInformation)
----→错误  COM_INTERFACE_ENTRY(ICatInformation)
----→错误  COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()提示:
e:\学习\练习\computer\computer\catinformation.h(26) : error C2440: 'static_cast' : cannot convert from 'class CCatInformation *' to 'struct IDispatch *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\学习\练习\computer\computer\catinformation.h(26) : error C2440: 'initializing' : cannot convert from 'long (__stdcall *)(void *,const struct _GUID &,void ** ,unsigned long)' to 'unsigned long'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
CatInformation.cpp
e:\学习\练习\computer\computer\catinformation.h(26) : error C2440: 'static_cast' : cannot convert from 'class CCatInformation *' to 'struct IDispatch *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
e:\学习\练习\computer\computer\catinformation.h(26) : error C2440: 'initializing' : cannot convert from 'long (__stdcall *)(void *,const struct _GUID &,void ** ,unsigned long)' to 'unsigned long'
        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Generating Code...
Error executing cl.exe.computer.dll - 4 error(s), 0 warning(s)

解决方案 »

  1.   

    BEGIN_COM_MAP(CCatInformation) 
         COM_INTERFACE_ENTRY(ICatInformation) 
         COM_INTERFACE_ENTRY2(IDispatch, ICatInformation) // IDispatch接口不能直接被请求,要映射到某个具体接口
    END_COM_MAP() 
      

  2.   

    我直接用向导建的,就添加了一个new   ATL   object     一点代码没写,就出错了!我刚学做vc  是不是添了new   ATL   object   还要在什么文件里设置一下啊?
      

  3.   

     COM_INTERFACE_ENTRY2(IDispatch,   ICatInformation)  也不行提示错误一样!
      

  4.   

    你的class   CCatInformation没有从IDispatchImpl<ICatInformation...> 继承,当然无法转换到IDispatch*接口了
      

  5.   

    继承了啊,自动生成的代码如下:
    // CatInformation.h : Declaration of the CCatInformation#ifndef __CATINFORMATION_H_
    #define __CATINFORMATION_H_#include "resource.h"       // main symbols/////////////////////////////////////////////////////////////////////////////
    // CCatInformation
    class ATL_NO_VTABLE CCatInformation : 
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CCatInformation, &CLSID_CatInformation>,
    public IDispatchImpl<ICatInformation, &IID_ICatInformation, &LIBID_COMPUTERLib>
    {
    public:
    CCatInformation()
    {
    }DECLARE_REGISTRY_RESOURCEID(IDR_CATINFORMATION)DECLARE_PROTECT_FINAL_CONSTRUCT()BEGIN_COM_MAP(CCatInformation)
    COM_INTERFACE_ENTRY(ICatInformation)
    COM_INTERFACE_ENTRY(IDispatch)
    END_COM_MAP()// ICatInformation
    public:
    };#endif //__CATINFORMATION_H_
      

  6.   

    估计你的ICatInformation没有继承IDispatch