Jump to content

DLLOpen and Best Practise Below The Salt...


Recommended Posts

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:

Link to comment
Share on other sites

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
Link to comment
Share on other sites

^^ 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.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...