1

我试图弄清楚这一点,但有点难过。我想要做的是使用 win32 lib 中的ReadConsole/WriteConsole函数并让它在一定程度上工作,但只是不在那里。我无法让第二个写入控制台正常工作。我不认为我将缓冲区发送到变量。我一定在这里遗漏了一些东西,我不知道它是什么。这是我到目前为止所拥有的

TITLE MASM Template                     (main.asm)

  ; Description:
  ; 
   ; Revision date:

 INCLUDE Irvine32.inc
 BufSize = 80
 .data
  endl EQU <0dh,0ah>            ; end of line sequence

 ;variable holders
 firstN db ?
 fNSize db ($-firstN)

 ;messages for getting input
 fName LABEL BYTE
BYTE "Enter your first name", endl
 fNameSize DWORD ($-fName)

 ;output handlers
 consoleHandle HANDLE 0     ; handle to standard output device
 bytesWritten  DWORD ?      ; number of bytes written

 ;input handlers
 buffer BYTE BufSize DUP(?)
 stdInHandle HANDLE ?
 bytesRead   DWORD ?

 .code
 main PROC
 ; Get the console output handle:
    INVOKE GetStdHandle, STD_OUTPUT_HANDLE
  mov consoleHandle,eax

  ; Write a string to the console:
INVOKE WriteConsole,
  consoleHandle,        ; console output handle
  ADDR fName,           ; string pointer
  fNameSize,            ; string length
  ADDR bytesWritten,    ; returns num bytes written
  0                     ; not used

   ; Get handle to standard input
INVOKE GetStdHandle, STD_INPUT_HANDLE
   mov   stdInHandle,eax

   ; Wait for user input
 INVOKE ReadConsole, stdInHandle, ADDR buffer,
  BufSize, ADDR bytesRead, 0

 ;cheack to see if read consol worked
  mov esi, OFFSET buffer
  mov ecx, bytesRead
  mov ebx, TYPE buffer
  call DumpMem

 ;move the input into the variable
  mov firstN, TYPE  buffer



   ; Write a string to the console:
INVOKE WriteConsole,
  consoleHandle,        ; console output handle
  ADDR firstN,          ; string pointer
  fNSize,           ; string length
  ADDR bytesWritten,    ; returns num bytes written
  0                     ; not used


INVOKE ExitProcess,0
   main ENDP
  END main

谢谢你的帮助 :)

4

1 回答 1

1

firstN 和 fNSize 都是一个字节,这不是你想要的。只需为第二个 WriteConsole 调用执行此操作:

INVOKE WriteConsole,
  consoleHandle,        ; console output handle
  ADDR buffer,          ; string pointer
  bytesRead,            ; string length
  ADDR bytesWritten,    ; returns num bytes written
  0                     ; not used
于 2011-11-30T19:12:35.613 回答