danielkza Posted March 8, 2011 Share Posted March 8, 2011 (edited) _WinAPI_HiWord() and _WinAPI_LoWord() seem to have inconsistent treatment of their parameters. The former seems to treat integers as signed, and the latter as unsigned. See this simple example: #include <WinAPI.au3> Global $Test = 0xFFFFFFFF MsgBox(0, "HiLoWord Test", "HiWord: " & _WinAPI_HiWord($Test) & @CRLF & _ "LoWord: " & _WinAPI_LoWord($Test) & @CRLF) ; [Output] ; HiWord: -1 ; LoWord: 65535 Is that intended behavior? I believe both functions should output the same value in this example, as both the low and high words are 0xFFFF. Edited March 8, 2011 by danielkza Link to comment Share on other sites More sharing options...
JohnOne Posted March 8, 2011 Share Posted March 8, 2011 Maybe it dosent like the 8 fs Global $Test = 0xFFFFFF works. 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 More sharing options...
danielkza Posted March 8, 2011 Author Share Posted March 8, 2011 Maybe it dosent like the 8 fsGlobal $Test = 0xFFFFFF works.It works by accident, because 00FF happens not to have the sign bit set. 0xFFFFF0FF (-1, signed -3841 ) is returned as (-1, unsigned 61695) too, for instance. Link to comment Share on other sites More sharing options...
kylomas Posted March 8, 2011 Share Posted March 8, 2011 danielkza, There is NO inconsistent behavior, nor is this an accident. $test is a double word with the sign carried in the most significant bit. When you break this into two words the low order word is positive and the hi order word is negative in your example. Google data representation for detailed explanations.kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
danielkza Posted March 8, 2011 Author Share Posted March 8, 2011 (edited) danielkza, There is NO inconsistent behavior, nor is this an accident. $test is a double word with the sign carried in the most significant bit. When you break this into two words the low order word is positive and the hi order word is negative in your example. Google data representation for detailed explanations. kylomas The sign bit would matter if I were trying to represent a single integer as a doubleword. In my case, the dword happens to be the concatenation of two separate words. The most significant bit is not a sign bit: it is simply part of one of the words. LoWord and HiWord exist for that exact case that shows up quite often in the Windows API. Since the values they return are always single words, they should treat them as so, and not carry the sign bit from whatever intermediate representation exists inside them (that's what is happening on the current code, with BitAND treating all it's parameters as unsigned). This behavior is not consistent with the function's goals. I ran into the problem while handling the WM_CONTEXTMENU message. See some of the description: xPos = GET_X_LPARAM(lParam); yPos = GET_Y_LPARAM(lParam); If the context menu is generated from the keyboard—for example, if the user types SHIFT+F10—then the x- and y-coordinates are -1 and the application should display the context menu at the location of the current selection rather than at (xPos, yPos). GET_X_PARAM is defined as ((int)(short)LOWORD(lp)) I tried the most obvious code, which obviously doesn't work. Local $PosX = _WinAPI_LoWord($lParam), $PosY = _WinAPI_HiWord($lParam) If $PosX = -1 And $PosY = -1 Then ; Do Stuff EndIF This issue should at least be documented somewhere. I spent 1:30h debugging the rest of my code because I never expected LoWord and HiWord not to work as they would in C code. A notice in the help file would be very helpful already. Edited March 8, 2011 by danielkza Link to comment Share on other sites More sharing options...
MvGulik Posted March 8, 2011 Share Posted March 8, 2011 (edited) Did you take in consideration that auotit(oops) autoit only has and uses signed integer's. (int32 or int64 flavor)Anyway. Its always a good thing to check any assumptions ... if your not completely 100% sure about how something might work or turn out ... in a other code language. Edited March 8, 2011 by iEvKI3gv9Wrkd41u "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
kylomas Posted March 8, 2011 Share Posted March 8, 2011 danielkza, This is one of those issues that can be argued forever, depending on expectations and point of view. I do agree with you on one point, the doc for the WinAPI could be better. On the other hand... You get my point, I hope! kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
danielkza Posted March 8, 2011 Author Share Posted March 8, 2011 Did you take in consideration that auotit(oops) autoit only has and uses signed integer's. (int32 or int64 flavor)Anyway. Its always a good thing to check any assumptions ... if your not completely 100% sure about how something might work or turn out ... in a other code language.If both numbers were treated as signed it would work exactly as I expect. The problem is that BitAND treats it's arguments as unsigned, messing up everything. If this was documented I would indeed have found out about it early on, but unfortunately it is not.danielkza, This is one of those issues that can be argued forever, depending on expectations and point of view. I do agree with you on one point, the doc for the WinAPI could be better. On the other hand...You get my point, I hope!kylomasI'd be satisfied as long as things were consistent, with both words treated as signed or unsigned. Link to comment Share on other sites More sharing options...
MvGulik Posted March 8, 2011 Share Posted March 8, 2011 ... The problem is that BitAND treats it's arguments as unsigned, ..... Wow ... I'm out. "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Malkey Posted March 9, 2011 Share Posted March 9, 2011 Here's my two cents worth. Does Yes = Si = Oui = Da = Ya ? Answer: Yes and no. Does -1 = 0xFFFFFFFF? Answer: Yes and no. (signed and unsigned integers) Here's Post #1 example completed. #include <WinAPI.au3> Global $Test = 0xFFFFFFFF MsgBox(0, "HiLoWord Test", "0xFFFFFFFF: " & 0xFFFFFFFF & @CRLF & _ "HiWord: " & _WinAPI_HiWord($Test) & @CRLF & _ "LoWord: " & _WinAPI_LoWord($Test) & @CRLF & _ "HiWord: " & hex(_WinAPI_HiWord($Test),4) & @CRLF & _ "LoWord: " & hex(_WinAPI_LoWord($Test),4) & @CRLF) #cs [Output] 0xFFFFFFFF: -1 HiWord: -1 LoWord: 65535 HiWord: FFFF LoWord: FFFF [Copied from WinAPI.au3 include file.] Func _WinAPI_HiWord($iLong) Return BitShift($iLong, 16) EndFunc ;==>_WinAPI_HiWord Func _WinAPI_LoWord($iLong) Return BitAND($iLong, 0xFFFF) EndFunc ;==>_WinAPI_LoWord #ce This works. #include <WinAPI.au3> Local $lParam = 0xFFFFFFFF Local $PosX = Hex(_WinAPI_LoWord($lParam), 4), $PosY = Hex(_WinAPI_HiWord($lParam), 4) If "0X" & $PosX = 0xFFFF And "0X" & $PosY = 0xFFFF And $PosX = "FFFF" And $PosY = "FFFF" Then ; MsgBox(0, "Results", "$PosX And $PosY equal.") EndIf Link to comment Share on other sites More sharing options...
Yashied Posted March 9, 2011 Share Posted March 9, 2011 Method 1Global $Test = 0xFFFFFFFF $PosX = BitAND($Test, 0xFFFF) $PosY = BitShift($Test, 16) If $PosX > 0x7FFF Then $PosX -= 0x10000 If $PosY > 0x7FFF Then $PosY -= 0x10000 MsgBox(0, "HiLoWord Test", "HiWord: " & $PosX & @CRLF & _ "LoWord: " & $PosY & @CRLF)Method 2Global $Test = 0xFFFFFFFF $tStruct1 = DllStructCreate('dword XY') $tStruct2 = DllStructCreate('short Y;short X', DllStructGetPtr($tStruct1)) DllStructSetData($tStruct1, 'XY', $Test) $PosX = DllStructGetData($tStruct2, 'X') $PosY = DllStructGetData($tStruct2, 'Y') MsgBox(0, "HiLoWord Test", "HiWord: " & $PosX & @CRLF & _ "LoWord: " & $PosY & @CRLF) matwachich 1 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
danielkza Posted March 9, 2011 Author Share Posted March 9, 2011 (edited) Thank you guys, I had found a workaround already (in this particular case I just need to check for -1 in both words, so checking for 0xFFFFFFFF is enough). Maybe'll file a bug report one of these days asking if the devs want to change it or at least document things better. Edited March 9, 2011 by danielkza Link to comment Share on other sites More sharing options...
matwachich Posted February 24, 2022 Share Posted February 24, 2022 The feature request would be to add functions: _WinAPI_GetXParam and _WinAPI_GetYParam Here is my attempt Func _WinAPI_GetXParam($lParam) $t = DllStructCreate("dword XY") $t.XY = $lParam $t2 = DllStructCreate("short X; short Y", DllStructGetPtr($t)) Return $t2.X EndFunc Func _WinAPI_GetYParam($lParam) $t = DllStructCreate("dword XY") $t.XY = $lParam $t2 = DllStructCreate("short X; short Y", DllStructGetPtr($t)) Return $t2.Y EndFunc Link to comment Share on other sites More sharing options...
Nine Posted February 24, 2022 Share Posted February 24, 2022 Lol 10 years after. One of my favorite rock groups. Kind of useless answer IMHO. matwachich 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now