我试图通过这种方式使用IHTMLDocument2接口更改div的内容:
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",我不明白为什么,这会是一个安全问题吗?
谢谢
发布于 2017-09-19 13:32:06
根据MSDN文档,传递给put_innerText的字符串是BSTR类型的。
所以,我建议尝试一些这样的代码:
CComBSTR text(OLESTR("hello"));
hr = htmldiv->put_innerText(text);https://stackoverflow.com/questions/46301676
复制相似问题