News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Access violation trying to call a win32 function

Started by vik, April 08, 2021, 08:04:36 AM

Previous topic - Next topic

vik

Hello I'm trying to run the program assembled from this code:

Quote.data

test_string byte "hello sailor", 0

.code

ExitProcess proto dwExitCode:dword
OutputDebugStringA proto lpOutputString:qword

main proc
    mov rax, -1
    mov rax, -2
    mov rax, -3
    mov rax, -4

    lea rcx, test_string
    call OutputDebugStringA

    mov rcx, 0
    call ExitProcess

main endp

end

but I get an access violation when I call OutputDebugStringA, any ideas why?

hutch--


vik

Could you point me where to learn about fixing it?

Vortex

Hello vik,

.data

test_string db 'Hello world!', 0

.code

EXTERN ExitProcess:PROC
EXTERN OutputDebugStringA:PROC

OutputDebugString TEXTEQU <OutputDebugStringA>

main PROC

    sub     rsp,4*8+8

    mov     rax,-1
    mov     rax,-2
    mov     rax,-3
    mov     rax,-4

    lea     rcx,test_string
    call    OutputDebugString

    xor     rcx,rcx
    call    ExitProcess

main ENDP

END


Moving to Windows Vista x64 :

https://www.codeproject.com/Articles/17263/Moving-to-Windows-Vista-x64

vik

Thank you. I ended up figuring out that I was missing shadow space.

What's the difference between declaring external functions with

label PROC

and

EXTERN label

Vortex

Label :

QuoteCreates a new label by assigning the current location-counter value and the given qualifiedType to name.

https://docs.microsoft.com/en-us/cpp/assembler/masm/label-masm?view=msvc-160

Extern :

QuoteDefines one or more external variables, labels, or symbols called name whose type is type.

https://docs.microsoft.com/en-us/cpp/assembler/masm/extern-masm?view=msvc-160