使用MASM64,我无法使用ReadConsoleInputw

问题描述 投票:0回答:1

i我将MASM64与最新的Visual Studio 2022预览使用最新的Windows 11预览。 不使用第三方组装库。只有纯Winapi。 我想在屏幕缓冲区坐标中单击左鼠标按钮时获得鼠标光标的位置。 getMousepos返回像素,因此它无用。 我已经设置了具有正确的STD输入句柄的控制台应用程序。 我已经正确设置了控制台模式(我希望)。 我已经正确设置了X64呼叫约定。 当我致电ReadConsoleInputw时,我可以使其正常工作。 但是它返回正确的y坐标,但x坐标卡在零。 我恳请帮助找出为什么X坐标始终为零。 这是输入句柄和控制台模式的相关设置。 存在错误检查,但在此处删除了勇敢。

; WinAPI libraries. INCLUDELIB kernel32.lib INCLUDELIB user32.lib .CONST ALIGN 2 ; From WinAPI. COORD STRUCT X WORD -1 Y WORD -1 COORD ENDS .CODE ALIGN 16 ; Sets the input handle since its needed for the mouse functions. mov ecx, -10 ; STD_INPUT_HANDLE nStdHandle. ; https://learn.microsoft.com/en-us/windows/console/getstdhandle ; Retrieves a handle to the specified standard output. EXTERNDEF GetStdHandle:PROC ; 2000. call GetStdHandle ; MyStdInputHandleQ is defined as QWORD elsewere. mov [MyStdInputHandleQ], rax ; Saves the returned value. ; Sets the console mode to enable the mouse and disable the keyboard. mov rcx, [MyStdInputHandleQ] ; hConsoleHandle. mov edx, 90h ; ENABLE_MOUSE_INPUT + ENABLE_EXTENDED_FLAGS dwMode. ; https://learn.microsoft.com/en-us/windows/console/setconsolemode ; Sets the input mode of a console's input buffer. EXTERNDEF SetConsoleMode:PROC ; 2000. call SetConsoleMode
在这里是程序:

; Gets the screen buffer mouse click coordinates. MyReadConsoleInputWProc PROC LOCAL MyResultD:DWORD push rbp mov rbp, rsp sub rsp, 4 * 8 sub rsp, 8 ; MyResultD. and rsp, -16 MyLoopLabel: mov rcx, [MyStdInputHandleQ] ; hConsoleInput. .CONST ALIGN 4 ; From WinAPI and used only by it. KEY_EVENT_RECORD STRUCT bKeyDown DWORD -1 wRepeatCount WORD -1 wVirtualKeyCode WORD -1 wVirtualScanCode WORD -1 UNION uChar UnicodeChar WORD -1 AsciiChar BYTE -1 ENDS dwControlKeyState DWORD -1 KEY_EVENT_RECORD ENDS ; From WinAPI and used only by it. MOUSE_EVENT_RECORD STRUCT dwMousePosition COORD <-1, -1> dwButtonState DWORD -1 dwControlKeyState DWORD -1 dwEventFlags DWORD -1 MOUSE_EVENT_RECORD ENDS ; From WinAPI and used only by it. WINDOW_BUFFER_SIZE_RECORD STRUCT dwSize COORD <-1, -1> WINDOW_BUFFER_SIZE_RECORD ENDS ; From WinAPI and used only by it. MENU_EVENT_RECORD STRUCT dwCommandId DWORD -1 MENU_EVENT_RECORD ENDS ; From WinAPI and used only by it. FOCUS_EVENT_RECORD STRUCT bSetFocus DWORD -1 FOCUS_EVENT_RECORD ENDS ALIGN 8 ; From WinAPI. INPUT_RECORD STRUCT EventType WORD -1 UNION Event KeyEvent KEY_EVENT_RECORD <> MouseEvent MOUSE_EVENT_RECORD <> WindowBufferSizeEvent WINDOW_BUFFER_SIZE_RECORD <> MenuEvent MENU_EVENT_RECORD <> FocusEvent FOCUS_EVENT_RECORD <> ENDS INPUT_RECORD ENDS .DATA ALIGN 8 MyInputRecordS INPUT_RECORD <> .CODE ALIGN 16 lea rdx, [MyInputRecordS] ; lpBuffer. mov r8d, 1 ; nLength. lea r9, MyResultD ; lpNumberOfEventsRead. ; https://learn.microsoft.com/en-us/windows/console/readconsoleinput ; Reads data from a console input buffer and removes it from the buffer. EXTERNDEF ReadConsoleInputW:PROC ; 2000. call ReadConsoleInputW ; Checks if the mouse event happend. mov ax, [MyInputRecordS.EventType] cmp ax, 2 ; MOUSE_EVENT. jne MyLoopLabel ; Checks if the left mouse button is pressed. mov eax, [MyInputRecordS.Event.MouseEvent.dwButtonState] test eax, 1 ; FROM_LEFT_1ST_BUTTON_PRESSED. jne MyLoopLabel ; Checks if the mouse button was pressed or released. mov eax, [MyInputRecordS.Event.MouseEvent.dwEventFlags] test eax, eax ; 0 means a mouse button was pressed or released. jne MyLoopLabel ; Gets the mouse cursor coordinates. mov ax, [MyInputRecordS.Event.MouseEvent.dwMousePosition.X] mov [MyCursorPositionCOORD.X], ax ; MyCursorPositionCOORD is defined as COORD elsewere. mov ax, [MyInputRecordS.Event.MouseEvent.dwMousePosition.Y] mov [MyCursorPositionCOORD.Y], ax leave ret MyReadConsoleInputWProc ENDP

我尝试了Stackoverflow,Copilot,其他AI工具,C ++和汇编代码样本的许多解决方案。 我使用调试器查看结构的内部。 我尝试了结构的不同数据对齐。 我希望X坐标在左键时反射鼠标坐标。

这是一个对齐问题。 一旦我将Align 2放在鼠标_EVENT_RECORD struct中的坐标结构上,它就开始起作用。
winapi masm64
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.