flat assembler
Message board for the users of flat assembler.

Index > Windows > locals

Author
Thread Post new topic Reply to topic
shadowomf



Joined: 31 Mar 2010
Posts: 12
Location: Germany
shadowomf
Hello,

I have a small problem with the locals macro, not the macro itself but I don't know how to make the following example work:
Code:
    proc WinMain hInst, hPrevInst, CmdLine, CmdShow
        
        locals
            windowClassName TCHAR 'OPENGL64DUMMY', 0
            windowClass WNDCLASSEX sizeof.WNDCLASSEX, 0, DummyWindowProc, 0, 0, 0, 0, 0, 0, 0, windowClassName, 0
            message MSG
        endl
        
        ; new window class for dummy window
        mov [windowClass.hInstance], rcx
        invoke LoadIcon, rax, 17
        mov [windowClass.hIcon], rax
        invoke LoadCursor, 0, IDC_ARROW
        mov [windowClass.hCursor], rax
        invoke RegisterClassEx, addr windowClass
    

The above code does not assemble and results in an fasm error (invalid value in the line
Quote:
windowClass WNDCLASSEX sizeof.WNDCLASSEX, 0, DummyWindowProc, 0, 0, 0, 0, 0, 0, 0, windowClassName, 0
).
When I use a global variable as windowClassName it does work without problems. However I would like to keep things seperated.

Is there any way to make it work?

And one more Question, I am using the "w" (Unicode) header version, is TCHAR the right way to do it or would a "du" be better?

Thanks in advance.
-Christoph
Post 19 Feb 2012, 17:27
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17472
Location: In your JS exploiting you and your system
revolution
The problem is you are trying to make the assembler do this:
Code:
mov [ebp+offset1],ebp+offset2    
You could try this:
Code:
windowClass WNDCLASSEX sizeof.WNDCLASSEX, 0, DummyWindowProc, 0, 0, 0, 0, 0, 0, 0, 'OPENGL64DUMMY', 0    
Post 19 Feb 2012, 20:33
View user's profile Send private message Visit poster's website Reply with quote
SFeLi



Joined: 03 Nov 2004
Posts: 140
SFeLi
shadowomf wrote:
windowClassName TCHAR 'OPENGL64DUMMY', 0

Do you really need this? Maybe:
Code:
proc foo ; Note that all local labels start with a dot.
    locals
        .pt     POINT
        .buffer rb 32
    endl

    .get:
        stdcall [GetCursorPos], addr .pt
        ccall   [wsprintf], addr .buffer, .fmt, [.pt.x], [.pt.y]
    .show:
        stdcall [MessageBox], 0, addr .buffer, .title, MB_ICONINFORMATION
  .exit: 
    ret 

  .fmt db 'Cursor at %u:%u',0
  .title db 'CursorPos',0
endp
; This way you can "keep things seperated" without initializing locals with the bunch of MOVs.    


Last edited by SFeLi on 19 Feb 2012, 21:52; edited 2 times in total
Post 19 Feb 2012, 21:39
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17472
Location: In your JS exploiting you and your system
revolution
SFeLi wrote:
every name/label in foo should start with a dot.
This is not a necessary condition. Labels inside locals can start with any non-numeric character. The macros use an equ to define the label and later it is released with restore.
Post 19 Feb 2012, 21:49
View user's profile Send private message Visit poster's website Reply with quote
SFeLi



Joined: 03 Nov 2004
Posts: 140
SFeLi
revolution, thank you for the correction. I don't use proc macros, but several years ago I had some problems with locals and I just remembered to use the dot for everything Smile
Post 19 Feb 2012, 21:55
View user's profile Send private message Reply with quote
shadowomf



Joined: 31 Mar 2010
Posts: 12
Location: Germany
shadowomf
Thank you for your fast reply.

Quote:

The problem is you are trying to make the assembler do this:

Code:
mov [ebp+offset1],ebp+offset2    


Maybe I'm a bit slow but why doesn't the following work? (I also tried it without brackets.)
Code:
        mov rax, [windowClassName]
        mov [windowClass.lpszClassName], rax
    


Quote:

You could try this:
Code:
windowClass WNDCLASSEX sizeof.WNDCLASSEX, 0, DummyWindowProc, 0, 0, 0, 0, 0, 0, 0, 'OPENGL64DUMMY', 0    


Sadly this doesn't work.


Quote:
Do you really need this? Maybe:
Code:
proc foo ; Note that all local labels start with a dot.
    locals
        .pt     POINT
        .buffer rb 32
    endl

    .get:
        stdcall [GetCursorPos], addr .pt
        ccall   [wsprintf], addr .buffer, .fmt, [.pt.x], [.pt.y]
    .show:
        stdcall [MessageBox], 0, addr .buffer, .title, MB_ICONINFORMATION
  .exit: 
    ret 

  .fmt db 'Cursor at %u:%u',0
  .title db 'CursorPos',0
endp    

; This way you can "keep things seperated" without initializing locals with the bunch of MOVs.

Even thouggh it looks a bit strange, it does work, thank you.
Using the TCHAR thingy results in an error, but "du" doesn't, is there anything that TCHAR does that "du" doesn't?

Thanks.
-Christoph
Post 19 Feb 2012, 22:52
View user's profile Send private message Visit poster's website Reply with quote
yoshimitsu



Joined: 07 Jul 2011
Posts: 96
yoshimitsu
windowClassName is a byte array, means with your code you get 8 bytes out of it which would be 'OPENGL64' and move it into windowClass.lpszClassName which should actually contain an address of string.
To be more precise, windowClassName is a symbolic equation for ebp+8, so it's not an actual address and therefore to calculate its real address you have to use lea:
Code:
lea rax,[windowClassName] ;it gets substituted for lea rax,[ebp+xx]
mov [windowClass.lpszClassName],rax    


PS: brackets are always needed when accessing memory.
Post 20 Feb 2012, 00:44
View user's profile Send private message Reply with quote
shadowomf



Joined: 31 Mar 2010
Posts: 12
Location: Germany
shadowomf
Now I think I've got it.
Thank you all.
Post 20 Feb 2012, 10:12
View user's profile Send private message Visit poster's website 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. Also on YouTube, Twitter.

Website powered by rwasa.