News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Fifth tutorial of iczelion series

Started by Abdel Hamid, January 25, 2019, 08:11:28 AM

Previous topic - Next topic

Abdel Hamid

i don't want to post so many threads about iczelion tutorials ! this will be annoying
so after your permission Mr.Hutch , i would like to post my questions about his tutorials on this thread  :icon_redface:
you can edit or delete whatever you want this is just a suggestion  :icon_rolleyes:
so many questions are in my head right now !
Tutorial 7 : i guess his running too fast and missing some points that needs to be  clarified  :(  :(  :(

http://win32assembly.programminghorizon.com/tut7.html

first question :

POINT STRUCT
    x   dd ?
    y   dd ?
POINT ENDS

in Win32API help files

typedef struct tagPOINT { // pt 
    LONG x;
    LONG y;
} POINT;

clearly there is a difference between double word and long , long is 64bit in size , double word is 32bit
why there is such difference between difinitions ???
second question : is 'MouseClick' a constant ? i haven't found it in any place , it doesn't exist in help files nor MSDN , and when i try to replace it with another label for instance : "MC" i get this error :

error A2006: undefined symbol : MC

- third question :

wParam is 32bit in size , low word of wParam for "x" , high word of wParam for "y" !
for example : x = 1200 , y = 2400
wParam will be : 24001200
after moving its value to eax , and doing logical "and" we'll get :
eax will be = 00001200 <= 
same for y , but why we used shr eax,16 and not shr eax,8 ????

    .ELSEIF uMsg==WM_LBUTTONDOWN
        mov eax,lParam
        and eax,0FFFFh
        mov hitpoint.x,eax
        mov eax,lParam
        shr eax,16
        mov hitpoint.y,eax
        mov MouseClick,TRUE
        invoke InvalidateRect,hWnd,NULL,TRUE


please give me an answer am really really tired , i have read the tutorial more than 10 times  :icon_redface:  :(

TBRANSO1

[quote author=Abdel Hamid link=topic=7648.msg83441#msg83441 date=1548386865]
clearly there is a difference between double word and long , long is 64bit in size , double word is 32bit

All 32-bit code is 4 bytes, including long... all max type definitions of long in Windows 32-bit is 4 bytes. refer to here: https://docs.microsoft.com/en-us/windows/desktop/winprog/windows-data-types

Quote
second question : is 'MouseClick' a constant ? i haven't found it in any place , it doesn't exist in help files nor MSDN , and when i try to replace it with another label for instance : "MC" i get this error :


.data
ClassName db "SimpleWinClass",0
AppName  db "Our First Window",0
MouseClick db 0         ; 0=no click yet


If I follow the code, which I've done this tutorial recently.  When the left click is detected, it sends a signal to the WndPrc, which at the end sets the MouseClick to true.  The Mouseclick is defined by the author as a constant 0 or false.  This sets it to true. Then in that same block, the reference to the Rectangle (window) is destroyed, and sends a signal to the the main, which detects and sends a signal back to the WndPrc to redraw things in the WM_Paint part.  If you see that the .IF MouseClick is TRUE ? part, it does the textout section and the MouseClick gets set back to false again.

I am not sure where MC comes from though, unless that is your code?


Abdel Hamid

Quote from: TBRANSO1 on January 25, 2019, 02:59:36 PM
I am not sure where MC comes from though, unless that is your code?
pardon me , i haven't seen MouseClick at the top , i like to type the whole code to remember
just forget about "MC" , thanks for your cooperation you saved me  :bgrin:
now i only need to know why he used shr eax,16 ?
he said :

Because y-coordinate is the high word of lParam, we must put it in the low word of eax prior to storing it in hitpoint.y. We do this by shifting eax 16 bits to the right.

suppose wParam has the high word y = 3000 , when we move wParam to eax
eax = 30000000
now i need to move "y" to the low word of eax to get the result below :
eax = 00003000
i tried to simulate this in a debugger but the register will have the value zero after shift ? is it normal , or am doing something wrong  :redface:

hutch--

> clearly there is a difference between double word and long , long is 64bit in size , double word is 32bit

In 32 bit, LONG is a 32 bit data size. In assembler DWORD and LONG are no different, they fit the same 32 bit register or memory. The distinction between signed and unsigned does not exist in the data, only how you evaluate it with conditional jumps, the difference between JA versus JG.

TBRANSO1

You are at the same spot I was a month ago.  I came into this world of assembly about 2 months ago.  I came from using HLL languages like Ruby, Python, Java, the C's.  While I had an introduction to assembly in school, being that MASM32 is a Microsoft approach and I never did anything with the MS libraries except the C RT stuff, I mostly did Linux POSIX C stuff.

I started his tutorials but found that I had lots of learning to do.  I turned to ol' Mr. Softie's online MSDN library and the Internet for help.  Go here and get learned up on more of the basics of Windows:
https://docs.microsoft.com/en-us/windows/desktop/winmsg/windows
https://docs.microsoft.com/en-us/windows/desktop/learnwin32/learn-to-program-for-windows
https://docs.microsoft.com/en-us/windows/desktop/winmsg/windowing

I can't find it now, but somewhere in there it defines the upper wParam and lower lParam.  The upper 16-bits of the 32-bit message that the main app sends to the WndPrc is used for certain signals and the lower 16-bit part is used for most of the rest.  In order for the correct signal to be read, it must be either truncated to the lower params by converting it to a WORD size, or shifting to the right for the Upper part and converting it to WORD size.

I made a macro based on the LOWORD and HIWORD C++ macros, but then I read later that MASM has LOWWORD and HIGHWORD macro directives built in, study those too.  Either way, you could use a mask like 00000FFFFh for the lower and/or just use the shl operator to move the bits down and then use the mask... that's all those C++ macros do.

Abdel Hamid

@Hutch-- , thank you sir for the good information
@TBRANSO1 , thank you so much for the bunch of informations
i have no experience in HLL , is it okay to read what you mentioned ?

TBRANSO1

Quote from: Abdel Hamid on January 25, 2019, 03:54:09 PM
@Hutch-- , thank you sir for the good information
@TBRANSO1 , thank you so much for the bunch of informations
i have no experience in HLL , is it okay to read what you mentioned ?

As for the documentation, I have had to read it multiple times and in short bursts, this information is saturated and makes you jump to different links. Spend time with though, you'll get it.

As for reading code... I struggled to read Win32 Kernel code and still do, since it's got so much unique language and conventions.  Furthermore what confused me is the certain libraries refer to the same data type, like a DWORD or DWORD PTR differently.  It was hard at first, it's getting easier now.  Reading C is pretty easy as it's straight forward, but reading Ruby or Python with a lot of concepts like monkey-patching, metaprogramming, wrappers, method-missing techniques will pull your hair out... as you really don't know sometimes what the author or authors were thinking, where the code begins or ends, jumping around like a crazy chicken from one file to another... one function here on this file, then calls a reference to a another to another to another then mangles the methods with monkey-patching, and metaprogramming, different levels indirection, it's crazy.

You will do fine, you seem smart enough and motivated.