Page 1 of 1

Question on IHTMLFrameBase2

Posted: Fri Oct 14, 2005 10:53 pm
by DevilDog
I've got a frames collection pointer and am trying to loop through the frames and get a reference to the ITHMLDocument2 within it.

Here's the code:

Code: Select all

  
If Document\get_parentWindow(@xWindow.IHTMLWindow2) = #S_OK 
    If xWindow\get_frames(@FramesCollection.IHTMLFramesCollection2_FIXED) = #S_OK 
      ; read the number of elements in this collection 
      ; 
      FramesCollection\get_length(@Total2)
      Debug "Number of Frames: "+Str(Total2) 
      For index2 = 0 To Total2-1 
          varIndex2.VARIANT_SPLIT\VAriant\vt = #VT_I4 
          varIndex2\VAriant\lVal = index      
          
          xFrameElementDispatch.IDispatch = 0 
          If FramesCollection\item(@varindex2, @xFrameElementDispatch.IDispatch) = #S_OK 
            If xFrameElementDispatch ; must check this value according to the docs, as even on failure, #S_OK is returned 

;  This next line does not work - invalid memory access
              If xFrameElementDispatch\QueryInterface(?IID_IHTMLFrameBase2, @xBaseDispatch.IHTMLFrameBase2 )= #S_OK  
               If xBaseDispatch\get_contentWindow(@Document2.IHTMLDocument2)
So I'm trying to get a pointer to a frame object in order to get the pointer to the IHTMLDocument2 object within it in order to access it's contents.

Freak posted an example that uses IHTMLFrameBase2 but it gets to it by looping through the tags and finding the <Frame> or <IFrame> tags and then retrieving the IHTMLFrameBase2 reference.

What am I missing? Help!

Posted: Sat Oct 15, 2005 12:05 am
by freak
the second argument to FramesCollection\item() must be a VARIANT pointer too.
So pass a pointer to an empty VARIANT structure there, and after a sucessfull
return, the pDispVal member of the structure holds the IDispatch pointer, or 0 on failure.

It crashes at the later line because you do not receive the correct pointer in this call.

Posted: Tue Oct 18, 2005 11:32 pm
by DevilDog
Freak,
That worked. I'm getting a pointer value in pdispval.

What am I doing wrong in the last IF below that is causing an error?

Code: Select all

          varIndex2.VARIANT_SPLIT\VAriant\vt = #VT_I4  
          varIndex2.VARIANT_SPLIT\VAriant\lVal = index      
          varIndex3.VARIANT_SPLIT
          
          
          xFrameElementDispatch.IDispatch = 0 
          If FramesCollection\item(@varIndex2, @varIndex3) = #S_OK 
            If varIndex3.VARIANT_SPLIT\VAriant\pdispVal  ; this shows a long value           

                xFrameElementDispatch.IDispatch = @varIndex3.VARIANT_SPLIT\VAriant\pdispVal  ; not sure if I'm using this correctly? 

                   If xFrameElementDispatch\QueryInterface(?IID_IHTMLWindow2, @Document2.IHTMLDocument2 )= #S_OK ;This gives an error
                       HookLinks(Document2.IHTMLDocument2)
                   EndIf
            EndIf
          EndIf
I just haven't gotten the hang of these variants, idispatch, etc. But I did buy a C++ book called "Thinking in C++" which seems to be pretty good but there's nothing like learning under fire. Thanks again in advance.

Posted: Wed Oct 19, 2005 1:03 pm
by freak

Code: Select all

xFrameElementDispatch.IDispatch =  @varIndex3.VARIANT_SPLIT\VAriant\pdispVal
should be

Code: Select all

xFrameElementDispatch.IDispatch = varIndex3.VARIANT_SPLIT\VAriant\pdispVal

Posted: Thu Oct 20, 2005 2:55 am
by Dare2
Interesting announcement! :)