why is bitblt throwing an exception

0

Im trying to create a program to output a picture to the screen, but when i do visual studio masm throws the exception Exception thrown at 0x00007FFEA0F15ADE (gdi32.dll) in assemblydraw.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF. and i dont know why this is happening or how to fix it.

Main code block

includelib user32.lib
include externals.asm
.data
include variables.asm
include pic.asm
.code
start proc
    mov holder, rsp
    and rsp, -16
    sub rsp, 32
    xor rcx, rcx
getdcfail:
    call __imp_GetDC
    cmp rax, 0
    je getdcfail
    mov screendc, rax
    mov rbx, 2000000000
    mov rcx, screendc
    lea rdx, bitmapinfo
    mov r8, 4; cbm_init
    lea r9, pic1colorbytes
    push rdx
    push 0
    call __imp_createdibitmap
    mov picdc, rax 
drawscreen:
    mov rcx, screendc
    mov rdx, 0
    mov r8, 0
    mov r9, 50
    push 50
    push picdc
    push 0
    push 0
    push 0cc0020h; srccopy is hex cc0020
    call __imp_bitblt
    dec rbx
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    nop
    cmp rbx, 0
    jne drawscreen
releasedcfail:
    mov rdx, screendc
    xor rcx, rcx
    call __imp_ReleaseDC
    cmp rax, 0
    je releasedcfail
    mov rcx, picdc
    call __imp_DeleteObject
    xor rcx, rcx
    call __imp_ExitProcess
    mov rsp, holder
    ret
start endp
end

Externals.asm

extrn __imp_GetDC:qword
extrn __imp_ReleaseDC:qword
extrn __imp_GetDesktopWindow:qword
extern __imp_ExitProcess:QWORD
extern __imp_SetDIBitsToDevice:qword
extern __imp_BitBlt:qword
extern __imp_CreateDIBitmap:qword
extern __imp_DeleteObject:qword

First part of pic.asm, a dib created by photoshop, and translated to hex codes to be put in my program

align qword
pic1:
byte 042H
byte 04DH
byte 048H
byte 027H
byte 000H
byte 000H
byte 000H
byte 000H
byte 000H
byte 000H
byte 036H
byte 000H
byte 000H
byte 000H
bitmapinfo:
byte 028H
byte 000H
byte 000H
byte 000H
byte 032H
byte 000H
byte 000H
byte 000H
byte 032H
byte 000H
byte 000H
byte 000H
byte 001H
byte 000H
byte 020H
byte 000H
byte 000H
byte 000H
byte 000H
byte 000H
byte 012H
byte 027H
byte 000H
byte 000H
byte 023H
byte 02EH
byte 000H
byte 000H
byte 023H
byte 02EH
byte 000H
byte 000H
byte 000H
byte 000H
byte 000H
byte 000H
byte 000H
byte 000H
byte 000H
byte 000H
pic1colorbytes:
byte 0FFH
byte 0FFH
byte 0FFH
byte 000H
byte 0FFH
byte 0FFH
byte 0FFH
byte 000H
byte 0FFH
byte 0FFH
byte 0FFH
winapi
assembly
x86
x86-64
masm
asked on Stack Overflow Nov 25, 2019 by Nathaniel Smith • edited Nov 25, 2019 by Nathaniel Smith

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0