Sign in to follow this  
Followers 0
MarkRobbins

Real OOP with AutoIt? Meet JSAIO...

20 posts in this topic

#1 ·  Posted (edited)

I've been thinking about this for the last couple of weeks, and I've finally got around to putting together a proof of concept.

As far as OOP goes, Javascript is a pretty damn good language -- very flexible, but lets look at some code. Here is a two button form for AutoIt written in Javascript.

var $=this;
var hgui;
this.MsgHandler_=function (m){
  if (m==$.AutoIt.GUI_EVENT_CLOSE) {
    $.AutoIt.GUIDelete(hgui);
    return true;
  }else if (m==button1) {
    $.AutoIt.Run("notepad.exe");
  }else if (m==button2) {
    alert('Thanks from a javascript alert box!');
  }
  return false;
}
var button1,button2;
function Example1(){
  var msg;
  hgui=$.AutoIt.GUICreate("My Gui",400,500);
  button1=$.AutoIt.GUICreateButton("Run Notepad",10,10,200,30);
  button2=$.AutoIt.GUICreateButton("Press Me",10,40,200,30);
  $.AutoIt.GUISetState($.AutoIt.SW_SHOW,hgui);
}
Example1();

This code would reside in an external file and be called by AutoIt.

I've created a framework in AutoIt using AutoItObject that is just big enough to make this code work.

Basically I am creating an AutoItObject, tacking on some core AutoIt functions and constants, and sending it off to play in Javascript land. There is much more to be tacked on.

Other than this AutoItObject being a proxy for AutoIt functionality, there is a Javascript COM object into which the javascript file is loaded, and a message loop that calls back into the javascript.

The framework is 300 lines of code.

Before I extend this, I want to know if AutoIt ALREADY has a COM object I that I can use like this. But I am thinking that even if it does, this hand-coded way would be better because you can make the calls pass objects instead of parameters.

Here is the framework:

#include <AutoItObject.au3>
#include <GUIConstants.au3>


Global $thisfile=@ScriptFullPath;
Global $logg=$thisfile&".log.txt";

Global $jsfile=$thisfile&".js";
;e C:\batch\borg\TestJsaio.au3.js

;fret not, you do not need, will be a no-op if not exist
Global Const $snarl="C:\batch\Snarl_CMD.exe";

; need script exit for AIO shutdown
OnAutoItExitRegister("EvtScriptExit")
_AutoItObject_StartUp()

; error handler
Global $oError
$oError = ObjEvent("AutoIt.Error", "_ErrFunc")

; JScript Com globals
Global $_ComObj_proxy
Global $_com
Global $_Js
JScriptInit()
;;;;;;;;;;;;;;;;;;;;;;;;;;done inits

;;;;;;;;;;; begin framework

; set up a mini framework of AutoIt Functions/constants and stick them on an object
Global $AutoItForCom=_AutoItObject_Create();
;_AutoItObject_AddMethod(ByRef $oObject, $sName, $sAutoItFunc, $fPrivate = False)
_AutoItObject_AddMethod($AutoItForCom,"GUICreate","GUICreate_AI")
_AutoItObject_AddMethod($AutoItForCom,"GUISetState","GUISetState_AI")
_AutoItObject_AddMethod($AutoItForCom,"GUIGetMsg","GUIGetMsg_AI")
_AutoItObject_AddMethod($AutoItForCom,"GUIDelete","GUIDelete_AI")
_AutoItObject_AddMethod($AutoItForCom,"MsgBox","MsgBox_AI")
_AutoItObject_AddMethod($AutoItForCom,"GuiCreateButton","GuiCreateButton_AI")
_AutoItObject_AddMethod($AutoItForCom,"Run","Run_AI")
;_AutoItObject_AddProperty(ByRef $oObject, $sName, $iFlags = $ELSCOPE_PUBLIC, $vData = "")
_AutoItObject_AddProperty($AutoItForCom, "SW_SHOW", $ELSCOPE_PUBLIC+$ELSCOPE_READONLY, @SW_SHOW)
_AutoItObject_AddProperty($AutoItForCom, "GUI_EVENT_CLOSE", $ELSCOPE_PUBLIC+$ELSCOPE_READONLY, $GUI_EVENT_CLOSE)


;;; here are the tie-ins that the object will call
Func GUICreate_AI($me,$title,$width,$height)
  #forceref $me
  ;GUICreate ( "title" [, width [, height [, left [, top [, style [, exStyle [, parent]]]]]]] )
  Local $rv=GUICreate($title,$width,$height)
  Return $rv
EndFunc
Func GUISetState_AI($me,$flag,$hwnd)
  #forceref $me
  ;GUISetState ( [flag [, winhandle]] )
  Local $rv=GUISetState($flag,HWnd($hwnd));need to covert Int32
  Return $rv
EndFunc
Func GUIGetMsg_AI($me,$advanced)
  #forceref $me
  Local $rv= GUIGetMsg ($advanced)
  Return $rv
EndFunc

Func GUIDelete_AI($me,$winhandle)
  #forceref $me
  Local $rv=GUIDelete($winhandle)
  Return $rv
EndFunc

Func MsgBox_AI($me,$flag,$title,$text)
  #forceref $me
  ;MsgBox ( flag, "title", "text" [, timeout [, hwnd]] )
  Local $rv=MsgBox($flag,$title,$text)
  Return $rv
EndFunc

Func GUICreateButton_AI($me,$text,$left,$top,$width=Default,$height=Default,$style=Default,$exstyle=Default)
  #forceref $me
  ;GUICtrlCreateButton ( "text", left, top [, width [, height [, style [, exStyle]]]] )
  Local $rv=GUICtrlCreateButton ( $text, $left, $top, $width, $height, $style, $exstyle)
  Return $rv
EndFunc

Func Run_AI($me,$program,$wkdir=Default,$show_flag=Default,$opt_flag=Default)
  #forceref $me
  ;Msg2("run",$program)
  Local $rv;
  If False Then
  ElseIf @NumParams==2 Then
    $rv=Run($program)
  ElseIf @NumParams==3 Then
    $rv=Run($program,$wkdir)
  ElseIf @NumParams==4 Then
    $rv=Run($program,$wkdir,$show_flag)
  ElseIf @NumParams==5 Then
    $rv=Run($program,$wkdir,$show_flag,$opt_flag)
  EndIf
  ;Run ( "program" [, "workingdir" [, show_flag [, opt_flag]]] )
  ;Local $rv=Run($program,$wkdir,$show_flag,$opt_flag)
  Return $rv
EndFunc
;;;;;;;;;;;;;;;; end of tie-ins

;;;;;;;;;; setup JScript COM obj
Global $jso=NewComObj()

; import our AutoIt Proxy into the jso
$jso.set("AutoIt", $AutoItForCom)

; read our javascript file
Global $ftext=FileRead($jsfile)

; set the file text up as a Main function
$jso.set_function("Main", "", $ftext)

; need to run our message loop in autoit code, but pass it back to JS land here
$jso.set_function("MsgHandler", "m", "return eval('this.MsgHandler_(m)');")

