The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: houyunqing on October 23, 2008, 12:29:27 AM

Title: Passing struct pointer as parameter?
Post by: houyunqing on October 23, 2008, 12:29:27 AM
The following is a procedure i wrote to set a WNDCLASSEX target to some default values i defined. the _wc is the address of the WNDCLASSEX struct
the question is, is there a better way to deal with this pointer instead of moving data to a register first and then do the mov [ebx+*], edx?
What's the normal way of operating on a pointer?
Thanks for any help :bg

   SetDefWndClassEx proc _wc:dword
      pusha
      mov      ebx, _wc
      mov      edx, sizeof WNDCLASSEX
      mov      [ebx], edx                     ;cbSize
      mov      edx, CS_HREDRAW or CS_VREDRAW
      mov      [ebx+4], edx                   ;style
      mov      edx, offset WndProc
      mov      [ebx+8], edx                   ;lpfnWndProc
      mov      edx, 0
      mov      [ebx+12], edx                  ;cbClsExtra
      ;mov      edx, 0
      mov      [ebx+16], edx                  ;cbWndExtra
      mov      edx, hInstance
      mov      [ebx+20], edx                  ;hInstance
      invoke   LoadIcon, 0, IDI_APPLICATION
      mov      [ebx+24], eax                  ;hIcon
      invoke   LoadCursor, 0, IDC_ARROW
      mov      [ebx+28], eax                  ;hCursor
      mov      edx, COLOR_WINDOW+1
      mov      [ebx+32], edx                   ;hbrBackground
      mov      edx, 0
      mov      [ebx+36], edx                  ;lpszMenuName
;      mov      _wc.lpszClassName,               ;lpszClassName
      mov      edx, [ebx+24]
      mov      [ebx+44], edx                  ;hIconSm
      popa
      ret
   SetDefWndClassEx endp
Title: Re: Passing struct pointer as parameter?
Post by: MichaelW on October 23, 2008, 02:09:10 AM
The constants CS_HREDRAW or CS_VREDRAW and COLOR_WINDOW+1 can be moved directly, and if you start by initializing the structure to all zeros (RtlZeroMemory, etc), you can eliminate the instructions that set individual members to zero.

Title: Re: Passing struct pointer as parameter?
Post by: jj2007 on October 23, 2008, 05:10:41 AM
You can use a more elegant notation:
LOCAL rc:RECT
lea edx, RECT  ; load the address of the rectangle structure
   mov eax, 123
   mov [edx.RECT.top], eax
   mov [edx.RECT.left], eax
etc