News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Console IN

Started by bomz, September 01, 2010, 05:24:29 PM

Previous topic - Next topic

bomz

..............................................
   invoke GetStdHandle, STD_INPUT_HANDLE
   .IF eax!=INVALID_HANDLE_VALUE
   invoke ReadFile, eax, addr String, sizeof String, addr Lenth, NULL
   .IF Lenth!=0
   invoke OemToChar, addr String, addr Buffer
..............................................

Help me please.
TYPE MY.TXT | MYPROG.EXE
error occurs in invoke GetStdHandle, STD_INPUT_HANDLE, if size of MY.TXT more than about 3.5 kb.Why? (trying to write to unexisting chanel)

How to differ this event
echo off|MYPROG.EXE
and this
MYPROG.EXE


invoke CreateFile,CONIN$,GENERIC_READ,0,0,OPEN_EXISTING,0,0
How CONIN$ use in CreateFile?

frktons

Quote from: bomz on September 01, 2010, 05:24:29 PM
..............................................
   invoke GetStdHandle, STD_INPUT_HANDLE
   .IF eax!=INVALID_HANDLE_VALUE
   invoke ReadFile, eax, addr String, sizeof String, addr Lenth, NULL
   .IF Lenth!=0
   invoke OemToChar, addr String, addr Buffer
..............................................

Help me please.
TYPE MY.TXT | MYPROG.EXE
error occurs in invoke GetStdHandle, STD_INPUT_HANDLE, if size of MY.TXT more than about 3.5 kb.Why? (trying to write to unexisting chanel)

How to differ this event
echo off|MYPROG.EXE
and this
MYPROG.EXE


invoke CreateFile,CONIN$,GENERIC_READ,0,0,OPEN_EXISTING,0,0
How CONIN$ use in CreateFile?

As far as I know GetStdHandle is used for the Console handle, for files maybe
you have to use another API call.
Not sure anyway, the handles can be used in many ways.
Mind is like a parachute. You know what to do in order to use it :-)

bomz

#2
readfile understand console handle too. code is working, but mistakes occurs for input biger than ~4,07 КБ (4 174 байт) bytes
http://msdn.microsoft.com/en-us/library/aa365467(VS.85).aspx
Quote
Parameters

hFile [in]

    A handle to the device (for example, a file, file stream, physical disk, volume, console buffer, tape drive, socket, communications resource, mailslot, or pipe).

frktons

Quote from: bomz on September 01, 2010, 07:13:52 PM
readfile understand console handle too. code is working, but mistakes occurs for input biger that ~3700 bytes

Usually you:
1. get an handle
2. open the file
3. read the file
4. close the file

I'm not sure if you do all of the above, and in the correct order.
Mind is like a parachute. You know what to do in order to use it :-)

bomz

it's working. put CONIN to clipboard
Quote
.386

.model flat, stdcall
option casemap :none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib

.data

.data?
Lenth dd ?
hMemory dd ?
pMemory dd ?
Buffer db 65536 dup(?)
String db 65536 dup(?)

;hStdIn dd ?
;evEvents word ?
;evBuffer INPUT_RECORD <>

.code
start:
   invoke GetStdHandle, STD_INPUT_HANDLE
   .IF eax!=INVALID_HANDLE_VALUE
   invoke ReadFile, eax, addr String, sizeof String, addr Lenth, NULL
   .IF (Lenth)   ;.IF Lenth!=0
   invoke OemToChar, addr String, addr Buffer
   dec Lenth
   invoke GlobalAlloc,LMEM_MOVEABLE,Lenth
   mov  hMemory,eax
   invoke GlobalLock,hMemory
   mov pMemory,eax
   invoke lstrcpy,pMemory,addr Buffer
   invoke GlobalUnlock,hMemory
   invoke OpenClipboard,NULL
   invoke EmptyClipboard
   invoke SetClipboardData,CF_TEXT,hMemory
   invoke CloseClipboard
   invoke GlobalFree,hMemory
   .ENDIF
   .ENDIF
   invoke ExitProcess,0