; hold on to your britches...
; this call will run through the js file and the file must do a setup and have a callback MsgHandler_
$jso.Main()

;; Message Loop
Local $end_if_true
Local $m
  While True
    $m=GUIGetMsg(0)
    $end_if_true=$jso.MsgHandler($m)
    ;Msg($end_if_true);
    If $end_if_true Then
      ExitLoop
    EndIf
  WEnd
Exit

;; the only thing worth looking at below this point is the _ComObj_init and friends
;;;;;;;;;;;;;;;functions
Func EvtScriptExit()
  ;Msg("EvtScriptExit")
  _AutoItObject_Shutdown()
  ;_logline('EvtScriptExit')
  ;If IsObj($MidiMgr) Then
  ;  $MidiMgr.Terminate()
  ;EndIf
EndFunc

Func Msg($s)
  MsgBox(0,$thisfile,$s)
EndFunc
Func Msg2($t,$s)
  MsgBox(0,$t,$s)
EndFunc


Func logclear()
  FileDelete($logg)
EndFunc

Func _logline($line)
  logline($line)
EndFunc

Func logline($line)
  Local $fh1=FileOpen($logg,1);
  If $fh1<>-1 Then
    FileWriteLine($fh1,$line)
    FileClose($fh1)
  EndIf
EndFunc

Func logsnarl($line)
  logerr($line)
  snarl(10,'Fatal Error',$line)
EndFunc

Func snarl($i,$t,$s)
  If Not FileExists($snarl) Then
    Return
  EndIf
  $s1=StringReplace($s,'"',"'")
  $t1=StringReplace($t,'"',"'")
  $cmd=$snarl&' snShowMessage '&$i&' "'&$t1&'" "'&$s1&'"';
  Run($cmd)
EndFunc

;;;;js utils
; #FUNCTION# ==================================================================
; Name      : _ComObj_init
; Description  : Creates MS Windows Script control and deploy it as proxy for
;               AutoIt COM object binding.
; Syntax      : _ComObj_init([$VBScriptSupport = false])
; Parameter : $VBScriptSupport
;               By default JScript doesn't have alert() function, it is provided
;               by browser's window object.
;               We can emulate this using VBScript's MsgBox function, which is
;               performance hog because we need another ScriptControl instance.
;               Other advantage is to be able to execute other VBScript's methods
;               within function via vb.Eval() method.
;               This feature is disabled by default.
; =============================================================================
Func _ComObj_init ($VBScriptSupport = false)
  Local $_Script
  $_Script = ObjCreate("ScriptControl")
  $_Script.Language = "JScript"
  $_Script.Timeout = 60000
  ;$_Script.AddCode("var $=this,arrays=[],vb;function set_vbscript($) {vb=$;vb.Language='VBScript';vb.AllowUI=true;}function alert(s){if(vb)vb.Eval('MsgBox(Unescape(""'+s+'""), 0, ""Autoit"")')}function get_proxy(){return $}function new_object($){$=new Function('return{'+$+'}')();$.set=function(k, v){$[k]=v};$.unset=function(k){delete $[k]};$.set_object=function(k,$){this.set(k,new_object($))};$.set_array=function(){var v=[];for(var i=0;i<arguments.length;i++)v[i]=arguments[i];$.set(v.shift(),new_array.apply(this,v))};$.set_function=function(k,p,$){this.set(k,new_function(p,$))};return $}function new_array(){var v=[];for(var i=0;i<arguments.length;i++)v[i]=arguments[i];return v}function array_get($,k){return $[k]}function array_set($,k,v){return $[k]=v}var new_function=(function(){function F(r) {return Function.apply(this,r)}F.prototype = Function.prototype;return function(p,$){p=p.split(/\s*,\s*/);p.push($);return new F(p)}})()")
  ;a[a.length]=i;
  ;function new_array(){var v=[];for(var i=0;i<arguments.length;i++)v[i]=arguments[i];return v}
  Local $more= _
  "$.get=function(k){return $[k]};" & _
  "$.has=function(n){" & _
  "  for (var i in this){" & _
  "    if (i!=n){" & _
  "      continue;" & _
  "    }" & _
  "    if (!this.hasOwnProperty(i)){" & _
  "      continue;" & _
  "    }" & _
  "    if (typeof(this[i])=='function'){" & _
  "      continue;" & _
  "    }" & _
  "    return true;" & _
  "  };" & _
  "  return false;" & _
  "};" & _
  "$.keys=function(){" & _
  "  var a=[];" & _
  "  for (var i in this){" & _
  "    if (this.hasOwnProperty(i)){" & _
  "      if (typeof(this[i])!='function'){" & _
  "        a[a.length]=i;" & _
  "      }" & _
  "    }" & _
  "  };" & _
  "  return a;" & _
  "};" & _
  "$.set2=function(){" & _
  "  for(var x=0;x<arguments.length-1;x+=2){" & _
  "    this[arguments[x]]=arguments[x+1]" & _
  "  }" & _
  "};" & _
  "Array.prototype.item=function(n){" & _
  "  return this[n];" & _
  "};" & _
  "Array.prototype.has=function(v){" & _
  "  for(x=0;x<this.length;x++){" & _
  "    if(this[x]==v){return true;}" & _
  "  }" & _
  "  return false;" & _
  "};" & _
  "Array.prototype.asString=function(d){" & _
  "  var s='';" & _
  "  for(x=0;x<this.length;x++){" & _
  "    if(s==''){s=this[x];}else{s+=d+this[x];}" & _
  "  }" & _
  "  return s;" & _
  "};"
  $_Script.AddCode("var $=this,arrays=[],vb;function set_vbscript($) {vb=$;vb.Language='VBScript';vb.AllowUI=true;}function alert(s){if(vb)vb.Eval('MsgBox(Unescape(""'+s+'""), 0, ""Autoit"")')}function get_proxy(){return $}function new_object($){$=new Function('return{'+$+'}')();$.set=function(k, v){$[k]=v};"&$more&"$.unset=function(k){delete $[k]};$.set_object=function(k,$){this.set(k,new_object($))};$.set_array=function(){var v=[];for(var i=0;i<arguments.length;i++)v[i]=arguments[i];$.set(v.shift(),new_array.apply(this,v))};$.set_function=function(k,p,$){this.set(k,new_function(p,$))};return $}function new_array(){var v=[];for(var i=0;i<arguments.length;i++)v[i]=arguments[i];return v}function array_get($,k){return $[k]}function array_set($,k,v){return $[k]=v}var new_function=(function(){function F(r) {return Function.apply(this,r)}F.prototype = Function.prototype;return function(p,$){p=p.split(/\s*,\s*/);p.push($);return new F(p)}})()")
  If $VBScriptSupport = true Then $_Script.Run("set_vbscript", ObjCreate("ScriptControl"))
  Return $_Script
EndFunc
; =============================================================================

Func NewComObj()
  Local $com
  While True
    $com=$_com.new_object("")
    Sleep(30)
    If IsObj($com) Then
      ExitLoop
    EndIf
  WEnd
  Sleep(30)
  Return $com
EndFunc

