News:

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

pointer Q

Started by DC, January 26, 2006, 04:00:16 AM

Previous topic - Next topic

DC

is there a better way to translate this then this?
from:
if (pPDX->hDevMode != NULL)
    GlobalFree(pPDX->hDevMode);
to:
    lea     eax, pd.hDevMode
    mov     al, [eax]
    .if al != NULL
        invoke  GlobalFree, pd.hDevMode
    .endif
this isn't daja vu, I'm just learning it for the 37th time
http://www.bmath.net

zooba

.if(pd.hDevMode)
    invoke  GlobalFree, pd.hDevMode
.endif


Alternatively you can include '!= NULL' in the .if statement, but since NULL will (at least in a Windows environment) evaluate to 0, there's no need.

Mincho Georgiev

DC,
I dont know where you find this ,but mem free for a structure member ,especially GlobalFree is not a good idea (you can do it for the whole struct if it's dnamically allocated). You better put NULL in that member instead.
If it's a single varialbe struct member offcourse,not a another structure in it (or class member structure).

P1

Quote from: shaka_zulu on January 26, 2006, 03:56:32 PMI dont know where you find this ,but mem free for a structure member ,especially GlobalFree is not a good idea (you can do it for the whole struct if it's dnamically allocated). You better put NULL in that member instead.
He is converting M$ recommended code from C.

Most of the time, M$ does know what it's doing.  Most of the time, we may not be privileged to know.

A handle object is dword, so you need to fix this:
    mov     al, [eax]
    .if al != NULL

The low order byte can be zero, but the handle may not be NULL.

so that, the GlobalFree is actual releasing the complete handle object.

Regards,  P1  :8)

Mincho Georgiev

Yeah, more atention is never useless. hDevMode is a handle to dynamically allocated DEVMODE. Sorry, i didn't even read the var's name.

DC

thanx guys,
I was assuming that pd.hDevMode was a pointer to a string, and didn't know if they were testing the pointer or the member.
take care,
DC
this isn't daja vu, I'm just learning it for the 37th time
http://www.bmath.net

zooba

In Microsoft-world, handles always start with an 'h'. Pointers to strings usually involve 'p', 'lp' and 'sz', but there's not much in the way of conventions (well, perhaps there is, but I can't figure it out from looking at their names) :U

Tedd

Quote from: zooba on January 27, 2006, 01:27:36 AM
In Microsoft-world, handles always start with an 'h'. Pointers to strings usually involve 'p', 'lp' and 'sz', but there's not much in the way of conventions (well, perhaps there is, but I can't figure it out from looking at their names) :U

If you really want to get into it, then you should search for information about 'hungarian' notation. Personally I think they get a bit too hard to read when you have more than 2 or 3 letters prefixed.
I prefer to just stick with 'h' for handles, 'p' for pointers ('lp' means long-pointer, but all my pointers are longs (dwords) anyway) and occasionally 'sz' for string (zero terminated) pointer.
No snowflake in an avalanche feels responsible.

EduardoS

I'm not a C/C++ specialist, but i think the "->" operator works in this way:

mov eax, pPDX
mov eax, (struct ptr [eax]).hDevMode

u

Exactly, EduardoS!
So the whole code is

mov eax,pPDX
mov eax,[eax].DEVMODE.hDevMode
.if eax
invoke GlobalFree,eax
.endif

Please use a smaller graphic in your signature.