News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

problem with an api function

Started by ninjarider, August 11, 2005, 04:01:30 PM

Previous topic - Next topic

ninjarider

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

      .486                      ; create 32 bit code
      .model flat, stdcall      ; 32 bit memory model
      option casemap :none      ; case sensitive

;     include files
;     ~~~~~~~~~~~~~
      include \masm32\include\windows.inc
      include \masm32\include\masm32.inc
      include \masm32\include\gdi32.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc

      include \masm32\macros\macros.asm     ; the macro file

;     libraries
;     ~~~~~~~~~
      includelib \masm32\lib\masm32.lib
      includelib \masm32\lib\gdi32.lib
      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\kernel32.lib

     .data
        ScreenhDC dd 0
        ScreenW dd 0
        ScreenH dd 0
        CenterX dd 0
        CenterY dd 0

    .data?
        hInstance dd ?

    .code

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

start:

push SM_CXSCREEN
call GetSystemMetrics
shr eax, 2
mov ScreenW, eax

push SM_CYSCREEN
call GetSystemMetrics
shr eax, 2
mov ScreenH, eax

push 0
call GetDC
mov ScreenhDC,  eax

push SRC_INVERT
push 200
push ScreenW
push ScreenhDC
push 200
push 200
push 0
push 0
push ScreenhDC
call BitBlt
end start

im not sure why but i dont think im getting any values. im using bitblt to test to make sure that its working. i can use any immediate numbers in the bitblt call and it will work. if i use the variables it doesn't work.

the few times that it has worked xp ask me if i want to send an error message.
y does it do that

Mirno

What do the magic numbers mean?
You should use the defined values in Windows.inc, it makes the code readable. It's too much hassle to work out what the values you are actually pushing mean.

Mirno

joe

I don't understand, but if You trminate process, Windows didn't send error message.
Use:
invoke ExitProcess,NULL

Tedd

I've just tried that and it all works fine.. but possbily for two corrections
- add invoke ExitProcess, NULL at the end (as joe said), just to tell windows this is the end of the program
- what is the value of "SRC_INVERT"?? -- should it be "SRCINVERT"??

The error message means the program did something bad and caused an exception -- removing the call to exit process causes this every time i've tried it :bdg
No snowflake in an avalanche feels responsible.

ninjarider

ok yeah thanks. and yes SRC_INVERT is suppose to be SRCINVERT i guess from me being use to vb i typed it that way.
how do i go about recieving the windows system messages without having a window.

ninjarider

i added the following code to the program and it takes it so long to load

in the data section
Time SYSTEMTIME <>

in the code section
push Time
Call GetSystemTime

Tedd

I think you can do a standard message loop without a window - the thread should still receive messages in its queue; just make sure you set the window handle to NULL for the GetMessage function (since you don't have a window handle.)
I have no idea why GetSystemTime should take very long to execute, though it might help if you actually push OFFSET Time rather than the 'value' of Time :wink (For me it just crashes like that anyway.)

At this point I would suggest you try to use the invoke macro, which will actually pick up errors like that for you, as well as making the code easier to read.

    invoke GetSystemTime, OFFSET Time

    invoke GetSystemMetrics, SM_CXSCREEN
    shr eax, 2
    mov ScreenW, eax

    invoke GetSystemMetrics, SM_CYSCREEN
    shr eax, 2
    mov ScreenH, eax

    invoke GetDC, 0
    mov ScreenhDC,  eax

    invoke BitBlt, ScreenhDC,0,0,200,200,ScreenhDC,ScreenW,200,SRCINVERT

    invoke ExitProcess, NULL

No snowflake in an avalanche feels responsible.