Doubt about DispHelper

New to FreeBASIC? Post your questions here.
Post Reply
TDT
Posts: 32
Joined: Nov 16, 2005 22:34

Doubt about DispHelper

Post by TDT »

I'm trying to use this code

Code: Select all


dhGetValue("%s", @CONTEUDO, ieApp2, ".document.frames.item(1).document.body.outerText")
to get the content of the second frame of a website but I'm getting the follow error

Member: .document.frames.item(0).document.body.outerText
Function: GetValue
Error In: InvokArray
Error: Não há suporte para esta interface
(It doesn't have support for this interface)
Code: 80004002
Source: IDispatch Interface

I made a little debug and the interface is "item", 'cause if I put only ".document.frames.item" it already returns this error. And this doesn't occurs with ".document.frames"

What I want to know is: This message error means that DISPHELPER doesn't support the ITEM interface of frames or this command doesn't exists and I have to use other simmilar ('cause in javascript this command exists)?

If anyone have another way to do this and can post here, I'll have to thank.
MystikShadows
Posts: 612
Joined: Jun 15, 2005 13:22
Location: Upstate NY
Contact:

Post by MystikShadows »

This might not be relevent. But in Javascript for examples, to access a specific frame I would need to change:

Code: Select all

dhGetValue("%s", @CONTEUDO, ieApp2, ".document.frames.item(1).document.body.outerText")
to

Code: Select all

dhGetValue("%s", @CONTEUDO, ieApp2, ".document.frames[1].document.body.outerText")
Perhaps if you changed it this way it might help.
TDT
Posts: 32
Joined: Nov 16, 2005 22:34

Post by TDT »

Hi MystikShadows,

I already tried and it doesn't work.. the disphelper returns the follow error:

Member: .document.frames[1].document.body.outerText
Function: GetValue
Error In: InvokeArray
Error: Object doesn't support this property or method: 'frames[1]'
Code: 80020006
Source: IDispatch Interface

This error is because doesn't existis a object "iframe" in the document.
So ".document.frames[n]" is for IFRAME tags and ".document.frames.item(n)" is for each FRAME tag inside a FRAMESET.


So, anyone could try to help?

Thx.
thatsgreat2345
Posts: 5
Joined: May 02, 2006 23:25

Post by thatsgreat2345 »

Untested, but I have made an InternetExplorer library of functions. It isn't complete yet but I don't plan on releasing it but here are 2 of the functions you can use.

Code: Select all

#Include "disphelper/disphelper.bi"
Dim CONTEUDO As Any Ptr
Dim sText As LPSTR
Dim iInt As Integer
CONTEUDO = _IEFrameGetCollection(ieapp2, 1)
iInt = _IEIsFrameSet(CONTEUDO)
If iInt Thens
dhGetValue("%s",@sText,CONTEUDO,".document.body.outertext")
Print *sText
EndIf

Function _IEFrameGetCollection(oObject As Any Ptr, iIndex As Integer = -1) As Any Ptr
	Dim oReturn As Any Ptr
	Dim iExtended As Integer
	'iIndex = CInt(iIndex)
	dhGetValue("%d",@iExtended,oObject,".document.parentwindow.frames.length")
		If iIndex < -1 Then
				dhGetValue("%o",@oReturn,oObject,".document.parentwindow.frames")
				Return oReturn
		Elseif ((iIndex > -1) And (iIndex < iExtended)) Then
				dhGetValue("%o",@oReturn,oObject,".document.parentwindow.frames.item(%d)",iIndex)
				Return oReturn
		EndIf 

End Function

Function _IEIsFrameSet(oObject As Any Ptr) As Integer
	Dim oReturn As LPSTR
	dhGetValue("%s",@oReturn,oObject,".document.body.tagName")
	If *oReturn = "FRAMESET" Then
		Return 1
	Else
		Return 0
	EndIf
End Function

EDIT:
I tested it out, and Access is denied. I'm not sure why , possibly some cross site scripting prevention , not totally sure.
Last edited by thatsgreat2345 on Apr 28, 2008 3:57, edited 1 time in total.
TDT
Posts: 32
Joined: Nov 16, 2005 22:34

Post by TDT »

Hi, thatsgreat2345

I test and I got the same error 'cause the "frames.item" ...

"It doesn't have support for this interface"



So..we're at the begin again :/
thatsgreat2345
Posts: 5
Joined: May 02, 2006 23:25

Post by thatsgreat2345 »

TDT wrote:Hi, thatsgreat2345

I test and I got the same error 'cause the "frames.item" ...

"It doesn't have support for this interface"



So..we're at the begin again :/

Code: Select all

http://msdn2.microsoft.com/en-us/library/ms535258(VS.85).aspx
and a quote from MSDN

Code: Select all

You can access the iframe object's properties, but not its contents.
It should be working but just getting an access denied.
and remember this is based on a 0-Based index. so 1 is 0 , 1 is 2 . So if you are getting the first frame, you need 0 not 1.

Plus I fixed the problem in the bottom post, I forgot the .document.body. part before calling the .outertext

Code: Select all

Function _IEFrameGetCollection(oObject As Any Ptr, iIndex As Integer = -1) As Any Ptr
	Dim oReturn As Any Ptr
	Dim iExtended As Integer
	Dim sText As LPSTR
	'iIndex = CInt(iIndex)
	dhGetValue("%d",@iExtended,oObject,".document.parentwindow.frames.length")
		If iIndex < -1 Then
				dhGetValue("%o",@oReturn,oObject,".document.parentwindow.frames")
				Return oReturn
		Elseif ((iIndex > -1) And (iIndex < iExtended)) Then
					Print iIndex
					Print iExtended
					Sleep 2000
					WITH1(oReturn,oObject,".document.parentwindow.frames.item(%d)",iIndex)
						dhGetValue("%s",@sText,oReturn,".document.body.outertext")
					END_WITH(oReturn)
					Print *sText
				Return oObject
		EndIf 

End Function
TDT
Posts: 32
Joined: Nov 16, 2005 22:34

Post by TDT »

The last code doesn't give me an error..

But the var sText didn't get anything..
It still empty..



BUT... your link in MSDN help me..
You give me the link that refers to IFRAME..
and what I want to get is FRAME (without I)

Then I read the FRAME object in MSDN..
and there.. I got this method..

.document.parentWindow.frames.NAME_OF_FRAME.document.body.outerText

and I got the CODE! :D



I would like to say thank you for all.

:)


EDIT:

I tested in 2 sites.. in the first I got Access denied too.. and in the other I got the information.. so.. you're right thatsgreat2345, some script blocks the access at the first site. ;)
thatsgreat2345
Posts: 5
Joined: May 02, 2006 23:25

Post by thatsgreat2345 »

TDT wrote:The last code doesn't give me an error..

But the var sText didn't get anything..
It still empty..



BUT... your link in MSDN help me..
You give me the link that refers to IFRAME..
and what I want to get is FRAME (without I)

Then I read the FRAME object in MSDN..
and there.. I got this method..

.document.parentWindow.frames.NAME_OF_FRAME.document.body.outerText

and I got the CODE! :D



I would like to say thank you for all.

:)


EDIT:

I tested in 2 sites.. in the first I got Access denied too.. and in the other I got the information.. so.. you're right thatsgreat2345, some script blocks the access at the first site. ;)
When you get text it is stored it returns the pointer with LPSTR, so you hae to refer to it with a *. So Dim sText as LPSTR , and to get the text you gotta do *sText, but good luck with whatever you are doing.
TDT
Posts: 32
Joined: Nov 16, 2005 22:34

Post by TDT »

thatsgreat2345 wrote:When you get text it is stored it returns the pointer with LPSTR, so you hae to refer to it with a *. So Dim sText as LPSTR , and to get the text you gotta do *sText, but good luck with whatever you are doing.
I know this.. and I use it .. but the *sText still empty :P~
Post Reply