Jump to content
Venix

Problem calling DLL

Recommended Posts

Venix

Hi, I had some downtime at work so I thought why not code some AutoIT for the first time in like 2 years. :)

I am currently trying to get a windows move state using GetGUIThreadInfo in user32.dll so I have been going through the following documentation to figure out how to do so.

https://msdn.microsoft.com/en-us/library/ms633506(VS.85).aspx

https://msdn.microsoft.com/en-us/library/ms632604(v=vs.85).aspx

https://msdn.microsoft.com/en-us/library/ms633522(v=vs.85).aspx

 I think the first DLL call I need to make is to call the function GetWindowThreadProcessId. Unfortunately when I try to do so the application just crashes. I am not sure if I am doing something wrong as I have pretty much no experience calling DLL's. I have a feeling the crashing might be to do with the crap computers I'm using at work.

Currently I have something along these lines. Is anyone able to give me a push in the right direction? :)

 

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>
Opt("MustDeclareVars")

Dim $hCurrentWindow, $dllTest

$hCurrentWindow = WinGetHandle("[Active]")
$dllTest = DllCall("user32.dll", "DWORD", "GetWindowThreadProcessId", "HWND", $hCurrentWindow)

Share this post


Link to post
Share on other sites
Starstar

 

$struc = "struct;DWORD lpdwProcessId;endstruct"
$struccrt = DllStructCreate($struc)
$hCurrentWindow = WinGetHandle("[Active]")

$dllTest = DllCall("user32.dll", "DWORD", "GetWindowThreadProcessId", "HWND*", $hCurrentWindow,"ptr",DllStructGetPtr($struccrt))

MsgBox(0,"",$dllTest[0])

[Edit::]

Your problem is that you are trying to get Window Thread Process Id. But you are not giving a space to where to store retrieved Data(ID).


Try this one...

Edited by Starstar
  • Like 1

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
Venix

Unfortunately I don't have a way to actively test this at the moment because the two systems I am using are completely closed off from each other but Ill look into it when I get home. Thanks for the help Starstar.

Share this post


Link to post
Share on other sites
Starstar

No problem Bro.Code has tested in win7 by me.......

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
Venix

I typed your previous code out manually on the system I am testing on and it worked perfectly. I am going to look into Dll Structs as I don't really know what they are not something I have ever researched. Would you mind explaining why you put in "HWND*" as the parameter type rather than just "HWND".? :)

Share this post


Link to post
Share on other sites
Starstar

I copied this line for you from help dllcall

"Add * to the end of another type to pass it by reference. For example "int*" passes a pointer to an "int" type."

* indicate that following one is by reference.......

[Edit::]

Reference means this parameter or variable has not value directly but by the other source.

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
Venix

Cool thanks, I think GetWindowThreadProcessID returns the same value as WinGetHandle("[Active]") anyway so I don't believe this particular DLL call will be necessary in my overall solution. But of course I will need to make other calls so I can refer back to your example for that :).

Share this post


Link to post
Share on other sites
Starstar

You needed or not but everything that can increase your knowledge is precious.


Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
Venix

I should be ok to continue from here, Ill probably just add to this thread if I have anymore queries on this subject. Thanks again, you have been a great help.

Share this post


Link to post
Share on other sites
Starstar

I should be ok to continue from here, Ill probably just add to this thread if I have anymore queries on this subject. Thanks again, you have been a great help.

My Pleasure.....


Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
Venix

​Was trying to find a WinAPI function for this but didn't see it, thanks for pointing that out. I still seem to be struggling to get back the information I am after from GetGUIThreadInfo. Just seems to be returning 0 which I believe is a failure.

This is what I currently have.

$hCurrentWindow = WinGetHandle("[Active]")
$threadProcessID = _WinApi_GetWindowThreadProcessId($hCurrentWindow, _WinAPI_GetProcessID())
$struc = "struct:BOOL lpgui;endstruct"
$struccrt = DllStructCreate($struc)
$dllTest = DllCall("user32.dll", "BOOL", "GetGUIThreadInfo", "DWORD*", $threadProcessID, "ptr", DllStructGetPtr($struccrt))

Edit::

MsgBox(0, "", $dllTest[0])

Do any of you see any noticeable errors? :)

Edited by Venix
Code Error

Share this post


Link to post
Share on other sites
Starstar

Your structure is wrong....Try some one like this...

$struct2 =  "struct;DWORD cbSize;DWORD flags;HWND hwndActive;HWND hwndFocus;HWND hwndCapture;HWND hwndMenuOwner;HWND hwndMoveSize;HWND hwndCaret;RECT rcCaret;endstruct"
$struccreat2 =  DllStructCreate($struct2)

and also set the size of structure.....because this function also required it.......

DllStructSetData($struccreat2,"cbSize", DllStructGetSize($struccreat2))

 

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
Venix

Alright thanks, I just made an assumption for the structure based on the data that was in the last one.  Do you know of any resources that explain the structure as I would like to learn?

Edited by Venix

Share this post


Link to post
Share on other sites
Starstar

https://msdn.microsoft.com/en-us/library/windows/desktop/ms632604(v=vs.85).aspx

Here is your structure information.You have nothing to do just write the type(like dword ,int ,str) of a variable and the name of variable as you wish..........

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
Venix

Ahh awesome, that makes sence now. :)

Share this post


Link to post
Share on other sites
Starstar

Ahh awesome, that makes sence now. :)

​Good keep it up......


Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

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

×