The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: DKOI on September 20, 2011, 03:59:42 PM

Title: WriteConsole - GetLastError = 8
Post by: DKOI on September 20, 2011, 03:59:42 PM
.686
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\macros\macros.asm
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\shlwapi.inc

includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\shlwapi.lib

.data
HEAP DD ?
TERM DD ?
message BYTE "215",10,13
by DWORD ?

.stack
DD 256 DUP(?)

.code
start:
fn GetProcessHeap
mov HEAP, EAX
fn HeapAlloc, HEAP, 0, 1
mov EBX, EAX
mov AL, 5
mov [EBX], AL
fn GetStdHandle, STD_OUTPUT_HANDLE
mov TERM, EAX
fn WriteConsole, TERM, ADDR message, [EBX], ADDR by, 0
fn HeapFree, HEAP, 0, EBX
fn Sleep, 1000
fn ExitProcess, 0
end start

I run it and text "215" doesn't appear, just command prompt are printed again. GetLastError after WriteConsole return 8 as error code, that's defined as ERROR_NOT_ENOUGH_MEMORY, but i don't actually know, what it mean. Can anybody give me answer, where error is? Sorry for bad english.
Title: Re: WriteConsole - GetLastError = 8
Post by: qWord on September 20, 2011, 04:42:54 PM
You are passing a DWORD, pointed by ebx, to WriteConsole, but only one byte is allocated and filled.
Title: Re: WriteConsole - GetLastError = 8
Post by: DKOI on September 20, 2011, 05:50:16 PM
Quote from: qWord on September 20, 2011, 04:42:54 PM
You are passing a DWORD, pointed by ebx, to WriteConsole, but only one byte is allocated and filled.
Oh, thanx, it works :)