我在idl中时这样写的
[//////////////////////////////////////////////////////////////////////////////////////
object,
uuid(2E62BDF8-9D3C-4D1F-A904-24562CCE303E),
helpstring("ICDictionary Interface"), //这是atl自动生成的
pointer_default(unique)
]
interface ICDictionary : IUnknown
{
[helpstring("method DicTestFun")] HRESULT DicTestFun(void);
};////////////////////////////////////////////////////////////////////////////////////
[//以下是我手工加入的
object,
uuid(6850F684-3529-4f2e-8195-4C0FB1DABBF3),
helpstring("ISpellCheck Interface"),
pointer_default(unique)
]
interface ISpellCheck : IUnknown
{
[helpstring("method SpellCheckFun")] HRESULT SpellCheckFun();
};
这是其中的idl文件,其中的ICDictionary是wizard自动生成,我根据其写出另外一个接口ISpellCheck 的定义,
然后在下面的代码中手工加入一句代码如下,在接口映射中加入下面的一句,这样编译正常,但是在我的客户测试程序中
却找不到ISpellCheck的定义。在生成的tlb文件中也没有任何关于ISpellCheck的声明和定义,请问什么地方错了
class ATL_NO_VTABLE CCDictionary :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CCDictionary, &CLSID_CDictionary>,
public ICDictionary,
public ISpellCheck//手工加入的
{
BEGIN_COM_MAP(CCDictionary)
COM_INTERFACE_ENTRY(ICDictionary)
COM_INTERFACE_ENTRY(ISpellCheck)//手工加入的
END_COM_MAP()
}
请问在使用atl建立com时,加入接口还有没有其它的方法,idl语言是不是比较难的,有没有详细介绍idl语言的书
5 个解决方案
#1
用类向导直接生成,就没有这样的麻烦了啊.
#2
不难,就和c语言差不多,里面也可以有枚举等类型。
你的这个接口找不到是因为你手工漏加了一些东西!!
你的这个接口找不到是因为你手工漏加了一些东西!!
#3
在idl最后的
library ....
[default] interface ICDictionary;
interface ISpellCheck; // 这里也要加
library ....
[default] interface ICDictionary;
interface ISpellCheck; // 这里也要加
#4
BEGIN_COM_MAP(CCDictionary)
COM_INTERFACE_ENTRY2(ICDictionary)//手工改为COM_INTERFACE_ENTRY2
COM_INTERFACE_ENTRY(ISpellCheck)//手工加入的
END_COM_MAP()
COM_INTERFACE_ENTRY2(ICDictionary)//手工改为COM_INTERFACE_ENTRY2
COM_INTERFACE_ENTRY(ISpellCheck)//手工加入的
END_COM_MAP()
#5
写错了!下面是我以前给别人写的例子:
// MuitInterface.idl : IDL source for MuitInterface.dll
//
// This file will be processed by the MIDL tool to
// produce the type library (MuitInterface.tlb) and marshalling code.
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(DD70A5F5-A411-459a-B54C-05F8CF56E791),
dual,
helpstring("IRTI1 Interface"),
pointer_default(unique)
]
interface IRTI1 : IDispatch
{
};
[
object,
uuid(3F7E1AE7-FDC2-41D6-8AC6-F24BECCA3F44),
dual,
helpstring("IRTI Interface"),
pointer_default(unique)
]
interface IRTI : IDispatch //手动添加的空接口
{
};
[
uuid(5F090D9A-8E8A-4EA7-AA92-2D7E03238146),
version(1.0),
helpstring("MuitInterface 1.0 Type Library")
]
library MUITINTERFACELib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(D096EC0F-CBB6-4286-B453-695B6E0FBD41),
helpstring("RTI Class")
]
coclass RTI
{
[default] interface IRTI;
interface IRTI1; //手动
};
};
.cpp:
// RTI.h : Declaration of the CRTI
#ifndef __RTI_H_
#define __RTI_H_
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CRTI
class ATL_NO_VTABLE CRTI :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CRTI, &CLSID_RTI>,
public IDispatchImpl<IRTI, &IID_IRTI, &LIBID_MUITINTERFACELib>,
public IDispatchImpl<IRTI1, &IID_IRTI1, &LIBID_MUITINTERFACELib> //手动
{
public:
CRTI()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_RTI)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CRTI)
//COM_INTERFACE_ENTRY(IRTI)
COM_INTERFACE_ENTRY2(IDispatch,IRTI) //手动!
COM_INTERFACE_ENTRY(IRTI1) //手动
END_COM_MAP()
// IRTI
public:
};
#endif //__RTI_H_
// MuitInterface.idl : IDL source for MuitInterface.dll
//
// This file will be processed by the MIDL tool to
// produce the type library (MuitInterface.tlb) and marshalling code.
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(DD70A5F5-A411-459a-B54C-05F8CF56E791),
dual,
helpstring("IRTI1 Interface"),
pointer_default(unique)
]
interface IRTI1 : IDispatch
{
};
[
object,
uuid(3F7E1AE7-FDC2-41D6-8AC6-F24BECCA3F44),
dual,
helpstring("IRTI Interface"),
pointer_default(unique)
]
interface IRTI : IDispatch //手动添加的空接口
{
};
[
uuid(5F090D9A-8E8A-4EA7-AA92-2D7E03238146),
version(1.0),
helpstring("MuitInterface 1.0 Type Library")
]
library MUITINTERFACELib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(D096EC0F-CBB6-4286-B453-695B6E0FBD41),
helpstring("RTI Class")
]
coclass RTI
{
[default] interface IRTI;
interface IRTI1; //手动
};
};
.cpp:
// RTI.h : Declaration of the CRTI
#ifndef __RTI_H_
#define __RTI_H_
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CRTI
class ATL_NO_VTABLE CRTI :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CRTI, &CLSID_RTI>,
public IDispatchImpl<IRTI, &IID_IRTI, &LIBID_MUITINTERFACELib>,
public IDispatchImpl<IRTI1, &IID_IRTI1, &LIBID_MUITINTERFACELib> //手动
{
public:
CRTI()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_RTI)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CRTI)
//COM_INTERFACE_ENTRY(IRTI)
COM_INTERFACE_ENTRY2(IDispatch,IRTI) //手动!
COM_INTERFACE_ENTRY(IRTI1) //手动
END_COM_MAP()
// IRTI
public:
};
#endif //__RTI_H_
#1
用类向导直接生成,就没有这样的麻烦了啊.
#2
不难,就和c语言差不多,里面也可以有枚举等类型。
你的这个接口找不到是因为你手工漏加了一些东西!!
你的这个接口找不到是因为你手工漏加了一些东西!!
#3
在idl最后的
library ....
[default] interface ICDictionary;
interface ISpellCheck; // 这里也要加
library ....
[default] interface ICDictionary;
interface ISpellCheck; // 这里也要加
#4
BEGIN_COM_MAP(CCDictionary)
COM_INTERFACE_ENTRY2(ICDictionary)//手工改为COM_INTERFACE_ENTRY2
COM_INTERFACE_ENTRY(ISpellCheck)//手工加入的
END_COM_MAP()
COM_INTERFACE_ENTRY2(ICDictionary)//手工改为COM_INTERFACE_ENTRY2
COM_INTERFACE_ENTRY(ISpellCheck)//手工加入的
END_COM_MAP()
#5
写错了!下面是我以前给别人写的例子:
// MuitInterface.idl : IDL source for MuitInterface.dll
//
// This file will be processed by the MIDL tool to
// produce the type library (MuitInterface.tlb) and marshalling code.
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(DD70A5F5-A411-459a-B54C-05F8CF56E791),
dual,
helpstring("IRTI1 Interface"),
pointer_default(unique)
]
interface IRTI1 : IDispatch
{
};
[
object,
uuid(3F7E1AE7-FDC2-41D6-8AC6-F24BECCA3F44),
dual,
helpstring("IRTI Interface"),
pointer_default(unique)
]
interface IRTI : IDispatch //手动添加的空接口
{
};
[
uuid(5F090D9A-8E8A-4EA7-AA92-2D7E03238146),
version(1.0),
helpstring("MuitInterface 1.0 Type Library")
]
library MUITINTERFACELib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(D096EC0F-CBB6-4286-B453-695B6E0FBD41),
helpstring("RTI Class")
]
coclass RTI
{
[default] interface IRTI;
interface IRTI1; //手动
};
};
.cpp:
// RTI.h : Declaration of the CRTI
#ifndef __RTI_H_
#define __RTI_H_
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CRTI
class ATL_NO_VTABLE CRTI :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CRTI, &CLSID_RTI>,
public IDispatchImpl<IRTI, &IID_IRTI, &LIBID_MUITINTERFACELib>,
public IDispatchImpl<IRTI1, &IID_IRTI1, &LIBID_MUITINTERFACELib> //手动
{
public:
CRTI()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_RTI)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CRTI)
//COM_INTERFACE_ENTRY(IRTI)
COM_INTERFACE_ENTRY2(IDispatch,IRTI) //手动!
COM_INTERFACE_ENTRY(IRTI1) //手动
END_COM_MAP()
// IRTI
public:
};
#endif //__RTI_H_
// MuitInterface.idl : IDL source for MuitInterface.dll
//
// This file will be processed by the MIDL tool to
// produce the type library (MuitInterface.tlb) and marshalling code.
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(DD70A5F5-A411-459a-B54C-05F8CF56E791),
dual,
helpstring("IRTI1 Interface"),
pointer_default(unique)
]
interface IRTI1 : IDispatch
{
};
[
object,
uuid(3F7E1AE7-FDC2-41D6-8AC6-F24BECCA3F44),
dual,
helpstring("IRTI Interface"),
pointer_default(unique)
]
interface IRTI : IDispatch //手动添加的空接口
{
};
[
uuid(5F090D9A-8E8A-4EA7-AA92-2D7E03238146),
version(1.0),
helpstring("MuitInterface 1.0 Type Library")
]
library MUITINTERFACELib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(D096EC0F-CBB6-4286-B453-695B6E0FBD41),
helpstring("RTI Class")
]
coclass RTI
{
[default] interface IRTI;
interface IRTI1; //手动
};
};
.cpp:
// RTI.h : Declaration of the CRTI
#ifndef __RTI_H_
#define __RTI_H_
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CRTI
class ATL_NO_VTABLE CRTI :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CRTI, &CLSID_RTI>,
public IDispatchImpl<IRTI, &IID_IRTI, &LIBID_MUITINTERFACELib>,
public IDispatchImpl<IRTI1, &IID_IRTI1, &LIBID_MUITINTERFACELib> //手动
{
public:
CRTI()
{
}
DECLARE_REGISTRY_RESOURCEID(IDR_RTI)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CRTI)
//COM_INTERFACE_ENTRY(IRTI)
COM_INTERFACE_ENTRY2(IDispatch,IRTI) //手动!
COM_INTERFACE_ENTRY(IRTI1) //手动
END_COM_MAP()
// IRTI
public:
};
#endif //__RTI_H_