COM interface created by ATL inherits IDispatch bu

2019-05-19 01:05发布

This my IDL file. IFrame is a dual interface and inherits both IDispatch and IUnknown.

[
    object,
    uuid(C5AD0517-37FC-479C-9C7A-A063B17E4A2E),
    dual,
    nonextensible,
    pointer_default(unique)
]
    interface IFrame : IDispatch{
};
[
    uuid(F7D50952-4AF1-491B-B0AA-35083AEFA998),
    version(1.0),
]
library bdsCOMLib
{
    importlib("stdole2.tlb");
    [
        uuid(9C2E7E2D-A39C-4FE7-BEEB-3BF65F9D4C05)      
    ]
    coclass Frame
    {
        [default] interface IFrame;
    };
};

And this is the CFrame class declaration which is suppose to implement IFrame:

class ATL_NO_VTABLE CFrame :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CFrame, &CLSID_Frame>,
public IDispatchImpl<IFrame, &IID_IFrame, &LIBID_bdsCOMLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
    public:
        CFrame()
        {
        }

    DECLARE_REGISTRY_RESOURCEID(IDR_FRAME)


    BEGIN_COM_MAP(CFrame)
        COM_INTERFACE_ENTRY(IFrame)
        COM_INTERFACE_ENTRY(IDispatch)
    END_COM_MAP()



    DECLARE_PROTECT_FINAL_CONSTRUCT()

    HRESULT FinalConstruct()
    {
        return S_OK;
    }

    void FinalRelease()
    {
    }
};
OBJECT_ENTRY_AUTO(__uuidof(Frame), CFrame)

The COM server gets registered and it works fine when I use the Frame object in VBA but by early binding. I want to use this object with VBScript, so I do need late binding.

But late binding cannot be done. I read up on the situation and it seems that the ATL (and IDispatchImp class) do all the implementation needed for IDispatch which gives me the ability to use the object with automation tools (e.g. VBScript).

However, in practice the script gives "Active X control cannot be created" error. It's the same in VBA when I try early binding.

What am I doing wrong? I am using Visual Studio 2012 on Windows 7 64-bit but my COM server is 32-bit (and it is registered with the system).

0条回答
登录 后发表回答