flat assembler
Message board for the users of flat assembler.

Index > Windows > Local structures

Author
Thread Post new topic Reply to topic
denial



Joined: 12 Sep 2004
Posts: 98
denial
When I use the proc macro it isn't possible to declare a struct-variable as local Sad
Is there a workaround or am I doin' something wrong?

Here's the code.

Code:
proc _main
_myself PERSON
_tmp dd ?
enter
(...)
return
endp

.data
struct PERSON
.age dd ?
.name rb 30
ends
    


Thank you Smile
Post 15 Feb 2005, 13:59
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
You simply have to define the structure before the first line where you want to use it - and everything should be OK.

Regards.
Post 15 Feb 2005, 16:05
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
denial



Joined: 12 Sep 2004
Posts: 98
denial
Thank you, it worked.
However, I wrote the struct-definition into the code-section now. Is that allowed, or does it have to be in data-section? I prefer to have my data-section below the code, that's why I ask. Smile
Post 15 Feb 2005, 17:16
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
denial wrote:
However, I wrote the struct-definition into the code-section now. Is that allowed, or does it have to be in data-section?


As far as structure definitions doesn't define any real data, it doesn't matter where exactly they will stay. The only condition is to be before variables defined with this structure.

Regards.
Post 15 Feb 2005, 17:21
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
denial



Joined: 12 Sep 2004
Posts: 98
denial
Thank you - You've helped me with alot of problems since I'm here. I'm very glad about. Smile
Post 15 Feb 2005, 17:33
View user's profile Send private message Reply with quote
Spidark



Joined: 11 May 2005
Posts: 39
Spidark
Hello i have a different question about local Structures.
Lets say i'm don't want to use the proc macro and choose to do it the hard way .
EXAMPLE
Code:
hWnd   equ ebp+8
uMsg   equ ebp+12
wParam equ ebp+16
lParam equ ebp+20
WndProc:
        push    ebp
        mov     ebp,esp
        push    ebx esi edi    
        cmp     dword [uMsg],WM_PAINT
        je      ON_PAINT
        cmp     dword [uMsg],WM_DESTROY
        je      ON_DESTROY
        cmp     dword [uMsg],WM_NCHITTEST
        je      ON_NCHITTEST
        cmp     dword [uMsg],WM_CREATE
        je      ON_CREATE
DEFWINPROC:
etc etc etc.    

Let's say that in my ON_PAINT message i want to use a tempRECT RECT structure.
With the proc macro you can do somemthing like this
Code:
proc, 1stPar , 2stPar
temRect RECT
LOCALVAR    dd   ?
     enter
initl:
     mov [LOCALVAR],0
     mov [temRect.right],100
     etc etc
    

