News:

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

WNDCLASSEX wc

Started by konan, October 20, 2009, 06:33:39 PM

Previous topic - Next topic

konan

I have a little bit stupid question.
In assembler:
LOCAL wc : WNDCLASSEX;  //here is reserving the memory for wc (something like object)
mov   wc.cbSize,SIZEOF WNDCLASSEX ; // here is size in bytes goes to cbSize of object wc.

In C++:
WNDCLASSEX wc;
wc.cbSize = sizeof(wc); //parametric function;

in Java (for example):
WNDCLASSEX wc=new WNDCLASSEX();
wc.cbSize = sizeof(wc); // parametric method;

How is possible, that parameter wc is given to same named object - wc ?  Where i'm wrong?

Astro

Hi,

Let's break this down. I hope this is correct...

LOCAL wc : WNDCLASSEX

This assigns 4 bytes of memory for the local function wc. If you look in windows.h (I think) WNDCLASSEX is defined as:

typedef WNDCLASSEX dword;

so:

LOCAL wc : DWORD would also be correct.

mov   wc.cbSize,SIZEOF WNDCLASSEX
First, sizeof looks at the size of WNDCLASSEX (obviously). As it is defined as a straightforward DWORD in the header, and a dword is 4 bytes, it knows to write 0x4 into wc.cbSize.

In your C++ code:
WNDCLASSEX wc;
wc.cbSize = sizeof(wc); //parametric function;

This is a similar thing, except it is looking at the size of wc, which it gets from its declaration where you told it is type WNDCLASSEX. As before, this works back to a DWORD value, and thus, 4 bytes.

Best regards,
Astro.

hutch--

Konan,

The WNDCLASSEX is a structure that holds a set of variable necessary to initialise a Window class for the following CreateWindowEx() functiion. The "WC" is just the address of the structure that is usually created on the stack and you use normal methods of setting those values before you register the class with the API. Its a reasonably comon technique in Windows that they picked up from the VAX guys who designed 32 bit Windows. Instead of a function that has some massive number of arguments in it like a few of the older API functions, the values are written to the structure members first THEN the function that uses them just has the address of the structure passed to it.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

konan

Quote from: Astro on October 20, 2009, 11:58:51 PM

First, sizeof looks at the size of WNDCLASSEX (obviously). As it is defined as a straightforward DWORD in the header, and a dword is 4 bytes, it knows to write 0x4 into wc.cbSize.

In your C++ code:
WNDCLASSEX wc;
wc.cbSize = sizeof(wc); //parametric function;

This is a similar thing, except it is looking at the size of wc, which it gets from its declaration where you told it is type WNDCLASSEX. As before, this works back to a DWORD value, and thus, 4 bytes.

Best regards,
Astro.
It's more clear now.

konan

Quote from: hutch-- on October 21, 2009, 12:07:58 AM
Konan,

The WNDCLASSEX is a structure that holds a set of variable necessary to initialise a Window class for the following CreateWindowEx() functiion. The "WC" is just the address of the structure that is usually created on the stack and you use normal methods of setting those values before you register the class with the API. Its a reasonably comon technique in Windows that they picked up from the VAX guys who designed 32 bit Windows. Instead of a function that has some massive number of arguments in it like a few of the older API functions, the values are written to the structure members first THEN the function that uses them just has the address of the structure passed to it.
After tens times readings of last sentances i think, that i started to understand - i.e. the sizeof operator reading the datas according to pointer wc, and gives this values to function with adress wc. At least looks for me like that. Thanks Hutch.

hutch--

Konan,

Its a reversed logic to older styles of programming.


LOCAL wc :WNDCLASSEX    ; allocate the structure in the stack in the proc.

; load the structure members with the values you want.

mov wc.member, value
    or
push mem_operand    ; or use the MACRO "m2m"
pop wc.member
etc ....

invoke RegisterClassEx,ADDR wc

; check the return value in EAX during debugging to see if it worked.


Its a very common style of programming in Windows API code. The old VAX fellas are responsible for the design.

Microsoft commonly use the trick of requiring the byte count (length) of the structure to see if it is a different version of the structure. If the reference material requires the length, always put it in so the API function reads the correct information.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php