News:

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

type conversion

Started by loki_dre, April 17, 2008, 06:03:19 AM

Previous topic - Next topic

loki_dre

how do I do type conversion???
eg. C code from MSDN website:

  HBITMAP hbm;
      hbm = (HBITMAP) GetClipboardData(CF_BITMAP);


u

Please use a smaller graphic in your signature.

jj2007

hbm = (HBITMAP) GetClipboardData(CF_BITMAP);

include \masm32\include\masm32rt.inc

.data
AppName db "Bitmap test", 0

.code

start:
call TestWin
invoke ExitProcess, 0

TestWin proc
LOCAL hBm:HBITMAP
  invoke OpenClipboard, 0
  .if eax
invoke IsClipboardFormatAvailable, CF_BITMAP
.if eax
invoke GetClipboardData, CF_BITMAP
mov hBm, eax
invoke MessageBox, 0, str$(eax), addr AppName, MB_OK
.else
invoke MessageBox, 0, chr$("No picture on clipboard"), addr AppName, MB_OK
.endif
invoke CloseClipboard
  .endif
  ret
TestWin endp
end start

loki_dre

looks like it is always failing
returns 0 for getclipboarddata.....

hutch--

loki,

make sure there is a bitmap copied to the clipboard, do it with paintbrush (MSPAINT) to make sure its there.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

loki_dre

invoke OpenClipboard, 0             <----------was my problem
invoke OpenClipboard, hwnd       <----------had it as that


any idea how to save this data as a bmp file to a memory location?
http://msdn2.microsoft.com/en-us/library/ms649016(VS.85).aspx         <-----seems to help
so far my code is:
LOCAL hwnd:HWND
LOCAL ps:PAINTSTRUCT
LOCAL hdc:HDC
LOCAL hdcMem:HDC
LOCAL hbm:HBITMAP      ;HBITMAP
LOCAL rc:RECT

invoke BeginPaint, hwnd, addr ps
;mov hdc,eax

invoke CreateCompatibleDC,hdc
mov hdcMem,eax
;COPY FROM CLIPBOARD
invoke OpenClipboard, 0

invoke GetClipboardData, CF_BITMAP    ;, CF_OWNERDISPLAY          ;CF_TEXT, CF_BITMAP
mov hbm,eax
invoke MessageBox, 0, str$(eax), addr AppName, MB_OK

invoke SelectObject,hdcMem, hbm
;invoke GetClientRect,hwnd,addr rc
;invoke BitBlt,hdc, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, SRCCOPY
invoke BitBlt,pMemory, 0, 0, 1280, 800, hdcMem, 0, 0, SRCCOPY

invoke CloseClipboard
invoke DeleteDC,hdcMem

loki_dre


evlncrn8

Quote from: Ultrano on April 17, 2008, 06:14:54 AM
Everything's a DWORD

unless you're in x64, or you're checking bytes /words of course :)

jj2007

Quote from: loki_dre on April 17, 2008, 11:50:58 AM
pMemory is the output

Not quite clear what you mean here. Where is pMemory defined? BitBlt needs a DC as destination, while you work with BeginPaint. The latter is ok as response to a WM_PAINT message, but that's not what you are doing here. Have a look at the GetDC/ReleaseDC pair.

loki_dre

if everything is a DWORD............how would I translate the following code?

BITMAPFILEHEADER fileHeader;
fileHeader.bfType      = 0x4d42;
fileHeader.bfSize      = 0;

u

 :bg

....
Well ok, there are also bytes, shorts, real8/qwords, real10, and structures and arrays of those.
But what I meant was "handles to Win32 objects are dwords". But also you'll notice it's extremely rare for a procedure-parameter to be non-dword. And the majority of variables on the stack of procs in your future code will be dwords.


local fileHeader: BITMAPFILEHEADER

mov fileHeader.bfType, 04d42h
mov fileHeader.bfSize , 0

Just look at the Win32 .h headers for the typedef definition of any strange/new "type" (of data) you stumble upon.
Please use a smaller graphic in your signature.

loki_dre

how would I translate the following code??

BITMAPINFO info;
BITMAPINFOHEADER infoHeader;
info.bmiHeader = infoHeader;

so far I have:
LOCAL infoHeader:BITMAPINFOHEADER
LOCAL info:BITMAPINFO
?!?!?!??!?!?!??!!??!    <----------------what comes next?


NightWare

BITMAPINFO is a structure containing BITMAPINFOHEADER+RGBQUAD DUP structures, so you don't have to define both... you can perfectly decompose it like :

Info_Bitmap   BITMAPINFOHEADER <?>   ;; ) bmiHeader (BITMAPINFOHEADER)
Info_Bitmap_Colors   RGBQUAD 256 dup (<?>)   ;; ) + bmiColors (RGBQUAD) (4 bytes A,R,V,B) * 256

loki_dre

how can i create a pointer to a byte????
ie.

BYTE* memory = 0;

jj2007

Quote from: loki_dre on April 18, 2008, 03:19:21 AM
how can i create a pointer to a byte????
ie.

BYTE* memory = 0;


It's a DWORD ;-)
Variant A:

xx proc
LOCAL MyByte:BYTE
LOCAL MyPtr:DWORD

lea eax, MyByte
mov MyPtr, eax
; attention, both values are being recreated every time you call the procedure



Variant B:


.data?
MyPtr    dd
.data
MyByte  db 255

xx proc
; LOCAL MyPtr:DWORD works, too, and may be shorter and faster, but once you leave the procedure,
the value is gone
; lea eax, MyByte works, too, but it's longer
mov eax, offser MyByte
mov MyPtr, eax