Jump to content
Sign in to follow this  
Kilmatead

DLLOpen and Best Practise Below The Salt...

Recommended Posts

Kilmatead

Noting the help file's suggestion that if calling _IsPressed() in a loop, it's the better part of valour to DLLOpen the common library user32 first, I'm also noting there is no explanation proffered as to why. I understand that single-calls presumably open/call/close the DLL, so it may be an abstract matter of "overhead" in an endless loop - but does this apply to a mere "few thousand" calls as well?

For example, perusing the GuiTreeView.au3 UDF file, pretty much all of the "interesting" functions are ultimately using _SendMessage(), which is a user32 DLL call - however these functions (unlike _IsPressed) aren't built to easily pass an open library handle through.

So if I have a routine that iteratively calls _GUITreeView_Expand() 8,000 times, and then stops (thus not an endless loop), is it worth my while to rewrite the necessary UDF's to allow open-handle passing? A few simple tests show that the world doesn't come to an end, and the devil doesn't seem to be bartering for my first-born or anything like that if I just submit the 8,000 calls one way or the other (no dramatic speed increases, etc).

So, when not being contained in an endless loop, but merely a semantically long one, do I gain anything other than a Best Practise star on my forehead for rewriting the UDF's? Given the example, it's quite easy to just breakdown _GUITreeView_Expand() into its base _SendMessage() component, but - say - taking the time to rewrite _GUICtrlTreeView_SetStateImageIndex() for no discernible benefit could be depressing, when you look at how it's written. :rolleyes:

Share this post


Link to post
Share on other sites
FireFox

It's faster to open the dll, make as many calls as you want, then closing the dll instead of opening and closing it everytime.

Proof :

#include <Misc.au3>

Global $iTimer, $hDLL

$iTimer = TimerInit()

$hDLL = DllOpen("user32.dll")

For $i = 0 To 100000
_IsPressed("01", $hDLL)
Next

DllClose($hDLL)

ConsoleWrite(TimerDiff($iTimer) / 1000 & " secs" & @CRLF)

$iTimer = TimerInit()

For $i = 0 To 100000
_IsPressed("01")
Next

ConsoleWrite(TimerDiff($iTimer) / 1000 & " secs" & @CRLF)

1.49700709421916 secs
1.75105206354706 secs

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
trancexx

^^ this is not entirely true. Things are not black and white like that.

When you DllOpen some module then AuoIt keeps track of all opened modules and iterates through a set of handles every time you pass dll handle. Same thing is done on lower level by the system with included reference count when you pass the string. Obviously AutoIt can do it slower than system does it depending on, for example the number of opened handles. It can also do it faster if ref count for the module drops to 0. So no, it's not black and white.

  • Like 1

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
FireFox

@trancexx

I was almost sure that I was not entirely right. But I could not know what you said, too advanced for me. (at least for a short time I hope)


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
JohnOne

Natural progression might raise the question then, how can one enumerate

open handles of a particular module?

If OpenHandles("User32.dll") < 100 Then

$Handle = DllOpen("the.dll")

_Func($Handle)

Else

_Func("the.dll")

EndIf

Or is that just too silly?


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
Beege

Natural progression might raise the question then, how can one enumerate

open handles of a particular module?

If OpenHandles("User32.dll") < 100 Then

$Handle = DllOpen("the.dll")

_Func($Handle)

Else

_Func("the.dll")

EndIf

Or is that just too silly?

Theres _WinAPI_EnumProcessModules and _WinAPI_EnumProcessHandles in

It is silly though..

Edited by Beege

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  

×