描述:
在开发ATL控件的时候选择了“支持MFC”选项之后,
在VB,VF等开发环境里面不能使用ATL控件,VB提示
“System Error &H80004005(-2147467259),不支持此接口”
VFP提示“OLE error code 0x80004005: Unspecified error”
通过调试发现只要将自己手动添加的三个属性宏去掉,
//PROP_ENTRY("DisplayNumber",1,CLSID_NULL)
//PROP_ENTRY("DispLegend",2,CLSID_NULL)
//PROP_ENTRY("BarStyle",3,CLSID_NULL)
问题就解决了,而一旦添加这三个宏其中的任何一个,在VB,VF里就会出现上面描述的症状。
现在的问题是:为什么属性持久性会失败?如果没有上面的宏,尽管ATL 为我
做了三对(get、put)函数,但是只能在运行的时候设置属性,并不能够显示持久性。
解决方案1:
这样做:
//PROP_ENTRY("DisplayNumber",1,CLSID_NULL)
//PROP_ENTRY("DispLegend",2,CLSID_NULL)
//PROP_ENTRY("BarStyle",3,CLSID_NULL)
将上面三个宏中的第二个参数,换成你COM类的IDL申明语言中关于这三个属性的ID号,也就是
说这个1,2,3是错误的,要根据IDL文件中的ID值来绑定属性值。
比如IDL中是这样的(ATL框架自动为你添加的代码)
[propget, id(5), helpstring("property DisplayNumber")] HRESULT DisplayNumber
[propget, id(6), helpstring("property DisplayLegned")] HRESULT DisplayLegned
[propget, id(7), helpstring("property BarStyle")] HRESULT BarStyle
那么你的宏应该这样:
PROP_ENTRY("DisplayNumber",5,CLSID_NULL)
PROP_ENTRY("DispLegend",6,CLSID_NULL)
PROP_ENTRY("BarStyle",7,CLSID_NULL)
interface ISWBomInfo2 : IDispatch
{
[id(1), helpstring("")] HRESULT ConnectServer([out]BSTR *strErrMsg, [out, retval]long *result);
};
这是不是ID号
BEGIN_PROP_MAP does not save out the extent, that is, the dimensions of a property map, because an object using a property map may not have a user interface, so it would have no extent. If the object is an ActiveX control with a user interface, it has an extent. In this case, you must specify PROP_DATA_ENTRY in your property map to supply the extent.
Example
BEGIN_PROP_MAP( CMyClass )
PROP_DATA_ENTRY( "Width", m_nWidth, VT_UI4 )
PROP_DATA_ENTRY( "Height", m_nHeight, VT_UI4 )
PROP_ENTRY( "Property1", 1, CLSID_MyClassPropPage1 )
PROP_ENTRY_EX( "Caption", DISPID_CAPTION, CLSID_MyClassPropPage2, IID_IMyDual1 )
PROP_PAGE( CLSID_CMyClassPropPage3 )
END_PROP_MAP( )
不知道是否有用,如果你的atl有界面,用PROP_DATA_ENTRY()试试看