Jump to content

Dllcalling question


Recommended Posts

Hi, I am trying to call a SendInput function from user32.dll but I just don't understand what kind of type should I put in, could anyone post an example of a call for it and a use of the function if you can?

Link to comment
Share on other sites

  • Moderators

Hi, I am trying to call a SendInput function from user32.dll but I just don't understand what kind of type should I put in, could anyone post an example of a call for it and a use of the function if you can?

Why would you be using an API call to SendInput and not just Send() from the regular functions that utilizes keybd_event API already?

http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspx

http://msdn.microsoft.com/en-us/library/ms646270(VS.85).aspx

DllCall for the first link and to create the pointer you'll need to use DllStructCreate for the pointer (2nd link).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Keybd_event fails at working.

So I call the struct create and stick the function of it in the type of calls in the sendinput?

Somewhat understood.

Edited by Misha
Link to comment
Share on other sites

  • Moderators

No..I dont get it, can you give an example for the dllstructcreate?

I'm not sure how AutoIt supports Unions to be honest. You have two structs at any one time you'd have to use.

$tagKEYBDINPUT = DllStructCreate("short;short;dword;dword;ulong*")

$tagInput = DllStructCreate("dword;uint");Something tells me you need to pass the $tagKEYBDINPUT as a pointer to this struct... 0.o

That of course is without testing and written in here based on the links provided.

Edit:

IMO, If keybd_event is failing, I seriously can't see SendInput working though.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Func sendinput($nInputs,$pInput,$cbSize)

DllOpen("user32.dll")

$tagKEYBDINPUT = DllStructCreate("short;short;dword;dword;ulong*")

$tagInput = DllStructCreate("dword;uint",$tagKEYBDINPUT)

$return = dllcall("user32.dll","Long","SendInput",$tagInput,$nInputs,$tagKEYBDINPUT,$pInput,"int",$cbSize)

Return $return

EndFunc

SendInput(18,0,1)

I tried this blindly since I dont quite understand, wheres my error

Oh and I tested it already, sendinput works but keybd/mouse events dont

Edited by Misha
Link to comment
Share on other sites

  • Moderators

Func sendinput($nInputs,$pInput,$cbSize)

DllOpen("user32.dll")

$tagKEYBDINPUT = DllStructCreate("short;short;dword;dword;ulong*")

$tagInput = DllStructCreate("dword;uint",$tagKEYBDINPUT)

$return = dllcall("user32.dll","Long","SendInput",$tagInput,$nInputs,$tagKEYBDINPUT,$pInput,"int",$cbSize)

Return $return

EndFunc

SendInput(18,0,1)

I tried this blindly since I dont quite understand, wheres my error

Oh and I tested it already, sendinput works but keybd/mouse events dont

How did you test it already if you can't even get it to work?

I have no idea what you are really doing there, or what you think you are doing.

Where did you get 18 for the number of arrays in the input structure?

Again, this is not tested... but you didn't create the call to the dll with even the types you were sending it:

Local $tagKEYBDINPUT = DllStructCreate("short;short;dword;dword;ulong*")
Local $tagInput = DllStructCreate("dword;uint")
Return DllCall("user32.dll","Long","SendInput", "uint", $nInputs, "ptr", DllStructGetPtr($tagInput), "int", DllStructGetSize($tagInput))

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

My friend tested it with c++.

I truly wonder what the hell am I doing..

Readed it wrongly, understood now

and yea, I really don't understand the dll structers so its hard for me to write this, I guess after this is solved I will understand this.

func sendinput($nInputs,$pInput,$cbSize)
DllOpen("user32.dll")
Local $tagKEYBDINPUT = DllStructCreate("short;short;dword;dword;ulong*")
Local $tagInput = DllStructCreate("dword;uint")
DllStructSetData ($tagKEYBDINPUT, 3,"INPUT_KEYBOARD",)
Dllstructsetdata($tagKEYBDINPUT,2,$pInput)
Return DllCall("user32.dll","Long","SendInput", "uint", $nInputs, "ptr", DllStructGetPtr($tagInput), "int", DllStructGetSize($tagInput))
endfunc
SendInput(1,14,1)

still not quite......I added the setdata because I figured i need to specify the type and the actually keyascii so I figured thats how it supposed to be.

Edited by Misha
Link to comment
Share on other sites

I'm not sure how AutoIt supports Unions to be honest. You have two structs at any one time you'd have to use.

Just a comment here on how to deal with a union in AutoIt.

$struct1 = DllstructCreate("int;int;")

$Struct2 = DllStructCreate("short;short",DllStructGetPtr($Struct1))

Then if you read Struct1 you read ints, but if you use struct2 you read shorts.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Moderators

Just a comment here on how to deal with a union in AutoIt.

$struct1 = DllstructCreate("int;int;")

$Struct2 = DllStructCreate("short;short",DllStructGetPtr($Struct1))

Then if you read Struct1 you read ints, but if you use struct2 you read shorts.

Yeah, I was fairly sure that was it, but my doubt came when I attempted to do that in the above scenario and it failed.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Yeah, I was fairly sure that was it, but my doubt came when I attempted to do that in the above scenario and it failed.

Ah, well I'm not brave enough to do it, I just talk about it.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I finally understood, looking at the screen last 15 minutes trying to figure it out.

The topic went a little off and I am already too tired to solve this further but I shall post it anyway what I thought was right...

func sendinput($nInputs,$pInput,$cbSize)
DllOpen("user32.dll")
Local $tagKEYBDINPUT = DllStructCreate("dword;dword;ulong*")

local $Substruct1 = dllstructcreate("short",$tagKEYBDINPUT)
local $Substract = dllstructcreate("word;word;dword;dword;ulong*")
Local $tagInput = DllStructCreate("dword;uint")
DllStructSetData ($Substruct, 1,"INPUT_KEYBOARD",)
Dllstructsetdata($Substruct,2,$pInput)
Return DllCall("user32.dll","Long","SendInput", "uint", $nInputs, "ptr", DllStructGetPtr($tagInput), "int", DllStructGetSize($tagInput))
endfunc
SendInput(1,14,1)

If you havent lost interest yet tell me if its correct.

Edited by Misha
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...