Page 11 of 18
Posted: Fri May 18, 2007 8:55 am
by akj
@Amundo
Thank you for investigating, but your code does not do what I want, which can be summaried as:
Code: Select all
See if IE is already running. If not, Run IE.
Get (the now running) IE to navigate to a chosen page.
I do not wish to unnecessarily run an extra instance of IE.
Am I right in thinking that dhGetObject() is the appropriate way to see if IE is already running and to get it's object handle?
Posted: Sun May 20, 2007 12:05 am
by ts-soft
Small Update
After Bugfixing of Tailbite (thanks ABBKlaus) i have reduced the size
of UserLibs to more normal

Open Office .org
Posted: Mon May 21, 2007 6:54 am
by KIKI
How can i affect value from an object to another ?
Exemple in vb
Code: Select all
zone_de = $objectgetCellByrange("B1:B2")
zone_arrivee =$object.getCellByrange("C1:C2")
zone_arrivee.DataArray = zone_de.DataArray
With PureDisplay Helper
With PureDisplay Helper
Code: Select all
dhGetValue("%o", @mycell, mafeuille, ".getCellRangeByName(%T)", @"B1:B2")
dhGetValue("%o", @mycell, mafeuille, ".getCellRangeByName(%T)", @"C1:C2")
I don't know how to translate this instruction into PureDisplay helper
zone_arrivee.DataArray = zone_de.DataArray
Posted: Mon May 21, 2007 9:57 am
by mk-soft
Use Type Variant
Result is a Variant with type Array.
FF

Posted: Mon May 21, 2007 11:59 am
by KIKI
Tha,ks it's works Good
Posted: Wed May 23, 2007 12:39 pm
by akj
In an earlier post I was trying to use dhGetObject() to acquire object handles to running instances of Internet Explorer. I could not get this to work (and would still like to) but in the meantime, Amundo has pointed me to an alternative PowerBasic solution which I have translated to PureBasic in case anyone is interested.
Before running the PureBasic code (in Debug mode), I suggest you run two instances of Internet Explorer (showing two different websites) and an instance of Windows Explorer.
Code: Select all
; IE Instances AKJ 23-May-07
; Enumerate the ShellWindows collection and
; identify running instances of Internet Explorer
; Converted from: www.forum.it-berater.org/index.php?topic=575.0
; The comments are mainly the text of the original PowerBasic code
; #COMPILE EXE
; #DIM ALL
; #INCLUDE "WIN32API.INC"
EnableExplicit
IncludePath #PB_Compiler_Home+"Examples\DispHelper_Include"
XIncludeFile "DispHelper_Include.pb"
Procedure Warn(msg$)
MessageRequester("Warning", msg$, #MB_ICONWARNING)
EndProcedure
; FUNCTION PBMAIN () AS LONG
; LOCAL oShellApp AS DISPATCH
; LOCAL oShellWindows AS DISPATCH
; LOCAL oIE AS DISPATCH
; LOCAL vRes AS VARIANT
; LOCAL nCount AS LONG
; LOCAL i AS LONG
; LOCAL vIdx AS VARIANT
Define oShellApp, oShellWindows, oIE, oDoc ; Objects
Define nCount, i, vRes, program$, error, OK.b=#True
dhInitializeImp()
dhToggleExceptions(#True)
; SET oShellApp = NEW DISPATCH IN "Shell.Application"
; IF ISFALSE ISOBJECT(oShellApp) THEN EXIT FUNCTION
oShellApp = dhCreateObject("Shell.Application")
If oShellApp=0
OK = #False
Warn("Could not create Shell.Application object")
EndIf
; OBJECT CALL oShellApp.Windows TO vRes
; SET oShellWindows = vRes
; IF ISFALSE ISOBJECT(oShellWindows) THEN EXIT FUNCTION
If OK
error = dhGetValue("%o", @oShellWindows, oShellApp, ".Windows")
If error
OK = #False
Warn("Shell.Windows method failed")
EndIf
EndIf
; OBJECT GET oShellWindows.Count TO vRes
; nCount = VARIANT#(vRes)
If OK
error = dhGetValue("%d", @nCount, oShellWindows, ".Count")
If error
OK = #False
Warn("ShellWindows.Count failed")
EndIf
EndIf
If OK
Debug "Shell windows count = "+Str(nCount)
; FOR i = 0 TO nCount - 1
For i = 0 To nCount - 1
; vIdx = i AS LONG
; OBJECT CALL oShellWindows.Item(vIdx) TO vRes
; SET oIE = vRes
error = dhGetValue("%o", @oIE, oShellWindows, ".Item(%d)", i)
If error
OK = #False
Warn("ShellWindows.Item() method failed")
EndIf
; IF ISTRUE ISOBJECT(oIE) THEN
; OBJECT GET oIE.FullName TO vRes
; MSGBOX VARIANT$(vRes)
; END IF
If OK
Debug ""
Debug "Shell object handle = $"+Hex(oIE)
error = dhGetValue("%T", @vRes, oIE, ".FullName")
If error
Warn("IE.FullName method failed")
Else
program$ = GetFilePart(PeekS(vRes))
Debug "Program = "+program$
If UCase(program$)="IEXPLORE.EXE" ; If Internet Explorer
; Get IE title text (code added by AKJ)
error = dhGetValue("%o", @oDoc, oIE, ".Document") ; Set oDoc = ieApp.Document
If error
Warn("IE.Document method failed")
Else
error = dhGetValue("%T", @vRes, oDoc, ".Title") ; title = oDoc.title
If error
Warn("IE.Document.Title method failed")
Else
Debug "IE Title = "+PeekS(vRes)
EndIf
EndIf
Else
Debug "(Not Internet Explorer)"
EndIf ; IE
EndIf
EndIf ; OK
; NEXT
Next i
EndIf ; OK
; END FUNCTION
dhFreeString(vRes)
dhReleaseObject(oIE)
dhReleaseObject(oShellWindows)
dhReleaseObject(oShellApp)
dhUninitialize()
End
Posted: Wed May 23, 2007 8:15 pm
by ts-soft
@akj
nice code, but you have always to use dhFreeString(vRes), not only ones at end

Posted: Wed May 23, 2007 8:29 pm
by akj
@ts-soft
I presume you mean that I should dhFreeString(vRes) each time around the FOR loop, rather than once only at the end of the program.
I used to think the same, but I did extensive testing of loops using %T and %s format codes and I never once got an error through not releasing the corresponding string pointers.
Can you supply an example where not using dhFreeString() in a loop does cause a problem?
Posted: Wed May 23, 2007 8:51 pm
by ts-soft
If you get a string, the lib uses SysAllocString_() for allocating memory.
This memory is to be freed, if you use the same value for next string, the old
one is still allocated, so you have a memoryleak
COM uses Ole-Strings!
Posted: Wed May 23, 2007 10:19 pm
by akj
@ts-soft
Sorry, but I didn't realise the problem was memory leakage.
Posted: Wed May 23, 2007 10:27 pm
by ts-soft
vRes becomes the pointer to a stringbuffer!
if you use it twice, vRes becomes a new pointer to another stringbuffer, so
you have no change to free the old one.
There is no GarbageCollector, like PB have
Posted: Fri Jun 01, 2007 2:26 pm
by ts-soft
Posted: Thu Jun 07, 2007 12:56 pm
by Kwai chang caine
Excuse me for my very bad english.
Congratulation at TS-Soft for his cool lib.
I have a problem.
I try to use the fantastic lib with a OLE application in my job.
in Visual basic the soft ATRA is running like this :
Code: Select all
Dim System As Object, Session As Object
Set System = GetObject(, "ATRA.System") ' Gets the system object
Set System = CreateObject("ATRA.System") ' Gets the system object
Set Session = System.ActiveSession
Session.Screen.row = 24 ' Mise sur la ligne 24
Session.Screen.Col = 4 ' Mise sur la colonne 4
Session.Screen.SendKeys ("Coucou") ' Ecris le mot coucou
In purebasic i have write this code :
Code: Select all
RunProgram ("C:\Program Files\Atra.exe")
Define.l Atra
Atra = dhCreateObject("Atra.system")
If Atra
dhPutValue (Atra, "Atra.Screen.Row", 24)
dhPutValue (Atra, "Atra.Screen.Col", 4)
dhPutValue (Atra, "Atra.Screen.SendKeys", @"Coucou")
dhReleaseObject (Atra)
Atra = 0
EndIf
He don't works
Somebody have an idea why ?
Thanks
Posted: Thu Jun 07, 2007 1:12 pm
by Kiffi
Hello Kwaï chang caïne,
please try this:
Code: Select all
dhPutValue (Atra, "Atra.Screen.Row = %d", 24)
dhPutValue (Atra, "Atra.Screen.Col = %d", 4)
dhCallMethod (Atra, "Atra.Screen.SendKeys(%T)", @"Coucou")
Greetings ... Kiffi
Posted: Thu Jun 07, 2007 1:14 pm
by ts-soft
I can't test it, but i think there is missing something like this:
Code: Select all
dhCallMethod(Atra, "System.ActiveSession")