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

thanks a lot. I trying this.

bomz

how to differ
Quote
include \masm32\include\masm32rt.inc

.data

.data?
Lenth dd ?

.code
start:
   invoke GetStdHandle, STD_INPUT_HANDLE
   invoke GetFileSize,eax,addr Lenth
   MsgBox 0, str$(eax), 0, MB_OK
   invoke ExitProcess,0
end start


Quote
ECHO OFF
COLOR 9F
CLS
echo off | current.exe
pause


Quote
ECHO OFF
COLOR 9F
CLS
current.exe
pause



Quote
ECHO OFF
COLOR 9F
CLS
type my.txt | current.exe
pause

strange but buffer size not 4096 but 4176

redskull

Use GetFileType() on the handle returned by GetStdHandle() to determine if it's a standard console or a pipe from another program. 

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

bomz

I think how to determine needed memorysize for clipboard.
allocate 10 mb and cut if need, or resize each 4176 byte

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

.data

.data?
StdIn      dd ?
Lenth      dd ?
hMemory      dd ?
pMemory      dd ?
BytesRead   dd ?

.code
start:
   invoke GetStdHandle, STD_INPUT_HANDLE
   .IF eax!=INVALID_HANDLE_VALUE
   mov StdIn, eax
   invoke GetFileSize,eax,addr Lenth
   .IF eax!=-1

   invoke GlobalAlloc,LMEM_MOVEABLE,1048576
   mov  hMemory,eax
   invoke GlobalLock,hMemory
   mov pMemory,eax
Next:
   invoke ReadFile, StdIn, pMemory, 4096, addr BytesRead, NULL
   mov eax, BytesRead
   add pMemory, eax
   add Lenth, eax
   cmp BytesRead, 0
   jne Next

   invoke GlobalUnlock,hMemory
   inc Lenth
   invoke GlobalReAlloc,hMemory,Lenth,GMEM_MOVEABLE
   mov  hMemory,eax
   invoke OpenClipboard,NULL
   invoke EmptyClipboard
   invoke SetClipboardData,CF_TEXT,hMemory
   invoke CloseClipboard
   invoke GlobalFree,hMemory

   .ENDIF
   .ENDIF
   invoke ExitProcess,0
end start

Yuri

GlobalFree is not needed here.

Quote from: SetClipboardData
If SetClipboardData succeeds, the system owns the object identified by the hMem parameter. The application may not write to or free the data once ownership has been transferred to the system

bomz

ok

strange but I can't Reallock memory to biggersize, only cut it.

Yuri

If you mean that the pointer changes, then it's normal. The next addresses are probably already allocated for other needs, so your block can't be extended in place.
As far as I know, you can reserve a large range of addresses through VirtualAlloc, then they won't be taken away and you will be able to commit more memory if needed to extend the initial block. Read about 'Virtual Memory Functions' on MSDN.
Quote
Reserving pages prevents needless consumption of physical storage, while enabling a process to reserve a range of its address space into which a dynamic data structure can grow. The process can allocate physical storage for this space, as needed.

This sounds promising, though I never used this technique myself.

bomz

GlobalReAlloc  - hear any words about resizing to bigger size.
Thanks

Yuri

Quote from: GlobalReAlloc
If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Call GetLastError and see what the error is.