Question on IHTMLFrameBase2

Just starting out? Need help? Post your questions and find answers here.
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

Question on IHTMLFrameBase2

Post 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!
When all is said and done, more is said than done.
freak
PureBasic Team
PureBasic Team
Posts: 5941
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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.
quidquid Latine dictum sit altum videtur
DevilDog
Enthusiast
Enthusiast
Posts: 210
Joined: Thu Aug 04, 2005 9:32 pm
Location: Houston, Tx.

Post 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.
When all is said and done, more is said than done.
freak
PureBasic Team
PureBasic Team
Posts: 5941
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Code: Select all

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

Code: Select all

xFrameElementDispatch.IDispatch = varIndex3.VARIANT_SPLIT\VAriant\pdispVal
quidquid Latine dictum sit altum videtur
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Interesting announcement! :)
@}--`--,-- A rose by any other name ..
Post Reply