createElement("..."); pElement->text = "...";-6ren">
gpt4 book ai didi

c++ - IXMLDOMElement Ptr p Element->text = "..."会失败吗?

转载 作者:太空宇宙 更新时间:2023-11-04 13:56:56 25 4
gpt4 key购买 nike

伪代码如下:

IXMLDOMElementPtr pElement;
pElement = pXMLDom->createElement("...");
pElement->text = "..."; // My question is can this step fail (such as because of memory restrain)?

更多,请帮我理解“=”运算符的内部工作原理!我熟悉C,但是C++/Java新手。

谢谢!

最佳答案

“=”运算符的内部工作原理基于特定的 Microsoft C++ 扩展,与遗留 C++ 运算符重载无关。

参见 property (C++)

When the compiler sees a data member declared with this attribute on the right of a member-selection operator ("." or "->"), it converts the operation to a get or put function, depending on whether such an expression is an l-value or an r-value.

当您使用#import 从 DLL 中导入 COM 定义(作为 MSXML?.DLL)时,会创建一个 TLH 文件(C++ header ),它反射(reflect)了与 DLL 关联的类型库的内容。

在该 TLH 中,您将找到结构 IXMLDOMNode 的声明,它继承自 IDispatch,包含以下行:

__declspec(property(get=Gettext,put=Puttext))
_bstr_t text;

GettextPuttext 方法在导入期间生成的 TLI 文件(内联函数)中定义。

Puttext 方法是:

inline void IXMLElement::Puttext ( _bstr_t p ) {
HRESULT _hr = put_text(p);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
}

put_text 方法是通过接口(interface)指针的原始调用,并且对于此类调用,一如既往地返回一个 HRESULT。所以,是的,理论上,这一步可能会失败。

关于c++ - IXMLDOMElement Ptr p Element->text = "..."会失败吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21013295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com