下面的接口该怎么定义?

weiym 2005-07-20 07:11:04
刚用ATL写COM ,像下面这样的接口在idl文件中该怎么定义?具体声明和实现时要注意什么?谢谢
[id(1),helpstring("get all command head attributes")] HRESULT getAllHeaders([out,retval] IXMLDOMNamedNodeMapPtr pRet);
[id(2),helpstring("Parse DOM from object")] HRESULT parseFromObject([in] IXMLDOMElementPtr oInitCmd);
...全文
189 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
weiym 2005-07-22
  • 打赏
  • 举报
回复
[id(1),helpstring("get element")] HRESULT getElement([out,retval] IXMLDOMElement** pRet);
该怎么定义啊
weiym 2005-07-22
  • 打赏
  • 举报
回复
楼上的,那传出参数是IXMLElement* ,总不能也用IDispatch*代替了吧
weiym 2005-07-21
  • 打赏
  • 举报
回复
主要是在ICommandMessage 接口里引入IXMLDOMElement,不知道该怎么用,好郁闷
weiym 2005-07-21
  • 打赏
  • 举报
回复
这是我的IDL文件:
// HCN2.idl : IDL source for HCN2.dll
//

// This file will be processed by the MIDL tool to
// produce the type library (HCN2.tlb) and marshalling code.

import "oaidl.idl";
import "ocidl.idl";
import "MSXML.IDL";
[
object,
uuid(3E300029-64FF-420F-B93B-2422DDA63E4D),
dual,
helpstring("IGzip Interface"),
pointer_default(unique)
]
interface IGzip : IDispatch
{
[id(1),helpstring("compress the string sSrc")] HRESULT compressString([in] BSTR sSrc,[out,retval] BSTR* sRet);
[id(2),helpstring("compress the string sSrc with iDeep option flag")] HRESULT compressStringEx([in] BSTR sSrc,[in] LONG iDeep,[out,retval] BSTR* sRet);
[id(3),helpstring("uncompress the string sSrc")] HRESULT uncompressString([in] BSTR sSrc,[in,defaultvalue(0)] LONG iOriginalSize,[out,retval] BSTR* sRet);
[id(4),helpstring("get the CRC of the string sSrc")] HRESULT crc([in] BSTR sSrc,[out,retval] BSTR* sRet);
[id(5),helpstring("read from ReadFromFile by binary access")] HRESULT ReadFromFile([in] BSTR FileName,[out,retval] BSTR* sRet);
[id(6),helpstring("write string buf to file filename")] HRESULT WriteToFile([in] BSTR FileName,[in] BSTR buf);
};
[
object,
uuid(9A5CBCA9-ECEC-4B9D-9E6D-E4B4253AA521),
dual,
helpstring("IBase64 Interface"),
pointer_default(unique)
]
interface IBase64 : IDispatch
{
[id(1),helpstring("get the length of unicode string asContents if change it to ascii")] HRESULT strUnicodeLen([in] BSTR asContents,[out,retval] LONG* lRet);
[id(2),helpstring("change the unicode string asContents to a ascii string ")] HRESULT toAnsi([in] BSTR asContents,[out,retval] BSTR* sRet);
[id(3),helpstring("change the ascii string asContents to a unicode string ")] HRESULT toUnicode([in] BSTR asContents,[out,retval] BSTR* sRet);
[id(4),helpstring("encode ascii string asContents to base64")] HRESULT encode([in] BSTR asContents,[out,retval] BSTR* sRet);
[id(5),helpstring("decode base64 string asContents to ascii")] HRESULT decode([in] BSTR asContent,[out,retval] BSTR* sRet);
};
[
object,
uuid(36013D81-94CE-494D-91F6-95EB07D76B20),
dual,
helpstring("ICommandMessage Interface"),
pointer_default(unique)
]
interface ICommandMessage : IDispatch
{

[id(1),helpstring("parse DOM from file")] HRESULT parseFromFile([in] BSTR sCmdFilePath);
[id(2),helpstring("parse DOM from string")] HRESULT parseFromString([in] BSTR sCmdText);
[id(3),helpstring("Parse DOM from object")] HRESULT parseFromObject([in] IXMLElement* oInitCmd);
[id(4),helpstring("set header attribute value")] HRESULT setHeader([in] LONG iHeader,[in] BSTR sValue);
[id(5),helpstring("get header attribute value")] HRESULT getHeader([in] LONG iHeader,[out,retval] BSTR* sRet);
[id(6),helpstring("set extend attribute value")] HRESULT setExtendHeader([in] BSTR sName,[in] BSTR sValue);

};

