Jump to content
Sign in to follow this  
Insolence

Trying out DLLCall

Recommended Posts

Insolence

Can't figure out how to translate X and Y into LParam.

Here's what I got so far:

DllCall("user32.dll", "int", "SendMessage", "hwnd", "int", "int","long", 0, "Diablo II - MPQ1", "WM_LBUTTONDOWN", 0, [x and y],0 )
; LRESULT SendMessage( 
;    HWND ,
;    UINT Msg,
;    WPARAM wParam,
;    LPARAM lParam
; );

Been messing with it for the last 2 hours, so it's most likely messed up and jumbled :idiot:


"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites
SumTingWong

Can't figure out how to translate X and Y into LParam.

Here's what I got so far:

DllCall("user32.dll", "int", "SendMessage", "hwnd", "int", "int","long", 0, "Diablo II - MPQ1", "WM_LBUTTONDOWN", 0, [x and y],0 )
; LRESULT SendMessage( 
;    HWND ,
;    UINT Msg,
;    WPARAM wParam,
;    LPARAM lParam
; );

Been messing with it for the last 2 hours, so it's most likely messed up and jumbled :D

<{POST_SNAPBACK}>

MAKEWORD

:idiot:

Share this post


Link to post
Share on other sites
Insolence

Owned me :idiot:

Regardless, I still can't get it to work, heh.

;408, 566 are the coords
HotKeySet("{SPACE}", "Click")

$WM_LBUTTONDOWN   = 0x0201
$MK_LBUTTON       = 0x0001

While 1
   Sleep (50)
WEnd

Func Click()
   DllCall("user32.dll", "int", "SendMessage", "hwnd", "int", "int", "long", 0, "Diablo II", $WM_LBUTTONDOWN, $MK_LBUTTON, MakeWord(408, 566),0 )
EndFunc

Func MakeWord($LoByte,$HiByte)
  Return BitOR($LoByte,0x100 * $HiByte)
EndFunc
; LRESULT SendMessage( 
;    HWND ,
;    UINT Msg,
;    WPARAM wParam,
;    LPARAM lParam
; );

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites
SumTingWong

Doh!

You can't pass a string of the window title as the window handle needed for the SendMessage API.

You must first get the handle for the Diablo II window and pass that value to the SendMessage API along with your params.

Have a look at the

WinGetHandle ( "title" [, "text"] )
function.

Without sounding condescending, you should really try to understand the SendMessage API before attempting to use it.

Edited by pacman

Share this post


Link to post
Share on other sites
Insolence

OH!!!

Agh, I'm an ass, lol. Lemme try that... I know I don't understand it but I tried my best, researched it for about 2 hours last night. I think I did fairly well for not understanding most of it :idiot:

EDIT: Still doesn't work -.-

DllCall("user32.dll", "int", "SendMessage", "hwnd", "int", "int", "long", 0, WinGetHandle ("Diablo II"), $WM_LBUTTONDOWN, $MK_LBUTTON, MakeWord(408, 566),0 )
Edited by Insolence

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites
SumTingWong

Right.

First of all, you're not using DllCall correctly

Each parameter value needs to follow its type description in DllCall.

LPARAM is a double-word value where:

The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.

The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.

The correct call should be:

DllCall("user32.dll", "int", "SendMessage", _
     "hwnd", WinGetHandle("Diablo II"), _
     "int", $WM_LBUTTONDOWN, _
     "int", $MK_LBUTTON, _
     "long", MakeLong(MakeWord(xxx, xxx), MakeWord(yyy, yyy)))

can't guarantee that this will work as I don't have Diablo II but that's the proper way to use DllCall.

Sorry, that number thing won't work for WinGetHandle

Edited by pacman

Share this post


Link to post
Share on other sites
Insolence

Agh sorry, I'm really trying hard to understand this and being the egotistical person I am it's hard to ask for help.

Thanks for not being rough on me :idiot:

