Click here to Skip to main content
15,896,726 members
Home / Discussions / COM
   

COM

 
QuestionRegistering assembly for COM interop Pin
Sameer Bhawtankar28-Feb-09 0:44
Sameer Bhawtankar28-Feb-09 0:44 
AnswerRe: Registering assembly for COM interop Pin
Jonathan Davies28-Feb-09 1:54
Jonathan Davies28-Feb-09 1:54 
Questionneed Suggestions for Project? Pin
shaina223127-Feb-09 17:29
shaina223127-Feb-09 17:29 
AnswerRe: need Suggestions for Project? Pin
Jonathan Davies28-Feb-09 2:15
Jonathan Davies28-Feb-09 2:15 
Questionserial port programming using threads in c Pin
rao_abhilash26-Feb-09 19:37
rao_abhilash26-Feb-09 19:37 
AnswerRe: serial port programming using threads in c Pin
«_Superman_»26-Feb-09 21:12
professional«_Superman_»26-Feb-09 21:12 
QuestionHow to find DispIds for excel procedures? Pin
SNI26-Feb-09 1:36
SNI26-Feb-09 1:36 
Questionfail to get IHTMLElement from IHTMLFormElement Pin
computer_nerd24-Feb-09 5:03
computer_nerd24-Feb-09 5:03 
Hello all

I am getting the form objects from internet explorer and want to get all the elements from each form. To do this, I get the form collection from the html document object, get an interface to each form element in the collection then try to get an IID_IHTMLElement interface from the IID_IHTMLFormElement interface in order to get all the elements in the form, as recommended by MS. It all works on my machine and all others I've tried, except that on my friend's pc, the QueryInterface call fails with E_NOINTERFACE. I'm not that proficient in COM, so I wonder if there is something I'm doing wrong here so that it only works on some systems. He assures me that he has IE7 installed so not an old cranky version. Code as follows:

bool ret = true;
CComPtr<IHTMLElementCollection> spForms;
long numForms = 0L;
    CComPtr<IDispatch> spDisp;

// get collection of forms within web page
HRESULT hr = spDoc->get_forms(&spForms.p);
if (FAILED(hr) || !spForms)
{
    ret = false;
}

if (ret)
{
    // get number of forms in collection
    HRESULT hr = spForms->get_length(&numForms);
    if (FAILED(hr))
    {
        ret = false;
    }
}

if (ret)
{
    // process each form
    for (int formNumber = 0; ret && (formNumber < numForms); formNumber++)
    {
        BSTR bstr;
        CString formName;
        CComPtr<IHTMLElementCollection> spElements;
        CComPtr<IHTMLFormElement> spFormElement;
        CComPtr<IHTMLElement> spElement;
        long numElements = 0L;

        // get next form
        CComVariant vIdx(0, VT_I4);
        HRESULT hr = spForms->item(CComVariant(formNumber), vIdx, &spDisp.p);
        if (FAILED(hr) || !spDisp)
        {
            ret = false;
        }

        if (ret)
        {
            // get form interface
            HRESULT hr = spDisp->QueryInterface(
                IID_IHTMLFormElement, (void**) &spFormElement.p);
            if (FAILED(hr) || !spFormElement)
            {
                ret = false;
            }
        }

        if (ret)
        {
            // get form name
            hr = spFormElement->get_name(&bstr);
            if (FAILED(hr))
            {
                ret = false;
            }
        }

        if (ret)
        {
            // need to call IHTMLElement::all() instead of IHTMLFormElement::item(),
            // otherwise will only get the controls and not all the elements in the form,
            // such as the labels
            HRESULT hr = spFormElement->QueryInterface(!!!
                IID_IHTMLElement, (void**) &spElement.p);
            if (FAILED(hr) || !spElement)
            {
                // FAILS HERE WITH hr == E_NOINTERFACE!!!
                ret = false;
            }

            ...... etc
        }
    }
}

AnswerRe: fail to get IHTMLElement from IHTMLFormElement Pin
Jonathan Davies25-Feb-09 5:49
Jonathan Davies25-Feb-09 5:49 
GeneralRe: fail to get IHTMLElement from IHTMLFormElement Pin
computer_nerd27-Feb-09 12:48
computer_nerd27-Feb-09 12:48 
GeneralRe: fail to get IHTMLElement from IHTMLFormElement Pin
Jonathan Davies28-Feb-09 3:52
Jonathan Davies28-Feb-09 3:52 
GeneralRe: fail to get IHTMLElement from IHTMLFormElement Pin
computer_nerd1-Mar-09 1:30
computer_nerd1-Mar-09 1:30 
Questionshell Undo manager Pin
Frank Thielemann24-Feb-09 4:11
Frank Thielemann24-Feb-09 4:11 
QuestionImport COM exe server Pin
RevathiRamakumar23-Feb-09 22:31
RevathiRamakumar23-Feb-09 22:31 
AnswerRe: Import COM exe server Pin
Jonathan Davies25-Feb-09 5:11
Jonathan Davies25-Feb-09 5:11 
QuestionCOM ATL exe question Pin
Anthony988723-Feb-09 9:20
Anthony988723-Feb-09 9:20 
QuestionRe: COM ATL exe question Pin
CPallini23-Feb-09 22:39
mveCPallini23-Feb-09 22:39 
AnswerRe: COM ATL exe question [modified] Pin
RevathiRamakumar23-Feb-09 22:45
RevathiRamakumar23-Feb-09 22:45 
GeneralRe: COM ATL exe question Pin
CPallini23-Feb-09 22:51
mveCPallini23-Feb-09 22:51 
GeneralRe: COM ATL exe question Pin
RevathiRamakumar23-Feb-09 22:55
RevathiRamakumar23-Feb-09 22:55 
AnswerRe: COM ATL exe question Pin
Anthony988724-Feb-09 10:01
Anthony988724-Feb-09 10:01 
QuestionWritting Add in for PDF. Pin
SNI23-Feb-09 1:02
SNI23-Feb-09 1:02 
QuestionDeleting an Instance of IShellFolder Pin
gn0tto22-Feb-09 23:39
gn0tto22-Feb-09 23:39 
QuestionRe: Deleting an Instance of IShellFolder Pin
gn0tto27-Feb-09 2:09
gn0tto27-Feb-09 2:09 
QuestionWhat are the ways a COM dll can be used? + questions Pin
grassrootkit19-Feb-09 4:09
grassrootkit19-Feb-09 4:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.