how do I do type conversion???
eg. C code from MSDN website:
HBITMAP hbm;
hbm = (HBITMAP) GetClipboardData(CF_BITMAP);
Everything's a DWORD
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
looks like it is always failing
returns 0 for getclipboarddata.....
loki,
make sure there is a bitmap copied to the clipboard, do it with paintbrush (MSPAINT) to make sure its there.
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
pMemory is the output
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 :)
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.
if everything is a DWORD............how would I translate the following code?
BITMAPFILEHEADER fileHeader;
fileHeader.bfType = 0x4d42;
fileHeader.bfSize = 0;
: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.
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?
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
how can i create a pointer to a byte????
ie.
BYTE* memory = 0;
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
is it possible to link a byte pointer:
BYTE* memory = 0;
to a memory allocated using the following method:
---------------------------------------
.data?
hMemory HANDLE ?
pMemory DWORD ?
.code
;ALLOCATE AND LOCK OUR MEMORY
invoke GlobalAlloc, GMEM_MOVEABLE or GMEM_ZEROINIT, MEMORYSIZE
mov hMemory, eax
invoke GlobalLock, hMemory
mov pMemory, eax
-----------------------------------------
and do it without using MemCopy function or a similar method
No
If you allocate memory the pointer returned is to that block of memory and in the case you gave it was zeroed so every byte will be zero. To put something else in that memory you will have to copy it over.
You can think of your memory as a note book. Each page of the note book is numbered at the bottom, when you write into the note book you can do it in either pencil or pen, pencil is read/write and pen is read only. When you no longer need the information you have written to a page you draw a line through it. When you ask Windows to allocate more memory it will search for a blank page or a page with a line drawn through it. Windows will return the page number it finds, if you need the information from another page copied to it you will have to do the copying yourself.
I think you are trying to apply C rules to ASM and you cannot do that, C performs a lot of the grunt work for you in the background like filling local variables and copying blocks of data. You will find that in ASM none of this is done for you, you're the grunt and you have to do all of these tasks explicitly.
Edgar
how can I see how a function like MemCopy works.....my intention is to duplicated it & add some processing routines to the data so that I can minimize the time of my program.
Goal:
copy & process data from a BYTE* to memory allocated.
nevermind, found it:
MemCopy proc public uses esi edi Source:PTR BYTE,Dest:PTR BYTE,ln:DWORD
; ---------------------------------------------------------
; Copy ln bytes of memory from Source buffer to Dest buffer
; ~~ ~~~~~~ ~~~~
; USAGE:
; invoke MemCopy,ADDR Source,ADDR Dest,4096
;
; NOTE: Dest buffer must be at least as large as the source
; buffer otherwise a page fault will be generated.
; ---------------------------------------------------------
cld
mov esi, [Source]
mov edi, [Dest]
mov ecx, [ln]
shr ecx, 2
rep movsd
mov ecx, [ln]
and ecx, 3
rep movsb
ret
MemCopy endp
how can I implement the AND function or NOT function for a constant?
I tried:
IMAGE_SIZE_COL_BYTES EQU (((24*1280 + 31) AND (NOT 31))/8)
it doesn't seem to work correctly for me
What value should be returned ?? If you're looking for 3840 then it works if not you have to explain what isn't working and why not otherwise there's no way to help you.
Donkey
It seems like BEDMAS was not correctly applied by the compiler:
24*1280 + 31
was interpreted as
24*(1280 + 31)
I changed it to:
(24*1280) + 31
and got the correct result
Quote
24*1280 + 31
was interpreted as
24*(1280 + 31)
What assembler are you using? 24*(1280+31)=31464, but for 24*1280+31 MASM and GoAsm should return 30751.
MASM32 V9.00
try the whole thing....maybe it makes a difference
IMAGE_SIZE_COL_BYTES EQU (((24*1280 + 31) AND (NOT 31))/8)
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.data
.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
IMAGE_SIZE_COL_BYTES EQU (((24*1280 + 31) AND (NOT 31))/8)
print ustr$(IMAGE_SIZE_COL_BYTES),13,10
inkey "Press any key to exit..."
exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start
3840