News:

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

Passing struct pointer as parameter?

Started by houyunqing, October 23, 2008, 12:29:27 AM

Previous topic - Next topic

houyunqing

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

MichaelW

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.

eschew obfuscation

jj2007

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