proc macro does it all for you i know.
How can you do the same the hard way ?? (Bug dangerous if you don't know what your doing way)
I mean how do you define e temRect structure as a LOCAL structure but with out using the proc macro.
Post 29 May 2005, 02:01
View user's profile Send private message Reply with quote
denial



Joined: 12 Sep 2004
Posts: 98
denial
I would be very interested into this, too. How to use local structures without proc-macro?
Post 01 Jun 2005, 11:31
View user's profile Send private message Reply with quote
Spidark



Joined: 11 May 2005
Posts: 39
Spidark
denial wrote:
I would be very interested into this, too. How to use local structures without proc-macro?

Well i kinda Figure out how it's done after poking around in my debugger and checking things out.
Your gonna have to create the whole structure in your procedure(maybe this could be done different with macros but i'm not sure, i'm not a whizzkid when it come to macros ) there could be an easier way to do this ( i hear them saying proc macro Laughing ).
ok to make this short here's the way that i did it, and i tell you it's make sense when you see it like this because you then know exactly what the hell is going on in the code behind the macro ( if your a newbie like me Laughing ).
Hope it helps.
Code:
;-----------------------------------------------------------------
; Program Name: localstruct.asm
; Version: 1.0
; Purpose:To learn how thing work without macros
; Author: Spidark (C) 2005
; Date: 1-06-2005
; Created using RadASM IDE with FASM
; This program was tested on Windows XP SP2 
; Credits: TO ALL ASSEMBLER MESSAGEBOARDS IN THE WORLD AND IN SPACE
;------------------------------------------------------------------

format PE GUI 4.0
entry start

include "%fasminc%\Win32a.inc"

section '.data' data readable writeable
        hwnd            dd   ?
        hInstance       dd   ?
        hdc             dd   ?
        Wtx             dd   ?
        Wty             dd   ?
        Wwd             dd   ?
        Wht             dd   ?

        wTitle          db   'Program:[ localstruct.asm ]Coded by Spidark 2005',0 ;name of our window
        wcName          db   '1111asm_Cla1111',0      ;name of our window cla1111
        msg             MSG
        wc              WNDCLASS
        errText         db      "Error Detected Program can not run on this machine!",0
        messCap         db      "Message",0
        expTxt          DB "USING LOCAL STRUCTURES WITH FASM THE HARDWAY",0

        
section '.code' code readable executable
        start:
                 
        invoke  GetModuleHandle,NULL
        mov     [hInstance],eax
        mov     [wc.hInstance],eax
        mov     [wc.style],CS_HREDRAW or CS_VREDRAW
        mov     [wc.lpfnWndProc],WndProc
        mov     [wc.lpszClassName],wcName
        mov     [wc.hbrBackground],COLOR_WINDOW+1
        invoke  LoadIcon,NULL,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke   LoadCursor,NULL,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClass,wc

        mov     [Wwd], 800
        mov     [Wht], 600 
        invoke  GetSystemMetrics,SM_CXSCREEN ; THIS ONE IS FROM THE FASM BOARD
        stdcall TopXY,[Wwd],eax
        mov     [Wtx], eax
        invoke  GetSystemMetrics,SM_CYSCREEN
        stdcall TopXY,[Wht],eax
        mov     [Wty], eax
        invoke    CreateWindowEx,\
                               0,\
                         wcName,\
                         wTitle,\
                         WS_OVERLAPPEDWINDOW ,\
                         [Wtx],\
                         [Wty],\
                         [Wwd],\
                         [Wht],\
                         NULL,\
                         NULL,\
                         [hInstance],\
                         NULL
        mov     [hwnd],eax
        invoke    ShowWindow,[hwnd],SW_SHOW
MSG_LOOP:
        invoke    GetMessage,msg,NULL,0,0
        or   eax,eax
        jz   END_LOOP
        invoke    TranslateMessage,msg
        invoke    DispatchMessage,msg
        jmp  MSG_LOOP
END_LOOP:
        invoke  MessageBoxEx,[hwnd],errText,messCap,MB_OK or MB_ICONSTOP 
        invoke  ExitProcess,0


hWnd   equ ebp+8
uMsg   equ ebp+12
wParam equ ebp+16
lParam equ ebp+20
;------------------------PAINTSTRUCT LOCAL---------------------------
;====================================================================
;ps_hdc                                 equ ebp-4               ;dd ?
;ps_fErase                              equ ebp-8               ;dd ?
;ps_rcPaint_rect_left                   equ ebp-12              ;dd ?
;ps_rcPaint_rect_top                    equ ebp-16              ;dd ?
;ps_rcPaint_rect_right                  equ ebp-20              ;dd ?
;ps_rcPaint_rect_bottom                 equ ebp-24              ;dd ?
;ps_fRestore                            equ ebp-28              ;dd ?
;ps_fIncUpdate                          equ ebp-32              ;dd ?
;ps_rgbReserved                         equ ebp-64              ;rb 32

;------------------------ LOCAL RECT STRUCTURE ------------------------
;======================================================================
;loc_rect_left                          equ ebp-68              ;dd ?
;loc_rect_top                           equ ebp-72              ;dd ?
;loc_rect_right                         equ ebp-76              ;dd ?
;loc_rect_bottom                        equ ebp-80              ;dd ?

;-------------------------LOCAL DEVICE HANDLE--------------------------
;======================================================================
;hdc                            equ     ebp-84                  ; dd ?


local_ps                        equ     ebp-64  
local_rect                      equ     ebp-80
local_hdc                       equ     ebp-84
WndProc:
        push    ebp 
        mov     ebp,esp
        sub     esp,84          ; make room for 84 bytes
        push    ebx esi edi    
        cmp     dword [uMsg],WM_PAINT
        je      ON_PAINT
        cmp     dword [uMsg],WM_DESTROY
        je      ON_DESTROY
        cmp     dword [uMsg],WM_NCHITTEST
        je      ON_NCHITTEST
DEFWINPROC:
        invoke    DefWindowProc,[hWnd],[uMsg],[wParam],[lParam]
        jmp  EXIT
        
ON_PAINT:
        lea      eax,[local_ps]         ; get the adress of local paintstruct
        push     eax                    ; save it in a reg
        invoke   BeginPaint,[hWnd],eax  ; call Api Guessing that Beginpaint Inits the locals
        mov      [local_hdc],eax                ; save the device
        lea      ebx,[local_rect]       ; get adress of local rect      
        push     ebx                    ; save local rect on the stack
        invoke   GetClientRect,[hWnd],ebx
        pop     ebx                     ; Maybe API destroys ebx ?? Not sure here so
        push    ebx                     ; restore it again for later
        invoke   DrawText,\             ; CALL API
                 [local_hdc],\
                 expTxt,\
                 -1,\
                 ebx,\                  ; Local Rect
                 DT_SINGLELINE or DT_CENTER or DT_VCENTER
        pop     ebx                             ; EBX must come first
        pop     eax                             ; holds local ps
        invoke   EndPaint,[hWnd],eax            ; Stop painting
        jmp  EXIT
        
ON_NCHITTEST:
        invoke DefWindowProc,[hWnd],[uMsg],[wParam],[lParam]
        cmp eax,1
        jnz @F
        inc eax
        @@:
        jmp EXIT
ON_DESTROY:
        invoke    PostQuitMessage,0

EXIT:
        pop  ebp
        add  esp,84
        pop  edi esi ebx
        ret  16
        
;--------------------------------------------------------------------;  
wDim    equ     ebp+8
sDim    equ     ebp+12
TopXY:
        push    ebp
        mov     ebp,esp
        shr     dword [sDim],1 ; divide screen dimension by 2
        shr     dword [wDim],1 ; divide window dimension by 2
        mov     eax,dword [wDim] ; copy window dimension into eax
        sub     dword [sDim],eax ; sub half win dimension from half screen dimension
        mov     eax,dword [sDim] ; in the masm example they have used "return sDim" so i have added this line to return sDim in eax
        pop     ebp
        ret     8   



section '.idata' import data readable writeable
        library KERNEL32, 'KERNEL32.DLL',\
                USER32,   'USER32.DLL'

        import  KERNEL32,\
               GetModuleHandle,         'GetModuleHandleA',\
               ExitProcess,             'ExitProcess'

        import USER32,\
               RegisterClass,           'RegisterClassA',\
               CreateWindowEx,          'CreateWindowExA',\
               DefWindowProc,           'DefWindowProcA',\
               ShowWindow,              'ShowWindow',\
               LoadCursor,              'LoadCursorA',\
               LoadIcon,                'LoadIconA',\
               GetMessage,              'GetMessageA',\
               TranslateMessage,        'TranslateMessage',\
               DispatchMessage,         'DispatchMessageA',\
               PostQuitMessage,         'PostQuitMessage',\
               MessageBoxEx,            'MessageBoxExA',\
               BeginPaint,              'BeginPaint',\
               GetClientRect,           'GetClientRect',\
               DrawText,                'DrawTextA',\
               EndPaint,                'EndPaint',\
               GetWindowRect,           'GetWindowRect',\
               GetDesktopWindow,        'GetDesktopWindow',\
               MoveWindow,              'MoveWindow',\
               GetWindow,               'GetWindow',\
               GetSystemMetrics,        'GetSystemMetrics'
               
section '.rsrc' resource from 'localstruct.res' data readable
         
    
Post 01 Jun 2005, 13:58
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.