Error 3e6 with WriteFile

It looks like you will get error 3E6 when you call write file with an address not aligned to DWORD.

;=====================================================================
; hello.asm – Example Assembler program
;
; Author: Sheng Jiang
; Course: COSC 2425
; Date: 5/23/05
;=====================================================================

.386
.MODEL flat, stdcall
option casemap:none

include windows.inc
include kernel32.inc
include masm32.inc

includelib kernel32.lib
includelib masm32.lib

.DATA
align 1
placeholder byte ?
Message BYTE  ‘Hello World!’,0
messegelen dword $-Message
errorcode dword 0
.CODE
Hello   PROC
int 3
sub esp,messegelen
mov ecx,messegelen
mov edi,esp
sub  esp , 8 ;//2 local var
invoke GetStdHandle, STD_OUTPUT_HANDLE
mov  [ebp-4] , eax ;
mov  eax  ,ebp
sub  eax  ,8
mov  [ebp-8] , eax;
copystringtostack:
dec edi
mov byte ptr [edi],’a’
loop copystringtostack
mov byte ptr [edi+12],0
invoke WriteFile, [ebp-4], edi, messegelen, near ptr [ebp-8],0
add esp,8
add esp,messegelen
invoke GetLastError
mov  errorcode,eax
invoke ExitProcess, 0
Hello   ENDP
END Hello

About Sheng Jiang 蒋晟

Microsoft MVP in Visual C , 2004- Forum moderator of the Visual C and .Net forums on CSDN Forum moderator of Chinese forums on Microsoft's MSDN forums
This entry was posted in ACC and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s