NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: michael_chan on August 23, 2016, 08:08:30 AM
-
i try call WriteConsoleOutputA use NASM
but the error message always display
87 (0x57)
The parameter is incorrect.
i don't know how to solve this problem
STD_OUTPUT_HANDLE EQU -11
NULL EQU 0
GLOBAL GobleyGook
EXTERN ExitProcess, GetLastError, GetStdHandle, WriteConsoleA, WriteConsoleOutputA, FormatMessageA
SECTION .data
STRUC lpBuffer
.Char : RESW 1
.Attributes: RESD 1
ENDSTRUC
_lpBuffer ISTRUC lpBuffer
at lpBuffer.Char, DW 'A'
at lpBuffer.Attributes, DD 1H
IEND
STRUC dwBufferSize
.X: RESW 1
.Y: RESW 1
ENDSTRUC
_dwBufferSize ISTRUC dwBufferSize
at dwBufferSize.X, DW 10
at dwBufferSize.Y, DW 10
IEND
STRUC dwBufferCoord
.X: RESW 1
.Y: RESW 1
ENDSTRUC
_dwBufferCoord ISTRUC dwBufferCoord
at dwBufferCoord.X, DW 0
at dwBufferCoord.Y, DW 0
IEND
STRUC smallRect
.Left : RESW 1
.Top : RESW 1
.Right : RESW 1
.Bottom: RESW 1
ENDSTRUC
_smallRect ISTRUC smallRect
IEND
SECTION .bss
dummy RESD 1
err RESD 1
err2 RESD 1
SECTION .text
GobleyGook:
PUSH STD_OUTPUT_HANDLE
CALL GetStdHandle
PUSH _smallRect
PUSH _dwBufferCoord
PUSH _dwBufferSize
PUSH _lpBuffer
PUSH EAX
CALL WriteConsoleOutputA
CALL GetLastError
PUSH NULL
PUSH 99
PUSH err
PUSH NULL
PUSH EAX
PUSH NULL
PUSH 1000H
CALL FormatMessageA
PUSH STD_OUTPUT_HANDLE
CALL GetStdHandle
push NULL
push dummy
push 32
push err
push EAX
call WriteConsoleA
PUSH NULL
CALL ExitProcess
Link & compiler
nasm -f win32 print.asm
golink.exe /console /entry GobleyGook print.obj kernel32.dll
on the windows 8.1 64bit
The API document
https://msdn.microsoft.com/zh-tw/library/windows/desktop/ms687404(v=vs.85).aspx (https://msdn.microsoft.com/zh-tw/library/windows/desktop/ms687404(v=vs.85).aspx)
please help me....
-
hello
replace
PUSH _dwBufferCoord
PUSH _dwBufferSize
for
PUSH dword [_dwBufferCoord]
PUSH dword [_dwBufferSize]
ok ?
-
Well... "ok"? Does it work? You Windows users have gotta help each other! I can't do it!
Best,
Frank
-
durelin was correct.
compiles and links:
C:\>prnt
The parameter is incorrect.
-
Well it isn't clear to me which parameter is incorrect. I'm thinking that "smallrect.bottom" and "smallrect.right" should probably be nonzero. Say 10,10? But I dunno.
Best,
Frank
-
Hello
Try this code (he is OK under windows 10) :
STD_OUTPUT_HANDLE EQU -11
NULL EQU 0
GENERIC_READ equ 080000000h
GENERIC_WRITE equ 040000000h
FILE_SHARE_READ equ 1h
FILE_SHARE_WRITE equ 2h
CONSOLE_TEXTMODE_BUFFER equ 0x00000001
INVALID_HANDLE_VALUE equ -1
GLOBAL Main
EXTERN ExitProcess, GetLastError, GetStdHandle, WriteConsoleA, WriteConsoleOutputA, FormatMessageA
SECTION .data
STRUC lpBuffer
.Char : RESW 1
.Attributes: RESD 1
ENDSTRUC
_lpBuffer ISTRUC lpBuffer
at lpBuffer.Char, Dw 'A'
at lpBuffer.Attributes, DD 21H
IEND
_lpBuffer2 ISTRUC lpBuffer
at lpBuffer.Char, DW 'B'
at lpBuffer.Attributes, DD 21H
IEND
STRUC dwBufferSize
.X: RESW 1
.Y: RESW 1
ENDSTRUC
_dwBufferSize ISTRUC dwBufferSize
at dwBufferSize.X, DW 2
at dwBufferSize.Y, DW 20
IEND
STRUC dwBufferCoord
.X: RESW 1
.Y: RESW 1
ENDSTRUC
_dwBufferCoord ISTRUC dwBufferCoord
at dwBufferCoord.X, DW 0
at dwBufferCoord.Y, DW 0
IEND
STRUC smallRect
.Left : RESW 1
.Top : RESW 1
.Right : RESW 1
.Bottom: RESW 1
ENDSTRUC
_smallRect ISTRUC smallRect
at smallRect.Left, DW 1
at smallRect.Top, DW 1
at smallRect.Right, DW 1
at smallRect.Bottom, DW 1
IEND
SECTION .bss
hOutput resd 1
hScreen resd 1
dummy RESD 1
err RESD 1
err2 RESD 1
buffer resb 200
SECTION .text
Main:
PUSH STD_OUTPUT_HANDLE
CALL GetStdHandle
PUSH _smallRect
PUSH dword [_dwBufferCoord]
PUSH dword [_dwBufferSize]
PUSH _lpBuffer
PUSH eax
CALL WriteConsoleOutputA
CALL GetLastError
PUSH NULL
PUSH 99
PUSH err
PUSH NULL
PUSH EAX
PUSH NULL
PUSH 1000H
CALL FormatMessageA
PUSH STD_OUTPUT_HANDLE
CALL GetStdHandle
push NULL
push dummy
push 32
push err
push EAX
call WriteConsoleA
.fin:
PUSH NULL
CALL ExitProcess
-
compiling and running on Vista 32bit produces the following output:
C:\X-Asm\X_Template>prnrect2
The operation completed successf
C:\X-Asm\X_Template>
I somehow think this is not the output desired??
Changing the values for smallRect in the above example:
_smallRect ISTRUC smallRect
at smallRect.Left, DW 0
at smallRect.Top, DW 6
at smallRect.Right, DW 10
at smallRect.Bottom, DW 10
IEND
yields the following out put:
C:\X-Asm\X_Template>prnrect2
The operation completed successf
C:\X-Asm\X_Template>
A
!?
d
each of the symbols displayed has a different back ground, red,green and yellow. Not sure if this was the intended output? or just a coincidence?
Klod