EDIT - I still can't get it to work... this is heart deafening

DllCall("user32.dll", "int", "SendMessage", _
    "hwnd", WinGetHandle("Diablo II"), _;also tried number() here
    "int", $WM_LBUTTONDOWN, _
    "int", $MK_LBUTTON, _
    "long", MakeLong(MakeWord(408, 408), MakeWord(566, 566)))

I set the return to $y and throw it to a message box and it's NULL. I'm really sorry this is such a pain in the ass to explain for you C++ adept fellas :D

Edited by Insolence

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites
SumTingWong

Sorry, final thing.

You need to convert the hex value string returned by WinGetHandle to decimal before passing to SendMessage.

The Hex2Dec function you need is here

DllCall("user32.dll", "int", "SendMessage", _
   "hwnd", Hex2Dec(WinGetHandle("Diablo II")), _
   "int", $WM_LBUTTONDOWN, _
   "int", $MK_LBUTTON, _
   "long", MakeLong(MakeWord(408, 408), MakeWord(566, 566)))

Share this post


Link to post
Share on other sites
Valik

You don't need MakeWord at all. MakeLong(408, 566) should be enough.

Share this post


Link to post
Share on other sites
SumTingWong

You don't need MakeWord at all.  MakeLong(408, 566) should be enough.

<{POST_SNAPBACK}>

DOH!

:"> Sorry...that was me having a stupid moment.

Share this post


Link to post
Share on other sites
Insolence

lol, no problem, lemme try that :idiot:

EDIT-

What a bitch, not working:

Func Click()
   $y = DllCall("user32.dll", "int", "SendMessage", _
      "hwnd",  Hex2Dec(WinGetHandle("Diablo II")), _
      "int",   $WM_LBUTTONDOWN, _
      "int",   $MK_LBUTTON, _
      "long",  MakeLong(408, 566))
   
   MsgBox("","", $y)
EndFunc

Func MakeLong($LoWord,$HiWord)
 Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc

Func Hex2Dec($hexa)
  $decimal = 0
  For $i = 0 To StringLen($hexa) Step 1
    $char = StringMid($hexa, StringLen($hexa)-$i, 1)
    If $char='A' Then
      $single = 10
    ElseIf $char='B' Then
      $single = 11
    ElseIf $char='C' Then
      $single = 12
    ElseIf $char='D' Then
      $single = 13
    ElseIf $char='E' Then
      $single = 14
    ElseIf $char='F' Then
      $single = 15
    Else
      $single = Number($char)
    EndIf
    $decimal = $decimal + $single*(16^$i)
  Next
  Return $decimal
EndFunc

This brings me back to my PHP days of missing one little thing in a thousand line script... ugh.

Edited by Insolence

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites
SumTingWong

lol, no problem, lemme try that :D

This brings me back to my PHP days of missing one little thing in a thousand line script... ugh.

<{POST_SNAPBACK}>

Welcome to the world of WIN32 programming :idiot:

DllCall returns an array with the first element being the returned value from SendMessage.

Therefore, the MsgBox line should be:

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

According to MSDN, if the application processes this message, it should return zero.

Edited by pacman

Share this post


Link to post
Share on other sites
Insolence

$y = 0, so I guess it IS processing it?

I must have to try PostMessage or something if it's not working now, right?

[EDIT] PostMessage returns 1, so there must be an error.

Edited by Insolence

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites
Valik

You don't need to convert the handle from WinGetHandle() to anything...

Not to be rude... but should you really be using DllCall() when you obviously have zero clue what you are doing? This isn't exactly a newbie friendly function.

Share this post


Link to post
Share on other sites
Insolence

I think I should be learning it, I mean why not?

I'm going to be learning C++ soon, I've worked a LITTLE with this function a LONG time ago, I just don't understand all of it yet. What's wrong with one more person to help out the masses who will be using this function later on? :idiot:

Works now, I think I love you, Valik.

Edited by Insolence

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.