Jump to content

How to check if DllCall will work before calling a function


DCCD
 Share

Recommended Posts

Hi everybody, To give you an idea, take a look at this simple example of a message box using DllCall function.

$result = DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0)

The question is how to check if DllCall will work before the message box appear?

Thanks & any help would be greatly appreciated..

Link to comment
Share on other sites

  • Moderators

DCCD,

Are you trying to see if a dll is present on the machine and ready to use? Perhaps you could make a hidden call to the same dll earlier in the script and see if you get an error response. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@Melba23, thanks a lot.

let's say i have another Dll has a func that i'd like to use, unfortunately if i call that func and it is being used by another process caused an unexpected error.

Actually the DllCall return value has a lot of helpful information about the error but unfortunately too late!.

About the hidden call, I tried hard to understand that but no luck! what do you mean by the hidden call?

Thanks again..

Link to comment
Share on other sites

  • Moderators

DCCD,

I came up with the "hidden call" idea because I thought you were checking for the availabilty of the DLL in general, not just a single function. The idea was that you would just use a simple call to the DLL with no visible effect on your script to see if it returned correctly. :bye:

As to your actual requirement to check if a specific function is in use - I am afraid I have no idea. But if it is critical, why not put the call into a loop like this pseudo-code:

start loop
    call dll
    if not error exitloop
    sleep
reloop
if we get here then the call succeeded

Then you will keep calling until your call is successful.. You may want to add a loop counter and abandon the call if yo get too many failures. :doh:

Any help? :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

let's say i have another Dll has a func that i'd like to use, unfortunately if i call that func and it is being used by another process caused an unexpected error.

That's nonsense.

DllCall() is advanced AutoIt feature for advanced users. The fact that you have managed to construct quoted sentence means you shouldn't be using DllCall() yet. Learn more.

As for DLL availability (check even), use DllOpen() function.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Did you create the offending DLL yourself?

If yes, care to show us the full code/data of the DLL function you invoke?

If not, which DLL are you talking about and why is it built in such a wrong way that it misbehaves?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

That's nonsense.

DllCall() is advanced AutoIt feature for advanced users. The fact that you have managed to construct quoted sentence means you shouldn't be using DllCall() yet. Learn more.

As for DLL availability (check even), use DllOpen() function.

Do i really need to use DllOpen() function, to check a specific function?, i don't think so..

Did you create the offending DLL yourself?

If yes, care to show us the full code/data of the DLL function you invoke?

If not, which DLL are you talking about and why is it built in such a wrong way that it misbehaves?

Actually no, it's not mine, there's nothing wrong with the Dll file, it's simple as my first

How to get some information or check if MessageBox function exists before the message box appear?

DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0)

@trancexx & @jchd, Thank You, all of you

Link to comment
Share on other sites

See the functions _WinAPI_LoadLibrary() and _WinAPI_GetProcAddress()

If you can get the address in the DLL of the procedure, chances are it exists in the DLL.

As far as some other program already having a function in use, DLL code is shared but the data is exclusive to each process (aside from specifically created shared data segments etc..)

Unless you are manipulating some hardware or have a locked file, it shouldn't matter if some program is using a function in a DLL. Windows calls are almost all in DLLs and many processes use them all the time.

Edited by MilesAhead
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

×
×
  • Create New...