Author Topic: my program and an online program  (Read 205 times)

shankle

  • Member
  • ****
  • Posts: 748
my program and an online program
« on: August 14, 2017, 09:53:18 AM »
             
          8-13-2017

I want to call an online program(B) from my program(A) and pass
some data from the online program(B) to my program(A) repeatedly.

Been trying this for months and getting nowhere. Yes I know 3rd
party programs can capture the data and pass it to the clipboard
but this is way to slow for the process I need to do. As an example
Fastcapture does this very nice but it is way to slow.

What my program(A) needs to do is call the online program(B) and
capture a small rectangle from program(B) and pass that data back
to my program(A) many times.

Since other programs can capture data from an online program screen,
there must be a way to do it in GoAsm. Tried dozens of ways to do it
with bitblt but none work.
Thanks for any suggestions.
          

Yuri

  • Member
  • **
  • Posts: 148
Re: my program and an online program
« Reply #1 on: August 15, 2017, 11:19:06 PM »
Look at this function, for example. It takes the window handle, the (client area) coordinates, width and height of the rectangle and returns in EAX a pointer to a buffer containing in each DWORD the color of a pixel in BGR format: the low byte is for blue, the next for green, the third for red. The fourth byte is probably not guaranteed to always contain 0, so it's better to mask it somehow.

If the function fails, it sets the carry flag and returns an error code in EAX.

The buffer is allocated each time the function is called, which is not an optimal solution, of course.

Code: [Select]
captureRect: FRAME hWnd, x, y, w, h
             USES rbx,rdi,rsi
             LOCALS bih:BITMAPINFOHEADER, pBmp, err

    lea rdi,[bih]
    mov ecx,sizeof BITMAPINFOHEADER / 4
    xor eax,eax
    mov [err],rax
    rep stosd
    invoke GetDC, [hWnd]
    mov rsi,rax
    test rax,rax
    jnz >
        mov D[err],1
        jmp >>.error
    :
    invoke CreateCompatibleDC, rsi
    mov rdi,rax
    test rax,rax
    jnz >
        mov D[err],2
        jmp >>.error
    :
    invoke CreateCompatibleBitmap, rsi, [w], [h]
    mov rbx,rax
    test rax,rax
    jnz >
        mov D[err],3
        jmp >>.error
    :
    invoke SelectObject, rdi, rbx
    test rax,rax
    jnz >
        mov D[err],4
        jmp >>.error
    :
    invoke BitBlt, rdi, 0, 0, [w], [h], rsi, [x], [y], SRCCOPY
    test eax,eax
    jnz >
        mov D[err],5
        jmp >>.error
    :
    mov eax,[w]
    shl eax,2
    mul D[h]
    invoke GlobalAlloc, GMEM_ZEROINIT, rax
    mov [pBmp],rax
    mov D[bih.biSize],sizeof BITMAPINFOHEADER
    mov edx,[w]
    mov ecx,[h]
    neg ecx
    mov [bih.biWidth],edx
    mov [bih.biHeight],ecx
    neg ecx
    mov W[bih.biPlanes],1
    mov W[bih.biBitCount],32
    mov D[bih.biCompression],BI_RGB
    invoke GetDIBits, rdi, rbx, 0, ecx, [pBmp], addr bih, DIB_RGB_COLORS
    test eax,eax
    jnz >
        mov D[err],6
        jmp >>.error
    :
    invoke DeleteDC, rdi
    invoke DeleteObject, rbx
    invoke ReleaseDC, [hWnd], rsi
    mov rax,[pBmp]
    clc
.exit
    ret
.error
    cmp D[err],6
    jb >
        invoke GlobalFree, [pBmp]
    :
    cmp D[err],4
    jb >
        invoke DeleteObject, rbx
    :
    cmp D[err],3
    jb >
        invoke DeleteDC, rdi
    :
    cmp D[err],2
    jb >
        invoke ReleaseDC, [hWnd], rsi
    :
    mov eax,[err]
    stc
    jmp .exit

ENDF
« Last Edit: August 16, 2017, 02:39:16 PM by Yuri »

Yuri

  • Member
  • **
  • Posts: 148
Re: my program and an online program
« Reply #2 on: August 16, 2017, 02:43:27 PM »
Added another "neg ecx" to make the height positive again for GetDIBits. It seemed to work OK without that, though.

shankle

  • Member
  • ****
  • Posts: 748
Re: my program and an online program
« Reply #3 on: August 16, 2017, 08:42:28 PM »
Thank you Yuri for responding.
It is not exactly what I want to do but I will use it as a guide.

HSE

  • Member
  • ****
  • Posts: 522
  • <AMD>< 7-32>
Re: my program and an online program
« Reply #4 on: August 18, 2017, 12:03:44 AM »
It's what I was searching last week (what a coincidence!). There is very few examples of GetDIBits, and my translation to assembly was failing  8) (or those example were incorrect, or even win32 help is wrong).

Thank you Yuri!  :t


Yuri

  • Member
  • **
  • Posts: 148
Re: my program and an online program
« Reply #5 on: August 18, 2017, 01:43:55 AM »
You are welcome. :icon_cool: