PureDispHelper UserLib - Update with Includefile for Unicode

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post 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?
Anthony Jordan
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Small Update

After Bugfixing of Tailbite (thanks ABBKlaus) i have reduced the size
of UserLibs to more normal :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
KIKI
Enthusiast
Enthusiast
Posts: 145
Joined: Thu Dec 28, 2006 11:49 am
Location: FRANCE

Open Office .org

Post 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
User avatar
mk-soft
Always Here
Always Here
Posts: 6202
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Post by mk-soft »

Use Type Variant

Code: Select all

dhGetValue("%v", ...)
Result is a Variant with type Array.

FF :wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
KIKI
Enthusiast
Enthusiast
Posts: 145
Joined: Thu Dec 28, 2006 11:49 am
Location: FRANCE

Post by KIKI »

Tha,ks it's works Good
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post 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
Anthony Jordan
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

@akj
nice code, but you have always to use dhFreeString(vRes), not only ones at end :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post 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?
Anthony Jordan
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

@ts-soft

Sorry, but I didn't realise the problem was memory leakage.
Anthony Jordan
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post 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
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post by Kwai chang caine »

Excuse me for my very bad english. :oops:
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
ImageThe happiness is a road...
Not a destination
User avatar
Kiffi
Addict
Addict
Posts: 1484
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Post 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
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

I can't test it, but i think there is missing something like this:

Code: Select all

dhCallMethod(Atra, "System.ActiveSession")
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply