Question

I am trying to figure this out but am stumped a bit. What I am trying to do is to use the ReadConsole/WriteConsole functions from the win32 lib and got it to work a degree but just not there. I am having trouble getting the second write console working correctly. I don't think I am sending the buffer to the variable right. I must be missing something here and I dont know what it is. Here is what I have so far

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

Thanks for any help :)

Was it helpful?

Solution

firstN and fNSize are each a single byte and that's not what you want. Simply do this for the second WriteConsole call:

INVOKE WriteConsole,
  consoleHandle,        ; console output handle
  ADDR buffer,          ; string pointer
  bytesRead,            ; string length
  ADDR bytesWritten,    ; returns num bytes written
  0                     ; not used
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top