[英]Change div innerHTML through IHTMLDocument2 and C++
我正在嘗試使用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”代替,我不明白為什么,這可能是安全問題嗎?
謝謝
根據MSDN文檔 ,傳遞給put_innerText
的字符串的類型為BSTR
。
所以,我建議嘗試這樣的代碼:
CComBSTR text(OLESTR("hello"));
hr = htmldiv->put_innerText(text);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.