开发者

How to correctly call on onsubmit event using IWebBrowser2 interfaces (using c++)

I'm trying to call the onsubmit programmatically without clicking in the form button.

First i try to simply call the submit function of the IHTMLFormElement interface but the form does not correctly processed the input data:

CComPtr<IHTMLFormElement> ppvForm;
ppvForm->submit();

I read in the documentation and it says that the submit function do not call the onsubmit event, then i try to call the onsubmit event by using the IDispatch invoke method provided by the get_onsubmit of the IHTMLFormElement interface:

CComPtr<IHTMLFormElement> ppvForm;
...
_variant_t vResult;
_variant_t tvar;
hResult = ppvForm->get_onsubmit(&tvar); // <<< i get a NULL VARIANT here 

DISPPARAMS params = {0};
hResult = tvar.pdispVal->Invoke(
    DISPID_VALUE, 
    IID_NULL,
    LOCALE_SYSTEM_DEFAULT, 
    DISPATCH_METHOD, 
    &params, 
    &vResult, 
    NULL, 
    NULL);
if( SUCCEEDED(hResult) )
...

But the ppvForm->get_onsubmit call return S_OK with a NULL variant... (don't know why?!)

And in the end tried the fireEvent fro开发者_运维百科m the IHTMLDocument4 interface:

HRESULT hrRes=S_FALSE;
CComPtr<IHTMLDocument4> piDoc;
...
VARIANT_BOOL varRet;
CComPtr<IHTMLEventObj>pEvent;
hrRes=piDoc->createEventObject(NULL, &pEvent);

_variant_t vtEvent(pEvent);
hrRes=piDoc->fireEvent(_bstr_t(_T("onsubmit")), &vtEvent, &varRet);

The fireEvent now returns always E_INVALIDARG! don't know why? don't know if i need to put something in the vtEvent or the "onsubmit" string is invalid, don't know.

Can anyone point me in the right direction or tell me what I'm doing wrong?


If get_onsubmit() is returning S_OK and a NULL handler, then there is simply no onsubmit event handler assigned to the form to begin with.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