end start

Vortex

Hi bomz,

Another one with C run-time functions :


include     scanf.inc

.data

string1     db 'What is your name?',13,10,13,10,0
string2     db 'Nice to meet you %s',13,10,0
f1          db '%s',0


.data?

szName      db 32 dup(?)

.code

start:

    invoke  crt_printf,ADDR string1
    invoke  crt_scanf,ADDR f1,ADDR szName
    invoke  crt_printf,ADDR string2,ADDR szName

    invoke  ExitProcess,0

END start

bomz

thanks I try it, but I want do this using only windows api

bomz

Quote
.386

.model flat, stdcall
option casemap :none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib
include     \MASM32\INCLUDE\msvcrt.inc
includelib \MASM32\LIB\msvcrt.lib
.data

string1     db 'What is your name?',13,10,13,10,0
string2     db 'Nice to meet you %s',13,10,0
f1          db '%s',0


.data?

szName      db 32 dup(?)

.code

start:

    invoke  crt_printf,ADDR string1
    invoke  crt_scanf,ADDR f1,ADDR szName
    invoke  crt_printf,ADDR string2,ADDR szName

    invoke  ExitProcess,0

END start

bomz

#8
Quote
BufferSize     COORD <>
...
mov BufferSize.x, 80
mov BufferSize.y, 10000
invoke SetConsoleScreenBufferSize, eax, addr BufferSize
this don't fix error. I am not shure that use this correct

using this construction
Quote
invoke  StdIn,ADDR String,sizeof String
mov Lenth,eax
cause the same error

and this too
    invoke  crt_scanf,ADDR f1,ADDR szName

japheth


   invoke SetClipboardData,CF_TEXT,hMemory
   invoke CloseClipboard
   invoke GlobalFree,hMemory


I guess you shouldn't free the memory handle.

Here's a working clipboard sample:


CopyStringToClipboard proc public hWnd:HWND, pszText:LPSTR

local hGlobal:HGLOBAL
local pGlobal:ptr byte

invoke lstrlen, pszText
inc eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_DDESHARE, eax
mov hGlobal,eax
.if (eax != 0)
invoke GlobalLock,hGlobal
.if (eax)
invoke lstrcpy, eax, pszText
invoke GlobalUnlock,hGlobal
invoke OpenClipboard, hWnd
invoke EmptyClipboard
invoke SetClipboardData,CF_TEXT,hGlobal
invoke CloseClipboard
.endif
.endif
ret
align 4

CopyStringToClipboard endp


bomz

in your code memory free when your call invoke ExitProcess,0

PS or RET

the question is not how to use clipboard but how use CONIN$, you may use    invoke  StdOut,ADDR String to see what you read from CONIN$. I need it because invoke OemToChar, addr String, addr Buffer - my windows xp russian. In windows vista and windows 2008 server there is a utility CLIP.EXE, it's do the same but can put to clipboard more than 8 kb. and no error occurs

this code call the same error
Quote
.386

.model flat, stdcall
option casemap :none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib

.data

.code
start:
   invoke GetStdHandle, STD_INPUT_HANDLE
   invoke ExitProcess,0
end start

May be buffer may be resize hear???
Quote
ECHO OFF
COLOR 9F
CLS
C:\masm32\bin\ml.exe /c /coff current.asm
C:\masm32\bin\link.exe /subsystem:console current.obj
DEL current.obj
pause
or hear
Quote
.386

.model flat, stdcall
option casemap :none

Yuri

"CONIN$" is a string, not a label. So, something like this should work:

.data

szConIn     DB "CONIN$",0

.code

invoke CreateFile,addr szConIn,GENERIC_READ,0,0,OPEN_EXISTING,0,0

bomz

I try so no result

may be so - 2>CON   . ??????

jj2007

Be sure to use FILE_SHARE_READ when opening "CONIN$"

http://support.microsoft.com/kb/90088

bomz