[
uuid(B96B0A40-D6A4-46A0-9BC8-872F294E18EA),
version(1.0),
helpstring("HCN2 1.0 Type Library")
]
library HCN2Lib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");

enum Header
{
SERVICEID = 0,
CMDTYPE = 1,
MSGMODELKEY = 2,
DESTID = 3,
CMDMODE = 4,
ECODE = 5,
EINFO = 6
};
[
uuid(3B3BB137-76B7-4824-8F02-2FE8873AAE27),
helpstring("Gzip Class")
]
coclass Gzip
{
[default] interface IGzip;
};
[
uuid(8A91D2F1-924A-4243-BB8E-DA750C3F34B7),
helpstring("Base64 Class")
]
coclass Base64
{
[default] interface IBase64;
};
[
uuid(3B9F1F24-485F-48E3-877F-F4ABB97864CF),
helpstring("CommandMessage Class")
]
coclass CommandMessage
{
[default] interface ICommandMessage;
};
};
编译出现的错误如下,帮忙看看原因啊
E:\项目\HCN组件(new)\HCN2\HCN2.idl(53) : warning MIDL2039 : interface does not conform to [oleautomation] attribute : [ Parameter 'oInitCmd' of Procedure 'parseFromObject' ( Interface 'ICommandMessage' ) ]
midl\oleaut32.dll : error MIDL2020 : error generating type library : LayOut failed : IXMLElementCollection
Error executing midl.exe.
weiym 2005-07-21
  • 打赏
  • 举报
回复
interface ICommandMessage : IDispatch
{
import "msxml.idl";
[id(1),helpstring("Parse DOM from object")] HRESULT parseFromObject([in] IXMLDOMElement* oInitCmd);
}
======
还是不行啊!
error MIDL2025 : syntax error : expecting a type specification near "IXMLDOMElement"
firmbird 2005-07-21
  • 打赏
  • 举报
回复
import msxml.idl
weiym 2005-07-21
  • 打赏
  • 举报
回复
[id(3),helpstring("Parse DOM from object")] HRESULT parseFromObject([in] IXMLDOMElement* oInitCmd);
-------
这样不行啊,编译提示错误
error MIDL2025 : syntax error : expecting a type specification near "IXMLDOMElement"
weiym 2005-07-21
  • 打赏
  • 举报
回复
up
wangweixing2000 2005-07-21
  • 打赏
  • 举报
回复
midl\oleaut32.dll : error MIDL2020 : error generating type library : LayOut failed : IXMLElementCollection
参数不用直接用接口
你用IDispatch*代替那些xml的接口即可!
firmbird 2005-07-20
  • 打赏
  • 举报
回复
不要用封装过的IXMLDOMElementPtr,直接用IXMLDOMElement*或者用IUnknown
AntonlioX 2005-07-20
  • 打赏
  • 举报
回复
up
ahhha 2005-07-20
  • 打赏
  • 举报
回复
idl文件中也是可以自定义数据类型的,你可以在idl文件的前面定义一个结构声明一下
IXMLDOMElementPtr

msdn中有说明。
weiym 2005-07-20
  • 打赏
  • 举报
回复
如果是常用的类型,我是会用的,可以有些对象类型不知道该怎么用了

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