我在嘗試檢測x86彙編語言中的關鍵事件時遇到了問題。當我運行我的程序時,出現此通用錯誤:檢測關鍵事件
key.exe遇到問題並需要關閉。對此造成的不便,我們表示歉意。
我的彙編程序fasm生成.bin文件,.exe文件和.com文件。如果我嘗試運行.com文件,會彈出一個消息框,提示圖像文件是有效的,但用於除當前機器以外的機器類型。
這裏是我的代碼:
include 'include/win32ax.inc'
section '.data' data readable writeable
inchar DB ?
numwritten DD ?
numread DD ?
outhandle DD ?
inhandle DD ?
char DB ?
section '.text' code readable executable
start:
;set up the console
invoke AllocConsole
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov [outhandle],eax
invoke GetStdHandle,STD_INPUT_HANDLE
mov [inhandle],eax
;get key press
mov ah,1h
int 21h
mov [char],AL
;print out the key pressed
invoke WriteConsole,[outhandle],char,15,numwritten,0
invoke ReadConsole,[inhandle],inchar,1,numread,0
invoke ExitProcess,0
.end start
我使用Windows XP的64位版本,但它與32位應用程序兼容。
你看上去編譯在其32位Windows的特定代碼DOS .COM程序。這是行不通的。 –
@AlexeyFrunze我可以舉一個例子來說明什麼會起作用嗎?當我谷歌大會關鍵事件,我只是得到int 21h的東西 – user2097804