1

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 :)

rkhb
  • 14,159
  • 7
  • 32
  • 60
MNM
  • 2,673
  • 6
  • 38
  • 73
  • You don't say what's wrong with the second WriteConsole call, but I'm guessing you only get one byte of output. Am I right? – Carey Gregory Nov 30 '11 at 18:57
  • I think that right it seams to only give me a smiley looking face which is kinda nice but not what I want – MNM Nov 30 '11 at 19:01

1 Answers1

1

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
Carey Gregory
  • 6,836
  • 2
  • 26
  • 47
  • I was wondering if there was a way to send what is in the buffer into a variable for storage? – MNM Nov 30 '11 at 19:25
  • Of course, but you need to allocate a buffer as large as bytesRead to store it, and then you need to copy the contents of buffer to it. You could dynamically allocate it with HeapAlloc or something similar. – Carey Gregory Nov 30 '11 at 20:12
  • could I use the stack to store the contents of the buffer then mov that to the variable? – MNM Nov 30 '11 at 20:26
  • Sure, but you need to manage the stack pointer yourself. As long as you do that properly you should be okay. – Carey Gregory Dec 01 '11 at 02:43