Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 352081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:42:13+00:00 2026-05-12T11:42:13+00:00

Basically I want to develop a BHO that validates certain fields on a form

  • 0

Basically I want to develop a BHO that validates certain fields on a form and auto-places disposable e-mails in the appropriate fields (more for my own knowledge). So in the DOCUMENTCOMPLETE event I have this:

for(long i = 0; i < *len; i++)
{
    VARIANT* name = new VARIANT();
    name->vt = VT_I4;
    name->intVal = i;
    VARIANT* id = new VARIANT();
    id->vt = VT_I4;
    id->intVal = 0;
    IDispatch* disp = 0;
    IHTMLFormElement* form = 0;
    HRESULT r = forms->item(*name,*id,&disp);
    if(S_OK != r)
    {
        MessageBox(0,L"Failed to get form dispatch",L"",0);// debug only
        continue;
    }
    disp->QueryInterface(IID_IHTMLFormElement2,(void**)&form);
    if(form == 0)
    {
        MessageBox(0,L"Failed to get form element from dispatch",L"",0);// debug only
        continue;
    }

    // Code to listen for onsubmit events here...         
}

How would I use the IHTMLFormElement interface to listen for the onsubmit event?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:42:14+00:00Added an answer on May 12, 2026 at 11:42 am

    Once you have the pointer to the element you want to sink events for, you would QueryInterface() it for IConnectionPointContainer and then connect to that:

    REFIID riid = DIID_HTMLFormElementEvents2;
    CComPtr<IConnectionPointContainer> spcpc;
    HRESULT hr = form->QueryInterface(IID_IConnectionPointContainer, (void**)&spcpc);
    if (SUCCEEDED(hr))
    {
        CComPtr<IConnectionPoint> spcp;
        hr = spcpc->FindConnectionPoint(riid, &spcp);
        if (SUCCEEDED(hr))
        {
            DWORD dwCookie;
            hr = pcp->Advise((IDispatch *)this, &dwCookie);
        }
    }
    

    Some notes:

    1. You probably want to cache dwCookie and cpc, since you need them later when you call pcp->Unadvise() to disconnect the sink.
    2. In the call to pcp->Advise() above, I pass this. You can use any object you have that implements IDispatch, which may or may not be this object. Design left to you.
    3. riid will be the event dispinterface you want to sink. In this case, you probably want DIID_HTMLFormElementEvents2.

    Here’s how to disconnect:

    pcp->Unadvise(dwCookie);
    

    Let me know if you have further questions.

    Edit-1:

    Yeah, that DIID was wrong. It should be: DIID_HTMLFormElementEvents2.

    Here is how I found it:

    C:\Program Files (x86)\Microsoft Visual Studio 8\VC\PlatformSDK>findstr /spin /c:"Events2" *.h | findstr /i /c:"form"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 160k
  • Answers 160k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try: pictureBox1.ImageLocation = "http://www.indianorphanages.net/images/india-political-map.gif"; May 12, 2026 at 11:42 am
  • Editorial Team
    Editorial Team added an answer I had the same problem. For Google API 1.2.2.0 Use… May 12, 2026 at 11:42 am
  • Editorial Team
    Editorial Team added an answer Try putting a current version of Xerces into the classspath,… May 12, 2026 at 11:42 am

Related Questions

I am looking to develop a system in which i need to assign every
I've been trying to develop a linq query that returns the ItemNumber column of
I'm looking for a open source .Net HTTP proxy library. Basically I want to
I develop code using .net, and sometimes using ruby. My friend wants me to
Good day folks, I'm in a need of a bit of guidance. Basically, I'm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.