帮忙转换一段C++Builder代码 ( 积分: 100 )

  • 主题发起人 主题发起人 eaglepsm
  • 开始时间 开始时间
E

eaglepsm

Unregistered / Unconfirmed
GUEST, unregistred user!
我在用Delphi写一个浏览器,需要调用IDM_开头的一些接口(比如IDM_KEEPSELECTION),我用WebBrowser1.ExecWB(IDM_KEEPSELECTION,OLECMDEXECOPT_DODEFAULT)始终出错:“试图吊销一个未注册的拖放目标”,用WebBrowser1.QueryStatusWB(IDM_KEEPSELECTION)发现并不支持该接口,我想可能是ExecWB本来就不支持以IDM_开头的接口,查了一下全文检索,发现C++Builder的ExecWbEx函数可以,但Delphi的WebBrowser没有ExecWbEx函数,下面是函数的C++代码,各位能不能帮我翻译成Delphi,谢谢
void TForm1::ExecWBEx(int cmdID,TVariant *pvaIn,TVariant *pvaOut,int nCmdExecOpt)
{
IDispatch * WebDocument = static_cast<IDispatch *>(CppWebBrowser->Document);
IHTMLDocument2 *HTMLDocument = static_cast<IHTMLDocument2 *>(WebDocument);
if(HTMLDocument)
{
IOleCommandTarget *pCmd;
HRESULT hr=HTMLDocument->QueryInterface(IID_IOleCommandTarget,(void **)(&pCmd));
if(SUCCEEDED(hr))
{
pCmd->Exec(&CGID_MSHTML,cmdID,nCmdExecOpt,pvaIn,pvaOut);
}
}
}
 
uses mshtml;

procedure TForm1.ExecWBEx(cmdID: Integer; pvaIn, pvaOut: PVariant;
nCmdExecOpt: Integer);
var
WebDocument : IDispatch;
HTMLDocument: IHTMLDocument2;
pCmd : IOleCommandTarget;
Hr : HResult;
begin
WebDocument := (CppWebBrowser.Document as IDispatch);
HTMLDocument:= (WebDocument as IHTMLDocument2);
if HTMLDocument <> nil then
begin
HTMLDocument.QueryInterface(IID_IOleCommandTarget, pCmd);
if SUCCEEDED(Hr) then
pCmd.Exec(@CGID_MSHTML, cmdID, nCmdExecOpt, pvaIn, pvaOut);
end;
end;
 
接受答案了.
 
后退
顶部