Func JScriptInit()
  $_ComObj_proxy = _ComObj_init(true)
  $_com = $_ComObj_proxy.Run("get_proxy")
  $_Js = $_com.new_object("")
  $_Js.set_function("AIOSetProperty","o,n,v","o[n]=v;")
EndFunc

Func JS_SetProp()
  $_Js = $_com.new_object("")
  $_Js.set_function("AIOSetProperty","o,n,v","o[n]=v;")
  Return $_Js;
EndFunc

My main questions are...

  1. Why doesn't this already exist, and where is it? and...
  2. Why doesn't this already exist -- what wall am I headed for?

:bike::nuke::ermm:>_<

Edited by MarkRobbins

Share this post


Link to post
Share on other sites

What are all of the concepts that a language needs to be considered object oriented?

 

While you can 'do' OOP in any language, it can be very painful without support. When you think about it, OOP is about making miniature programs, self-contained and (as much as possible) unaware of the outside world.

Many OOP languages are strongly typed, to prevent you from sticking square pegs in round holes, and catching those mistakes at compile time.

Javascript is 'duck typed', meaning its objects are fluid and it is up to the programmer to decide if a particular object 'quacks like a duck'.

This is done by inspecting the object to see if it has a particular property or interface.

The main thing an OOP language must support is heritability, Javascript does a reasonable job of this but it does fall short in some sense, you have to boilerplate a lot of the heritability mechanism yourself.

Bright points of Javascript are:

  • Functions are objects, can be passed
  • It has a cool binding mechanism, where functions declared within functions can access variables within the enclosing scope. Its hard to explain, but once you get it, its very useful
  • Objects are dynamic, and act like hash tables
  • It has a very powerful Eval()
  • Objects can be made up on the fly, no formal declarations or 'class makers' needed
  • It has reflection, you can iterate through an object
  • Its the most popular scripting language in the world

Compared to AutoIt, Javascript will:

  • Get rid of the Globals nightmare, probably possible to write a very complex program with just a single global
  • Allow Case Sensitive identifiers (which some will hate)
  • Get rid of $ on identifiers (which I will LOVE)
  • Provide potential code libraries to be used from the web (typecastjs.org), though many of these are web based, they could be ported
  • Get rid of the parameter nightmare, just pass objects
  • Dynamically create functions, objects and 'code' with Eval()
  • Offer Easy Timers - SetInterval, SetTimeout
  • Provides an easy, well established plugin-mechanism
  • Base types (Number,String,Object,Array,Date,Bool) can be extended

 

For a great lecture on Js ...

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

"Functions are objects, can be passed"

"Get rid of $ on identifiers (which I will LOVE)" 

I'm hoping that a later version of AutoIt will provide this.

"It has a cool binding mechanism, where functions declared within functions can access variables within the enclosing scope. Its hard to explain, but once you get it, its very useful"

I think those are called closures.

OK, so basically, not real oop in autoit but rather java oop in autoit?

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites

Javascript is the most popular scripting language in the world? Most used perhaps, but only because its the only choice for client side web apps. Doesn't mean its a good language.

Share this post


Link to post
Share on other sites

OK, so basically, not real oop in autoit but rather java oop in autoit?

 

Some would claim that java is TOO oop-y. Execution in the Kingdom of Nouns

Javascript!=Java

Its a common misconception that Js is not real oop, its just not classical oop ala C++ and the like.

Share this post


Link to post
Share on other sites

Javascript is the most popular scripting language in the world? Most used perhaps, but only because its the only choice for client side web apps. Doesn't mean its a good language.

<script type="text/vbscript">

Do you know of a better language for scripting? I mean language in terms of language features, not libraries.

I think its a good language, though it does have some flaws. For a not-good language, one would have a hard time explaining the rise of Js on the server side.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Forgive me for being somewhat critical but I struggle to see how shoehorning another language into autoit is a good idea.

I would much prefer Autoit or AutoitObject to evolve to be a fully fledged OOP language rather than masquerade it to something that it is not. I love autoit for its directness and simplicity in achieving tasks that would otherwise take you a lot of time to get through in another language.

At the same time my 10-20,000 lines of structured code (not anymore) can use the oop treatment.

So I would ideally prefer for Autoit or AIO to evolve to provide better OOP plumbing (i.e. events etc.) stuff you find in C# and .NET (there you go I said it). If found myself building similar “frameworks” that look like this:

#include 'System.au3'

#include 'System.Collections.au3'

#include 'System.ComponentModel.au3'

#include 'System.Diagnostics.au3'

#include 'System.Data.au3'

#include 'System.Messaging.au3'

#include 'System.Drawing.au3'

#include 'System.IO.au3'

#include 'System.Windows.au3'

#include 'System.Windows.Automation.au3'

#include 'System.Windows.Controls.au3'

#include 'System.Windows.Forms.au3'

#include 'System.Windows.Input.au3'

You can guess what’s in there and what they are supposed to do but I say “frameworks” because in reality it’s a mickey mouse attempt to dress up win api or au3 functions so that they behave like .net. It worked for a while but before too long you run into all sort of other issues.

Having been through this loop I really think it’s a waste of time. There is language that does this already. Its called C# and it runs on a framework that dos all this already and its called .NET and you can buy some thing like DevExpress or similar to sex it up.  

Autoit is still great. Just a few days ago it helped me sort through  150,000 images and save the day for a pretty major retailer all from code found in the help files. Thank you very much. I love Autoit but I am gonna have to give up trying to make it look and work like .NET J

Edited by LateArrival

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Apparently the Node.js creator chose javascript because it had no io conventions so he could come up with his funky event based system, that made it so popular. Outside of web development, does javascript have many uses?

