首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过IHTMLDocument2和C++更改div IHTMLDocument2

通过IHTMLDocument2和C++更改div IHTMLDocument2
EN

Stack Overflow用户
提问于 2017-09-19 13:23:41
回答 1查看 370关注 0票数 2

我试图通过这种方式使用IHTMLDocument2接口更改div的内容:

代码语言:javascript
复制
    IHTMLElementCollection* collection = NULL;
    IDispatch* mydiv;

    doc2->get_all(&collection);
    long count;
    collection->get_length(&count);     //just to check I get something

    CComVariant varstr = L"mydivname";
    CComVariant varint = 0;
    collection->item(varstr, varint, &mydiv);    //this works I get the div
    IHTMLElement* htmldiv;
    mydiv->QueryInterface(IID_IHTMLElement, (void**)&htmldiv);

    CComBSTR html;
    htmldiv->get_innerHTML(&html);      //works too, I get the current content

    HRESULT hr=htmldiv->put_innerText(L"hello");      //this does not work but returns S_OK

    collection->Release();

所以我的div的内容被清除了,没有被替换成"hello",我不明白为什么,这会是一个安全问题吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-19 13:32:06

根据MSDN文档,传递给put_innerText的字符串是BSTR类型的。

所以,我建议尝试一些这样的代码:

代码语言:javascript
复制
CComBSTR text(OLESTR("hello"));
hr = htmldiv->put_innerText(text);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46301676

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档