This is the relevant portion in MASM. It does not work and i have tried a few variations but have not succeeded:
.ELSEIF uMsg==WM_GETMINMAXINFO
mov [lParam + 24],300 ; beginning of ptMinTrackSize
mov [lParam + 28],300 ;
mov eax, NULL
ret
the code above crashes. If i do lParam +12 and +16 it does not crash but that was just done as a test bc it is not the variable i need.
This does work to desired effect in VC:
case WM_GETMINMAXINFO:
((MINMAXINFO*)lparam)->ptMinTrackSize.x=300;
((MINMAXINFO*)lparam)->ptMinTrackSize.y=300;
return 0;
MSDN defines MINMAXINFO structure as:
typedef struct {
POINT ptReserved;
POINT ptMaxSize;
POINT ptMaxPosition;
POINT ptMinTrackSize;
POINT ptMaxTrackSize;
} MINMAXINFO;
MSDN defines POINT as:
typedef struct tagPOINT {
LONG x;
LONG y;
}POINT, *PPOINT;
lParam+24 is probably not the beggining of ptMinTrackSize
lParam is a pointer to a structure, so the line "[lParam + 24]" is "the value pointed to by the value in the memory address located 24 bytes above lParam", which is certainly not valid. Try:
mov eax, lParam ;move the value stored in lParam into eax (the address of ptMinTrackSize)
mov eax, [eax+24] ;move the value stored 24 bytes above the address of ptMinTrackSize into eax
-r
when you try this
mov [lParam + 24],300
which is the same as this
mov lParam[24],300
the assembler does not know whether lParam[24] is a word or a dword
i think points are dwords, so
mov dword ptr lParam[24],300
WM_MINMAXINFO is defined in windows.inc as
WM_GETMINMAXINFO equ 24h
someplace, you have to declare a structure
MyMinMaxInfo MINMAXINFO <>
if you look in masm32\windows.inc
MINMAXINFO STRUCT
ptReserved POINT <>
ptMaxSize POINT <>
ptMaxPosition POINT <>
ptMinTrackSize POINT <>
ptMaxTrackSize POINT <>
MINMAXINFO ENDS
i think what you want is
.DATA?
MyMinMaxInfo MINMAXINFO <>
.CODE
.
.
.
mov dword ptr MyMinMaxInfo.ptMinTrackSize.x,300
mov dword ptr MyMinMaxInfo.ptMinTrackSize.y,300
now, the assembler knows the size (maybe - lol), so the "dword ptr" may not be required
mov MyMinMaxInfo.ptMinTrackSize.x,300
mov MyMinMaxInfo.ptMinTrackSize.y,300
Doesn't this code tell C that lparam contains a pointer?
((MINMAXINFO*)lparam)->ptMinTrackSize.x=300;
Whereas your code is the following
((MINMAXINFO)lparam)->ptMinTrackSize.x=300;
I don't know C but isn't the * a de-reference or something? I am curious...
redskull has it right
mov eax, lParam ;move the value stored in lParam into eax (the address of ptMinTrackSize)
i figured it out:
.ELSEIF uMsg==WM_GETMINMAXINFO
mov ecx, lParam;
mov eax,300;
mov [ecx+24], eax
mov [ecx+28], eax
works correctly!!! thanks for all the points(lol) in the right direction. i have to say pointers in MASM are fairly confusing. I guess you can move based on a register but not a memory location? idk the assembler gets mad at :
mov [lParam+24], 300
and even
mov [ecx+24], 300
apparently it has to be register to memory location based on register
Quote from: sinsi on January 21, 2010, 03:58:07 AM
Doesn't this code tell C that lparam contains a pointer?
((MINMAXINFO*)lparam)->ptMinTrackSize.x=300;
Whereas your code is the following
((MINMAXINFO)lparam)->ptMinTrackSize.x=300;
I don't know C but isn't the * a de-reference or something? I am curious...
my code is the top portion. not sure what you are saying.
* is inside the () above. what i am doing is saying cast lparam into a pointer to a MINMAXINFO structure.
* can be a dereference pointer as well. it actualy has many uses. the code above can also be written as:
(*((MINMAXINFO*)lparam)).ptMinTrackSize.x=300;
in this example the first * is a derefernce operator so you can use . instead of the pointer form ->
it can also be written C++ only format of :
reinterpret_cast<MINMAXINFO*>(lparam)->ptMinTrackSize.x=300;
or using dereference
(*reinterpret_cast<MINMAXINFO*>(lparam)).ptMinTrackSize.x=300;
I do not think that Sinsi was really expecting an answer in C/C++... instead he was using the questions as hints to point you in the right direction.
You are sending a pointer as a parameter in lparam and because of this you have to load it into a register because this CPU can not directly use a memory location to reference another memory location. C compiler will do that for you behind the scene but in ASM you must do it yourself.
As said above ... You could use something like this:
mov esi,[lparam] ; esi now points to MINMAXINFO
mov [esi + MINMAXINFO.ptMinTrackSize.x],300 ; access structure members by name and not by offsets
mov [esi + MINMAXINFO.ptMinTrackSize.y],300
THis does not look confusing when compared to the C alternative...
Quote from: BogdanOntanu on January 21, 2010, 07:44:17 AM
mov esi,[lparam] ; esi now points to MINMAXINFO
mov [esi + MINMAXINFO.ptMinTrackSize.x],300 ; access structure members by name and not by offsets
mov [esi + MINMAXINFO.ptMinTrackSize.y],300
if you like C syntax you can write:
mov [esi.MINMAXINFO.ptMinTrackSize.x],300
mov [esi.MINMAXINFO.ptMinTrackSize.y],300
OR
mov [esi].MINMAXINFO.ptMinTrackSize.x,300
mov [esi].MINMAXINFO.ptMinTrackSize.y,300
Reading back his post makes more sense. he was pointing out what my ASM code looks like. and his post is what helped me figure it out even though i did not understand him. :) and both of your responses make the code more readable. Once again sorry for such a basic question. i found the goASM website that answeres alot of these questions in the code provided there (http://www.jorgon.freeserve.co.uk/)