Somebody can translate these code to ASM for me?

HDC getLandscapePrinterDC()
{
PRINTDLG pd;
LPDEVMODE dm;

memset(&pd, 0, sizeof (PRINTDLG));

pd.Flags = PD_RETURNDEFAULT;
if (!PrintDlg (&pd))
return NULL;
if (pd.hDevMode == NULL)
return NULL;
pd.Flags &= ~PD_RETURNDEFAULT;
dm = (LPDEVMODE) GlobalLock (pd.hDevMode);
if (dm == NULL)
return NULL;
dm.dmOrientation = DMORIENT_LANDSCAPE;
dm.Fields |= DM_ORIENTATION;
GlobalUnlock (pd.hDevmode);
pd.Flags |= PD_RETURNDC;
if (PrintDlg (&pd))
return NULL;
return pd.HDC
}


Thanks,

Guy
Posted on 2002-01-23 15:34:13 by Guy
I make it something like this... note that i have left out the 'memset', as i believe it is a macro and i am not sure exactly what it does, but i believe it to be unnecessary here.



getLandscapePrinterDC proc USES ESI EDI EBX EBP

LOCAL pd :PRINTDLG
LOCAL dm :PDEVMODE ;this equates to a DWORD

mov esi, ADDR pd
assume esi : ptr PRINTDLG


mov eax, PD_RETURNDEFAULT
mov [esi].Flags, eax


invoke PrintDlg, esi
.IF !eax
ret ;eax already holds NULL if we are here
.ENDIF

.IF [esi].hDevMode == NULL
mov eax, NULL
ret
.ENDIF

mov eax, PD_RETURNDEFAULT
xor [esi].Flags, eax

invoke GlobalLock, [esi].hDevMode
.IF !eax
ret
.ENDIF
mov dm, eax

mov edi, dm
assume edi : ptr DEVMODE
mov [edi].dmOrientation, DMORIENT_LANDSCAPE

or [edi].Fields, DM_ORIENTATION

invoke GlobalUnlock. [esi].hDevMode

or [esi].Flags, PD_RETURNDC

invoke PrintDlg, esi
.IF eax
mov eax, NULL
ret
.ENDIF

mov eax, [esi].HDC
assume esi : nothing
assume edi : nothing
ret
getLandscapePrinterDC endp
Posted on 2002-01-23 15:57:14 by sluggy
memset is an ANSI C function to fill a buffer with a value... here 0... in this case, it is the same as RtlZeroMemory...
Posted on 2002-01-23 16:00:35 by JCP
sluggy,

MASM cause an error at: mov esi, ADDR pd
It says syntax error: ADDR

I have change it to - mov esi, dword ptr pd - in order to compile ok, but this time the program crash just after this line: mov .Flags, eax

Any reason why?


Guy
Posted on 2002-01-23 19:01:13 by Guy
test mov esi, pd
Posted on 2002-01-23 19:04:30 by CodeLover
- mov esi,pd - MASM send error: intruction operands must be the same size


Guy
Posted on 2002-01-23 19:30:37 by Guy
try "mov esi, offset pd" or "lea esi, "
Posted on 2002-01-23 20:17:13 by f0dder
Umm, yeah, i didn't test any of the code i posted above, but it should be pretty close :)
Posted on 2002-01-23 21:33:39 by sluggy
Of course. It is Guy task to read your code carefully and interpret it. Then write his own code, fresh of your code and helped with the Win32.hlp when it comes to the use of the structures.

In a few words, sluggy, your code is 100% crap. :tongue:
Posted on 2002-01-23 21:42:15 by CodeLover
In a few words, sluggy, your code is 100% crap. :tongue:

Welcome to my fan club, send me your address and i'll send you an autograph :alright:
Posted on 2002-01-24 03:13:45 by sluggy
hmmm,

Try and keep it friendly folks, posting an idea from the top of your head is something we all do from time to time and I am sure that it is seen as such.

Guy,

You ONLY use ADDR with the INVOKE syntax, OFFSET is the syntax for other uses of an address of a variable. NOTE that depending on how you load a variable, you sometimes need to use LEA to get that value into a memory operand.

Regards,

hutch@movsd.com
Posted on 2002-01-24 04:36:16 by hutch--
I think it was very gracious of sluggy to write about 40 lines of code just to help out a complete stranger. Asking for help with something puts you at the mercy of others for answers. That will always have its drawbacks(untested code) and rewards(a general understanding of the concept). It is disrespectful to insult someones good graces.
Posted on 2002-01-24 12:42:49 by rdaneel
Nah, i don't think CodeLover was rubbishing my code, i think he was just poking fun because there was one or two small mistakes in it.....
Whether he likes it or not, i took his comment in good humor :)
Posted on 2002-01-24 14:49:47 by sluggy
Of course rdaneel, sluggy is right. At least what i tried to do is to make sluggy laugh a bit. :grin:
Posted on 2002-01-24 14:59:41 by CodeLover
My bad. I'm clueless. I feel kinda dumb now. :rolleyes:

mov byte ptr , rdaneel
Posted on 2002-01-24 15:04:37 by rdaneel