Python and ruby have pretty large feature sets. They are both used far more often than javascript for server side programming (and not because they've been around for longer like php). Python I know has most (if not all) the features listed above are there, and there are plenty more as well.

Personally I'd say lots of language features doesn't make a good language, and neither does being flexible. To me, a good language is something like C#, where if you gave 2 C# programmers the same task, their code would look very similar (and not because they are restricted by the language).

Edit: I hope I'm not sounding too cynical about your project. Nothing personal, I just don't like javascript. Probably because I was forced to use it in a couple of web development projects.

Edited by Mat

Share this post


Link to post
Share on other sites

Forgive me for being somewhat critical but I struggle to see how shoehorning another language into autoit is a good idea.

 

I think of it this way. On the language front, AutoIt is lacking, but on the library front it is pretty good. Somone at Netscape once remarked that Windows was just a bag of iffy drivers... which at the time, was kinda fair for an insult. So if we look at AutoIt and see it as a so-so language that has a nice bunch of calls... and those calls can be pretty easily clipped onto a COM object -- why would you stay in the language?

Your point about DotNet is well taken, but not even C# is Javascript. Its all about target size, do you want an elephant gun or a shotgun. Javascript gives informality and quick prototyping. I guess my point is that heavier armor has its cost.

To be fair, the objections that come to my mind would be the continuity and coding split, and the question of debugging. I guess my question for you is, why do you do AutoIt and not DotNet? Whats wrong with the best of both worlds?

That is, if it can be done. This is just a probe, I really didn't expect so much poo-pooing. Did AutoItObject receive that reception?

Share this post


Link to post
Share on other sites
 

 

 

Outside of web development, does javascript have many uses?

ECMAScript is basis for ActionScript, which is Flex and Flash, both are not confined to the web and are used to create rich GUI desktop apps.

 

I'd say lots of language features doesn't make a good language, and neither does being flexible

Javascript has many, many flaws. But something has to be said about a language that is so flexible that its mistakes can be rectified ad-hoc.

 

if you gave 2 C# programmers the same task, their code would look very similar

 

Good thing for a production environment for sure.

I think your comments were pretty restrained for someone who dislikes javascript. I will ask the same question to you -- why not just develop in C# instead of AutoIt? I don't want to sound snarky, but shouldn't we all have a good answer to that? There must be a reason, and wouldn't that reason be better off in a language that supports OO?

 

Share this post


Link to post
Share on other sites

 Its all about target size, do you want an elephant gun or a shotgun. I guess my point is that heavier armor has its cost.

 

I guess in my case I need an elephant with a machine gun!

A lot of the low level stuff like handling windows, controls, trays, ini files - if you care for that - or hotkeys are not very accessible in WPF or are very counter-intuitive to work with.Do-able but a royal pain. On the other hand, wiring sophisticated GUIs together in AI is also doable but also a royal pain. I mean who wants to register WM_something to handle control events in 2013.

So there is no happy medium as I see it. Enough people have build some of the 'missing' features in WPF over the years so rather than trying to turn AI into something it is not perhaps the best course of action is to invest time in building up the features one needs in C#/WPF (or similar). I could be wrong but attempting to do the opposite  may be quite a huge task and there are always lots of people with varying needs and you can never keep everybody happy.

To be honest it would be too much for me to presume what is right or not for AI since I am new here and I have very healthy respect for anybody who can produce a language and run it successfully over many years. Anyway wasn't poo poing your idea but I just come to think that AI is a pretty good script language to automate windows applications. That is it I think...The rest is just mismanaged or unrealistic expectations (on my part at least).

Share this post


Link to post
Share on other sites

why not just develop in C# instead of AutoIt? I don't want to sound snarky, but shouldn't we all have a good answer to that? There must be a reason, and wouldn't that reason be better off in a language that supports OO?

I do. I do hardly any AutoIt scripting any more, apart from for very small desktop apps and utilities. For GUI programming, I could still write a GUI in AutoIt from scratch faster than I can do it in visual studio with the designer (and certainly a lot faster than I could do it in C# source code). AutoIt I could write a few hundred lines of script in notepad on someone elses pc, run it with a single standalone executable, and it will work first time (well... most of the time anyway). 

For me, C#, C++, AutoIt and python cover all my needs. None of them are perfect, I don't think a one-language-fits-all solution is possible.

But anyway. Don't let my grumbling stand in your way. Language development is great fun, its something I've had an interest in for years.

Share this post


Link to post
Share on other sites

To Mat 

Btw if I got this right do you take:

 

43 38 48 31 30 4e 34 4f 32 with 43 31 32 48 32 32 4F 31 31 or without?

Share this post


Link to post
Share on other sites

I've done some timing tests.

The message loop has to reside in AI and call into JSCOM using an eval.

1000 such calls take 626ms

Direct calls, without eval, into JSCOM

1000 such calls take 728ms (it is weird that eval is faster)

Calling an empty function on the AutoIt AutoItObject (calling out to autoit)

1000 such calls take 69ms

For direct speed comparisons of the languages...

100k loops of addition x=x+1 in AI take 174ms, in JSCOM take 12ms - 1450% faster

10k loops of string concatenation s=s&' '  in AI take 97ms, in JSCOM take 7ms - 1385% faster

100k loops of calling an empty function in AI take 559ms, in JSCOM take 64ms - 873% faster

 

Share this post


Link to post
Share on other sites

 

I've done some timing tests.

 

 

For direct speed comparisons of the languages...

100k loops of addition x=x+1 in AI take 174ms, in JSCOM take 12ms - 1450% faster

10k loops of string concatenation s=s&' '  in AI take 97ms, in JSCOM take 7ms - 1385% faster

100k loops of calling an empty function in AI take 559ms, in JSCOM take 64ms - 873% faster

 

Not sure how you did the timing tests, but for me 100K "x += 1" gives me 44ms, string concatenation $s &= " " gives me 60ms, and calling an empty function 100K times gives me 104ms, using beta 3.3.9.12. In 3.3.8.1 I get 27ms, 64ms, and 68ms respectively. All things considered, the speed difference isn't all that bad, considering interpreted languages and all.

 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

 

Not sure how you did the timing tests, but for me 100K "x += 1" gives me 44ms, string concatenation $s &= " " gives me 60ms, and calling an empty function 100K times gives me 104ms, using beta 3.3.9.12. In 3.3.8.1 I get 27ms, 64ms, and 68ms respectively. All things considered, the speed difference isn't all that bad, considering interpreted languages and all.

 

 

 

I don't know how you can say that about the speed diff, they are both interpreted. On my planet any difference over 2x is quite considerable. The addition loop executes in 0.06 the time, Concat 0.07, and empty fn in 0.1  -- those are huge.

 

Here are the AI Tests

;loop additions
#cs
$time=TimerInit()
Global $end=100*1000
Global $x,$y=1
For $x=1 To $end
  $y=$y+1
Next
Global $t1
$t1=TimerDiff($time);174
Msg($t1)
Exit
#ce

;loop concat
#cs
$time=TimerInit()
Global $end=10*1000
Global $x,$y=''
For $x=1 To $end
  $y=$y&'x'
Next
Global $t1
$t1=TimerDiff($time);97
Msg($t1)
Exit
#ce

;loop empty fn
#cs
Func EmptyFn($x)
EndFunc
$time=TimerInit()
Global $end=100*1000
Global $x,$y=''
For $x=1 To $end
  EmptyFn(0)
Next
Global $t1
$t1=TimerDiff($time);559
Msg($t1)
Exit
#ce

Intel Xeon E5 2620

Share this post


Link to post
Share on other sites

To Mat 

Btw if I got this right do you take:

 

43 38 48 31 30 4e 34 4f 32 with 43 31 32 48 32 32 4F 31 31 or without?

Nope. I don't like them sweet. I like them hot and black :)

Share this post


Link to post
Share on other sites

Eval is not good.

 

It is the js eval I have to use if I calling into JSCOM with the msg loop, otherwise it hangs...

$jso.set_function("MsgHandler", "m", "return eval('this.MsgHandler_(m)');")

So the call looks like

Local $end_if_true
Local $m
  While True
    $m=GUIGetMsg(0)
    $end_if_true=$jso.MsgHandler($m)
    ;Msg($end_if_true);
    If $end_if_true Then
      ExitLoop
    EndIf
  WEnd
Exit

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • Chimp
      By Chimp
      An example on how to inject jQuery into a web page
      It can be useful to manage the page from AutoIt using jQuery.
      Idea from here: http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet
      Suggestions and improvements are welcome
      #include <ie.au3> Example() Func Example() Local $oIE = _IECreate("www.google.com") Local $jQuery = _jQuerify($oIE) MsgBox(0, "Version", "jQuery version: " & $jQuery.fn.jquery) MsgBox(0, "Example", "click ok to exit." & @CRLF & "Google logo will fade out by jQuery...") $jQuery('#hplogo').fadeOut(3000) ; jQuery will fade out the google logo EndFunc ;==>Example ; #FUNCTION# ==================================================================================================================== ; Name ..........: _jQuerify ; Description ...: ; Syntax ........: _jQuerify(Byref $oIE) ; Parameters ....: $oIE - Object variable of an InternetExplorer.Application. ; Return values .: an object variable pointing to the jQuery library ; Author ........: Chimp ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _jQuerify(ByRef $oIE) Local $jsEval, $jQuery, $otherlib = False ; create a reference to the javascript eval() function $oIE.document.parentWindow.setTimeout('document.head.eval = eval', 0) Do Sleep(250) $jsEval = Execute('$oIE.Document.head.eval') Until IsObj($jsEval) ; if jQuery is not already loaded then load it If $jsEval("typeof jQuery=='undefined'") Then ; check if the '$' (dollar) name is already in use by other library If $jsEval("typeof $=='function'") Then $otherlib = True Local $oScript = $oIE.document.createElement('script'); $oScript.type = 'text/javascript' ; If you want to load jQuery from a disk file use the following statement ; where i.e. jquery-1.9.1.js is the file containing the jQuery source ; (or also use a string variable containing the whole jQuery listing) ;~ $oScript.TextContent = FileRead(@ScriptDir & "\jquery-1.9.1.js") ; <--- from a file ; If you want to download jQuery from the web use this statement $oScript.src = 'https://code.jquery.com/jquery-latest.min.js' ; <--- from an url $oIE.document.getElementsByTagName('head').item(0).appendChild($oScript) Do Sleep(250) Until $jsEval("typeof jQuery == 'function'") EndIf Do Sleep(250) $jQuery = $jsEval("jQuery") Until IsObj($jQuery) If $otherlib Then $jsEval('jQuery.noConflict();') Return $jQuery EndFunc ;==>_jQuerify  
    • XaelloNegative
      By XaelloNegative
      Hi there.
      Im having some kind of a coder block here, 
      <td class="treeview ctl00_CenterContent_objTreeView_2" style="white-space:nowrap;"> <input type="checkbox" name="ctl00_CenterContent_objTreeViewn1CheckBox" id="ctl00_CenterContent_objTreeViewn1CheckBox"> <span class="ctl00_CenterContent_objTreeView_0 treeview ctl00_CenterContent_objTreeView_1" id="ctl00_CenterContent_objTreeViewt1" style="border-style:none;font-size:1em;"> <i class="fa fa-file-code-o fa-fw"> </i> <span data-placement="bottom" data-toggle="tooltip" title="" data-original-title="Tool tip for said part">REFUNDS</span></span></td> this is a code directly from the website im working with. I was thinking of inserting a javascript that would get the "REFUNDS" part. Any ideas on how to do so?
      Any thoughts will be highly appreciated.
    • gillesg
      By gillesg
      Hello,
       
      Is there a way to get all the properties and method of a COM object thru Autoit.
      I am looking in a way of display the imbricated structure of object and method.
       
      Example of COm objects are "itunes.application", "Shell.application" and so on.
      The idea is to have a code looking like
      $objtobrowse = objcreate("itunes.application") if isobj($objtobrowse) then $colItems = $objtobrowse.buildinproperty For $objItem In $colItems ConsoleWrite($objItem.<Name> & " - " & $objItem.<Value> & @CRLF) Next EndIf  
    • timmalos
      By timmalos
      Hey all.
      I'm a little stuck starting with COM interfacing with Microsoft OneNote.
      The msdn doc is there : https://msdn.microsoft.com/en-us/library/office/jj680118.aspx?f=255&MSPPError=-2147217396
      I found, with the OleViewer what I need to access :
      // Generated .IDL file (by the OLE/COM Object Viewer) // // typelib filename: 3 [ uuid(0EA692EE-BB50-4E3C-AEF0-356D91732725), version(1.1), helpstring("Microsoft OneNote 15.0 Object Library"), custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 134218339), custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 2147483647), custom(DE77BA65-517C-11D1-A2DA-0000F8773CE9, Created by MIDL version 8.00.0611 at Mon Jan 18 19:14:07 2038 ), custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, Microsoft.Office.Interop.OneNote.dll) ] library OneNote { // TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046} importlib("stdole2.tlb"); // Forward declare all types defined in this typelib interface IQuickFilingDialog; interface IQuickFilingDialogCallback; interface IApplication; interface Windows; interface Window; dispinterface IOneNoteEvents; typedef [uuid(552E0E02-B287-4EC6-9CC0-4BA019EE5EA1)] enum { hsSelf = 0, hsChildren = 1, hsNotebooks = 2, hsSections = 3, hsPages = 4 } HierarchyScope; typedef [uuid(41C8F6EA-0AF0-4A4F-99E9-5EB01EBFC9A3)] enum { heNone = 0, heNotebooks = 1, heSectionGroups = 2, heSections = 4, hePages = 8 } HierarchyElement; typedef [uuid(4DB67B4F-CC7D-45B5-88FE-569AE5798FF2)] enum { rrtNone = 0, rrtFiling = 1, rrtSearch = 2, rrtLinks = 3 } RecentResultType; typedef [uuid(B5EB9D34-5278-4D8A-AE1F-2F88EA56BBCE)] enum { cftNone = 0, cftNotebook = 1, cftFolder = 2, cftSection = 3 } CreateFileType; typedef [uuid(D6E78E55-7EE7-4A31-BF3E-B01E819599BA)] enum { piBasic = 0, piBinaryData = 1, piSelection = 2, piFileType = 4, piBinaryDataSelection = 3, piBinaryDataFileType = 5, piSelectionFileType = 6, piAll = 7 } PageInfo; typedef [uuid(D6166973-3665-4EDB-94B0-77C65C34B51C)] enum { pfOneNote = 0, pfOneNotePackage = 1, pfMHTML = 2, pfPDF = 3, pfXPS = 4, pfWord = 5, pfEMF = 6, pfHTML = 7, pfOneNote2007 = 8 } PublishFormat; typedef [uuid(E195F3E3-8EC3-4A67-81FE-DDBEC2B42D3F)] enum { slBackUpFolder = 0, slUnfiledNotesSection = 1, slDefaultNotebookFolder = 2 } SpecialLocation; typedef [uuid(452D048E-7F61-4258-94B9-A39E19C290DA)] enum { flEMail = 0, flContacts = 1, flTasks = 2, flMeetings = 3, flWebContent = 4, flPrintOuts = 5 } FilingLocation; typedef [uuid(82FC5A95-FEB7-4242-95E1-369C5DFE3F49)] enum { fltNamedSectionNewPage = 0, fltCurrentSectionNewPage = 1, fltCurrentPage = 2, fltNamedPage = 4 } FilingLocationType; typedef [uuid(226CC8E6-1ED0-4770-A7F1-A80BB4DDF07B)] enum { npsDefault = 0, npsBlankPageWithTitle = 1, npsBlankPageNoTitle = 2 } NewPageStyle; typedef [uuid(B67BC7E1-91B9-4F50-8471-77C76F8D63D6)] enum { dlDefault = 0xffffffff, dlNone = 0, dlLeft = 1, dlRight = 2, dlTop = 3, dlBottom = 4 } DockLocation; typedef [uuid(68555133-B62F-4490-9D66-9E9BFC68F6C6)] enum { xs2007 = 0, xs2010 = 1, xs2013 = 2, xsCurrent = 2 } XMLSchema; typedef [uuid(1ECC88B3-6D2B-4EDD-8DD5-BB11E5D34C09)] enum { tcsExpanded = 0, tcsCollapsed = 1 } TreeCollapsedStateType; typedef [uuid(13F18B04-E76F-42E0-97E6-8B6ABF38B484)] enum { nfoLocal = 1, nfoNetwork = 2, nfoWeb = 4, nfoNoWacUrl = 8 } NotebookFilterOutType; [ odl, uuid(1D12BD3F-89B6-4077-AA2C-C9DC2BCA42F9), helpstring("IQuickFilingUI Interface"), dual, oleautomation ] interface IQuickFilingDialog : IDispatch { [id(00000000), propget] HRESULT Title([out, retval] BSTR* bstrTitle); [id(00000000), propput] HRESULT Title([in] BSTR bstrTitle); [id(0x00000001), propget] HRESULT Description([out, retval] BSTR* bstrDescription); [id(0x00000001), propput] HRESULT Description([in] BSTR bstrDescription); [id(0x00000002), propget] HRESULT CheckboxText([out, retval] BSTR* bstrText); [id(0x00000002), propput] HRESULT CheckboxText([in] BSTR bstrText); [id(0x00000003), propget] HRESULT CheckboxState([out, retval] VARIANT_BOOL* pfChecked); [id(0x00000003), propput] HRESULT CheckboxState([in] VARIANT_BOOL pfChecked); [id(0x00000004), propget] HRESULT WindowHandle([out, retval] uint64* pHWNDWindow); [id(0x00000005), propget] HRESULT TreeDepth([out, retval] HierarchyElement* pTreeDepth); [id(0x00000005), propput] HRESULT TreeDepth([in] HierarchyElement pTreeDepth); [id(0x00000006), propget] HRESULT ParentWindowHandle([out, retval] uint64* pHWNDParentWindow); [id(0x00000006), propput] HRESULT ParentWindowHandle([in] uint64 pHWNDParentWindow); [id(0x00000007), propget] HRESULT Position([out, retval] tagPOINT* pPoint); [id(0x00000007), propput] HRESULT Position([in] tagPOINT pPoint); [id(0x00000008)] HRESULT SetRecentResults( [in] RecentResultType recentResults, [in] VARIANT_BOOL fShowCurrentSection, [in] VARIANT_BOOL fShowCurrentPage, [in] VARIANT_BOOL fShowUnfiledNotes); [id(0x0000000a)] HRESULT AddButton( [in] BSTR bstrText, [in] HierarchyElement allowedElements, [in] HierarchyElement allowedReadOnlyElements, [in] VARIANT_BOOL fDefault); [id(0x0000000b)] HRESULT Run([in] IQuickFilingDialogCallback* piCallback); [id(0x0000000c), propget] HRESULT SelectedItem([out, retval] BSTR* pbstrSelectedNodeID); [id(0x0000000d), propget] HRESULT PressedButton([out, retval] unsigned long* pButtonIndex); [id(0x0000000e), propput] HRESULT TreeCollapsedState([in] TreeCollapsedStateType rhs); [id(0x0000000f), propput] HRESULT NotebookFilterOut([in] NotebookFilterOutType rhs); [id(0x00000010)] HRESULT ShowCreateNewNotebook(); [id(0x00000011)] HRESULT AddInitialEditor(BSTR initialEditor); [id(0x00000012)] HRESULT ClearInitialEditors(); [id(0x00000013)] HRESULT ShowSharingHyperlink(); }; typedef struct tagtagPOINT { long x; long y; } tagPOINT; [ odl, uuid(627EA7B4-95B5-4980-84C1-9D20DA4460B1), helpstring("IQuickFilingDialogCallback Interface"), dual, oleautomation ] interface IQuickFilingDialogCallback : IDispatch { [id(0x60020000)] HRESULT OnDialogClosed([in] IQuickFilingDialog* dialog); }; [ odl, uuid(452AC71A-B655-4967-A208-A4CC39DD7949), helpstring("IApplication Interface"), dual, oleautomation ] interface IApplication : IDispatch { [id(0x60020000)] HRESULT GetHierarchy( [in] BSTR bstrStartNodeID, [in] HierarchyScope hsScope, [out] BSTR* pbstrHierarchyXmlOut, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020001)] HRESULT UpdateHierarchy( [in] BSTR bstrChangesXmlIn, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020002)] HRESULT OpenHierarchy( [in] BSTR bstrPath, [in] BSTR bstrRelativeToObjectID, [out] BSTR* pbstrObjectID, [in, optional, defaultvalue(0)] CreateFileType cftIfNotExist); [id(0x60020003)] HRESULT DeleteHierarchy( [in] BSTR bstrObjectID, [in, optional, defaultvalue(00:00:00)] DATE dateExpectedLastModified, [in, optional, defaultvalue(0)] VARIANT_BOOL deletePermanently); [id(0x60020004)] HRESULT CreateNewPage( [in] BSTR bstrSectionID, [out] BSTR* pbstrPageID, [in, optional, defaultvalue(0)] NewPageStyle npsNewPageStyle); [id(0x60020005)] HRESULT CloseNotebook( [in] BSTR bstrNotebookID, [in, optional, defaultvalue(0)] VARIANT_BOOL force); [id(0x60020006)] HRESULT GetHierarchyParent( [in] BSTR bstrObjectID, [out] BSTR* pbstrParentID); [id(0x60020007)] HRESULT GetPageContent( [in] BSTR bstrPageID, [out] BSTR* pbstrPageXmlOut, [in, optional, defaultvalue(0)] PageInfo pageInfoToExport, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020008)] HRESULT UpdatePageContent( [in] BSTR bstrPageChangesXmlIn, [in, optional, defaultvalue(00:00:00)] DATE dateExpectedLastModified, [in, optional, defaultvalue(2)] XMLSchema xsSchema, [in, optional, defaultvalue(0)] VARIANT_BOOL force); [id(0x60020009)] HRESULT GetBinaryPageContent( [in] BSTR bstrPageID, [in] BSTR bstrCallbackID, [out] BSTR* pbstrBinaryObjectB64Out); [id(0x6002000a)] HRESULT DeletePageContent( [in] BSTR bstrPageID, [in] BSTR bstrObjectID, [in, optional, defaultvalue(00:00:00)] DATE dateExpectedLastModified, [in, optional, defaultvalue(0)] VARIANT_BOOL force); [id(0x6002000b)] HRESULT NavigateTo( [in] BSTR bstrHierarchyObjectID, [in, optional, defaultvalue("")] BSTR bstrObjectID, [in, optional, defaultvalue(0)] VARIANT_BOOL fNewWindow); [id(0x6002000c)] HRESULT NavigateToUrl( [in] BSTR bstrUrl, [in, optional, defaultvalue(0)] VARIANT_BOOL fNewWindow); [id(0x6002000d)] HRESULT Publish( [in] BSTR bstrHierarchyID, [in] BSTR bstrTargetFilePath, [in, optional, defaultvalue(0)] PublishFormat pfPublishFormat, [in, optional, defaultvalue("")] BSTR bstrCLSIDofExporter); [id(0x6002000e)] HRESULT OpenPackage( [in] BSTR bstrPathPackage, [in] BSTR bstrPathDest, [out] BSTR* pbstrPathOut); [id(0x6002000f)] HRESULT GetHyperlinkToObject( [in] BSTR bstrHierarchyID, [in] BSTR bstrPageContentObjectID, [out] BSTR* pbstrHyperlinkOut); [id(0x60020010)] HRESULT FindPages( [in] BSTR bstrStartNodeID, [in] BSTR bstrSearchString, [out] BSTR* pbstrHierarchyXmlOut, [in, optional, defaultvalue(0)] VARIANT_BOOL fIncludeUnindexedPages, [in, optional, defaultvalue(0)] VARIANT_BOOL fDisplay, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020011)] HRESULT FindMeta( [in] BSTR bstrStartNodeID, [in] BSTR bstrSearchStringName, [out] BSTR* pbstrHierarchyXmlOut, [in, optional, defaultvalue(0)] VARIANT_BOOL fIncludeUnindexedPages, [in, optional, defaultvalue(2)] XMLSchema xsSchema); [id(0x60020012)] HRESULT GetSpecialLocation( [in] SpecialLocation slToGet, [out] BSTR* pbstrSpecialLocationPath); [id(0x60020013)] HRESULT MergeFiles( [in] BSTR bstrBaseFile, [in] BSTR bstrClientFile, [in] BSTR bstrServerFile, [in] BSTR bstrTargetFile); [id(0x60020014)] HRESULT QuickFiling([out, retval] IQuickFilingDialog** ppiDialog); [id(0x60020015)] HRESULT SyncHierarchy([in] BSTR bstrHierarchyID); [id(0x60020016)] HRESULT SetFilingLocation( [in] FilingLocation flToSet, [in] FilingLocationType fltToSet, [in] BSTR bstrFilingSectionID); [id(0x00000064), propget] HRESULT Windows([out, retval] Windows** ppONWindows); [id(0x00000066), propget, hidden] HRESULT Dummy1([out, retval] VARIANT_BOOL* pBool); [id(0x60020019)] HRESULT MergeSections( [in] BSTR bstrSectionSourceId, [in] BSTR bstrSectionDestinationId); [id(0x00000068), propget] HRESULT COMAddIns([out, retval] IDispatch** ppiComAddins); [id(0x00000069), propget] HRESULT LanguageSettings([out, retval] IDispatch** ppiLanguageSettings); [id(0x6002001c)] HRESULT GetWebHyperlinkToObject( [in] BSTR bstrHierarchyID, [in] BSTR bstrPageContentObjectID, [out] BSTR* pbstrHyperlinkOut); }; [ odl, uuid(6D4B9C3E-CC05-493F-85E2-43D1006DF96A), helpstring("List of our Windows Interface"), dual, oleautomation ] interface Windows : IDispatch { [id(00000000), propget] HRESULT Item( [in] unsigned long Index, [out, retval] Window** Item); [id(0x00000001), propget] HRESULT Count([out, retval] unsigned long* Count); [id(0xfffffffc), propget] HRESULT _NewEnum([out, retval] IUnknown** _NewEnum); [id(0x00000003), propget] HRESULT CurrentWindow([out, retval] Window** ppCurrentWindow); }; [ odl, uuid(8E8304B8-CBD1-44F8-B0E8-89C625B2002E), helpstring("Window Interface"), dual, oleautomation ] interface Window : IDispatch { [id(00000000), propget] HRESULT WindowHandle([out, retval] uint64* pHWNDWindow); [id(0x00000001), propget] HRESULT CurrentPageId([out, retval] BSTR* pbstrPageObjectId); [id(0x00000002), propget] HRESULT CurrentSectionId([out, retval] BSTR* pbstrSectionObjectId); [id(0x00000003), propget] HRESULT CurrentSectionGroupId([out, retval] BSTR* pbstrSectionObjectId); [id(0x00000004), propget] HRESULT CurrentNotebookId([out, retval] BSTR* pbstrNotebookObjectId); [id(0x00000009)] HRESULT NavigateTo( [in] BSTR bstrHierarchyObjectID, [in, optional, defaultvalue("0")] BSTR bstrObjectID); [id(0x0000000a), propget] HRESULT FullPageView([out, retval] VARIANT_BOOL* pIsFullPageView); [id(0x0000000a), propput] HRESULT FullPageView(VARIANT_BOOL pIsFullPageView); [id(0x0000000b), propget] HRESULT Active([out, retval] VARIANT_BOOL* pIsActive); [id(0x0000000b), propput] HRESULT Active(VARIANT_BOOL pIsActive); [id(0x0000000d), propget] HRESULT DockedLocation([out, retval] DockLocation* pDockLocation); [id(0x0000000d), propput] HRESULT DockedLocation(DockLocation pDockLocation); [id(0x0000000e), propget] HRESULT Application([out, retval] IApplication** ppiApp); [id(0x0000000f), propget] HRESULT SideNote([out, retval] VARIANT_BOOL* pIsSideNote); [id(0x00000010)] HRESULT NavigateToUrl([in] BSTR bstrUrl); [id(0x00000011)] HRESULT SetDockedLocation( [in] DockLocation DockLocation, [in] tagPOINT ptMonitor); }; [ uuid(E2E1511D-502D-4BD0-8B3A-8A89A05CDCAE), helpstring("IOneNoteEvents Interface"), nonextensible ] dispinterface IOneNoteEvents { properties: methods: [id(0x00000001)] void OnNavigate(); [id(0x00000002)] void OnHierarchyChange([in] BSTR bstrActivePageID); }; [ uuid(D7FAC39E-7FF1-49AA-98CF-A1DDD316337E), version(1.0), helpstring("Application Class") ] coclass Application { [default] interface IApplication; [default, source] dispinterface IOneNoteEvents; }; typedef [uuid(D3F5A756-4BAC-4D3D-9BAF-90935121AAA6)] enum { hrMalformedXML = 0x80042000, hrInvalidXML = 0x80042001, hrCreatingSection = 0x80042002, hrOpeningSection = 0x80042003, hrSectionDoesNotExist = 0x80042004, hrPageDoesNotExist = 0x80042005, hrFileDoesNotExist = 0x80042006, hrInsertingImage = 0x80042007, hrInsertingInk = 0x80042008, hrInsertingHtml = 0x80042009, hrNavigatingToPage = 0x8004200a, hrSectionReadOnly = 0x8004200b, hrPageReadOnly = 0x8004200c, hrInsertingOutlineText = 0x8004200d, hrPageObjectDoesNotExist = 0x8004200e, hrBinaryObjectDoesNotExist = 0x8004200f, hrLastModifiedDateDidNotMatch = 0x80042010, hrGroupDoesNotExist = 0x80042011, hrPageDoesNotExistInGroup = 0x80042012, hrNoActiveSelection = 0x80042013, hrObjectDoesNotExist = 0x80042014, hrNotebookDoesNotExist = 0x80042015, hrInsertingFile = 0x80042016, hrInvalidName = 0x80042017, hrFolderDoesNotExist = 0x80042018, hrInvalidQuery = 0x80042019, hrFileAlreadyExists = 0x8004201a, hrSectionEncryptedAndLocked = 0x8004201b, hrDisabledByPolicy = 0x8004201c, hrNotYetSynchronized = 0x8004201d, hrLegacySection = 0x8004201e, hrMergeFailed = 0x8004201f, hrInvalidXMLSchema = 0x80042020, hrFutureContentLoss = 0x80042022, hrTimeOut = 0x80042023, hrRecordingInProgress = 0x80042024, hrUnknownLinkedNoteState = 0x80042025, hrNoShortNameForLinkedNote = 0x80042026, hrNoFriendlyNameForLinkedNote = 0x80042027, hrInvalidLinkedNoteUri = 0x80042028, hrInvalidLinkedNoteThumbnail = 0x80042029, hrImportLNTThumbnailFailed = 0x8004202a, hrUnreadDisabledForNotebook = 0x8004202b, hrInvalidSelection = 0x8004202c, hrConvertFailed = 0x8004202d, hrRecycleBinEditFailed = 0x8004202e, hrAppInModalUI = 0x80042030 } Error; [ uuid(DC67E480-C3CB-49F8-8232-60B0C2056C8E), version(1.0), helpstring("Application2 Class") ] coclass Application2 { [default] interface IApplication; [default, source] dispinterface IOneNoteEvents; }; }; So far, I didn't manage to be able to interact with it : There is my code (based on same issue someone had in 2011
      #AutoIt3Wrapper_UseX64=n #include <Array.au3> #include "AutoItObject\AutoItObject.au3" ;=============================================================================== ;interface "OneNoteIApplication" Global Const $sCLSID_OneNoteApplication = "{0039FFEC-A022-4232-8274-6B34787BFC27}" Global Const $sIID_IOneNoteApplication = "{2DA16203-3F58-404F-839D-E4CDE7DD0DED}" ; Definition Global $dtagIOneNoteWindows = $dtagIDispatch Global $dtagIOneNoteApplication = $dtagIDispatch & _ "GetHierarchy hresult(bstr;dword;bstr*);" & _ "UpdateHierarchy hresult(bstr);" & _ "OpenHierarchy hresult(bstr;bstr;bstr*;dword);" & _ "DeleteHierarchy hresult(bstr;double);" & _ "CreateNewPage hresult(bstr;bstr*;dword);" & _ "CloseNotebook hresult(bstr);" & _ "GetHierarchyParent hresult(bstr;bstr*);" & _ "GetPageContent hresult(bstr;bstr*;dword);" & _ "UpdatePageContent hresult(bstr;double);" & _ "GetBinaryPageContent hresult(bstr;bstr;bstr*);" & _ "DeletePageContent hresult(bstr;bstr;dword);" & _ "NavigateTo hresult(bstr;bstr;bool);" & _ "Publish hresult(bstr;bstr;dword;bstr);" & _ "OpenPackage hresult(bstr;bstr;bstr*);" & _ "GetHyperlinkToObject hresult(bstr;bstr;bstr*);" & _ "FindPages hresult(bstr;bstr;bstr*;bool;bool);" & _ "FindMeta hresult(bstr;bstr;bstr*;bool);" & _ "GetSpecialLocation hresult(dword;bstr*);" ; List Global $ltagIOneNoteApplication = $ltagIDispatch & _ "GetHierarchy;" & _ "UpdateHierarchy;" & _ "OpenHierarchy;" & _ "DeleteHierarchy;" & _ "CreateNewPage;" & _ "CloseNotebook;" & _ "GetHierarchyParent;" & _ "GetPageContent;" & _ "UpdatePageContent;" & _ "GetBinaryPageContent;" & _ "DeletePageContent;" & _ "NavigateTo;" & _ "Publish;" & _ "OpenPackage;" & _ "GetHyperlinkToObject;" & _ "FindPages;" & _ "FindMeta;" & _ "GetSpecialLocation;" ;=============================================================================== _AutoItObject_StartUp() Global $objOneNote = ObjCreate("OneNote.Application") Global $pOneNote = _AutoItObject_IDispatchToPtr($objOneNote) _AutoItObject_IUnknownAddRef($objOneNote) Global $oOneNote = _AutoItObject_WrapperCreate($pOneNote, $dtagIOneNoteWindows) ;~ Global $oOnenote = ObjCreateInterface($sCLSID_OneNoteApplication,$sIID_IOneNoteApplication,$dtagIOneNoteApplication,True) ;~ ; Check if object is created: If Not IsObj($oOneNote) Then MsgBox(48, "Error", "Object not created. Something is wrong.") Exit EndIf $aCall = $oOneNote.GetTypeInfoCount(0) $iTypeInfoCount = $aCall[1] ConsoleWrite("$iTypeInfoCount = " & $iTypeInfoCount & @CRLF) $Window = $oOneNote.Windows ;~ ConsoleWrite("Test = " & $Window.CurrentPageId & @CRLF) $str = "onenote:///R:\Software\OneNote%20EOD\EOD%20Scrum\Sprint%20136.one#section-id={D2EB7AEB-362B-490A-9CE0-0B9316DF0DAD}&end" $hBSTR = DllCall("oleaut32.dll", "ptr", "SysAllocString", "wstr", $str) $aCall = $oOnenote.NavigateToUrl($hBSTR[0])  
      Can someone help me to go in the good direction? I'm a little lost with what's needed, (CLSID and IID whereas I have only a UUID and can't find a good starting doc online)
      Thanks a lot,
       
    • Patryk
      By Patryk
      Dear Colleagues,
      I have no idea how to refer to style.display in my loop. There is a button like: 
      <input name="ctl00$bodyPlaceholder$btnFecharProcessamento" class="button" id="bodyPlaceholder_btnFecharProcessamento" style="display: none;" onclick="FecharJanelaProcessamento();return false;" type="submit" value="Fechar"> I want it to be clicked as soon as button's style change from style="display: none;" to  style= ="display: inline-block;" 
      This is what I got, but it's not working...
      Func GetButtons() $oButtons = _IEGetObjByName($oForm,"ctl00$bodyPlaceholder$btnFecharProcessamento",-1) $i = 0 While $i <> 1 For $oBtn In $oButtons If _IEFormElementGetValue($oBtn) = "Fechar" And $oBtn.document.style.display = "display: inline-block;" Then $i = 1 _IEAction($oBtn, "focus") _IEAction($oBtn, "click") ExitLoop EndIf Next WEnd EndFunc  
      I will really appreciate if you could help me with these loop!