flat assembler
Message board for the users of flat assembler.

Index > Windows > Why is the error "undefined symbol 'size?Ty'" generated?

Author
Thread Post new topic Reply to topic
zvn



Joined: 21 Oct 2024
Posts: 12
zvn 21 Oct 2024, 12:39
Why during the program compilation process:
Code:
format    PE GUI
include   'win32a.inc'
entry     beg

section '.code' code executable
beg:

        invoke GetModuleHandle, 0
        invoke DialogBoxParam, eax, 0, HWND_DESKTOP, DialogProc, 0
        invoke ExitProcess, 0

proc    DialogProc hwnddlg, msg, wParam, lParam
xor     eax, eax
cmp     [msg], WM_CLOSE
jne     ExitProc
invoke  EndDialog, [hwnddlg], 0
ExitProc:
ret
endp

section 'import' import readable

library kernel,         'kernel32.dll',\
        user,           'user32.dll'

import kernel,\
      GetModuleHandle,    'GetModuleHandleW',\
      ExitProcess,        'ExitProcess'

import user,\
      DialogBoxParam,     'DialogBoxParamW',\
      EndDialog,          'EndDialog'

section '.rsrc' resource readable

directory       RT_DIALOG, dialogs, RT_MENU,   menus

resource        dialogs, 0, LANG_NEUTRAL, MainWindow
dialog          MainWindow, '', 300, 300, 200, 100, WS_VISIBLE+WS_SYSMENU
enddialog

resource        menus, 1, LANG_NEUTRAL, main_menu
menu main_menu
menuitem '&File', 2
    

fasm 1.73.30 generated error "undefined symbol 'size?Ty'" with instructions:
main_menu dd RVA data?Tx,size?Ty,0,0
in 153 line file resource.inc = macros menu?
Post 21 Oct 2024, 12:39
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4061
Location: vpcmpistri
bitRAKE 21 Oct 2024, 15:11
It looks like your code is truncated - it's difficult to discern what is actually happening. I'm going to assume and show this complete menu resource as an example:
Code:
  menu main_menu
       menuitem '&File',0,MFR_POPUP
                menuitem '&New',IDM_NEW
                menuseparator
                menuitem 'E&xit',IDM_EXIT,MFR_END
       menuitem '&Help',0,MFR_POPUP + MFR_END
                menuitem '&About...',IDM_ABOUT,MFR_END    
... every MFR_POPUP needs a corresponding MFR_END and a terminating MFR_END for the top-level menu bar.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 21 Oct 2024, 15:11
View user's profile Send private message Visit poster's website Reply with quote
zvn



Joined: 21 Oct 2024
Posts: 12
zvn 22 Oct 2024, 04:29
Quote:
It looks like your code is truncated - it's difficult to discern what is actually happening.

You are right. This code creates a window. Other controls behave normally. But the menu does not work.
Quote:
I'm going to assume and show this complete menu resource as an example:

In my Win10 system, your menu compiles without errors, but after launching the menu does not appear in the window.
Quote:
every MFR_POPUP needs a corresponding MFR_END and a terminating MFR_END for the top-level menu bar.

Yes, but the error occurs in the menu macro, not in the menuitem macro...
Any other thoughts on this?


Description: Example of a window with your menu resource...
Filesize: 6.58 KB
Viewed: 649 Time(s)

windlg.png


Post 22 Oct 2024, 04:29
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1024
Location: Russia
macomics 22 Oct 2024, 05:30
zvn wrote:
Yes, but the error occurs in the menu macro, not in the menuitem macro...
Is it really a matter? If you do not have a macro call that will have to declare the missing variable, then you will get an error exactly at the place where the undeclared variable is used (in another macro or even module).

To make menu appear, it is not enough to simply declare it. It should also be added to the dialog.
Post 22 Oct 2024, 05:30
View user's profile Send private message Reply with quote
zvn



Joined: 21 Oct 2024
Posts: 12
zvn 22 Oct 2024, 05:47
Quote:
Is it really a matter? If you do not have a macro call that will have to declare the missing variable, then you will get an error exactly at the place where the undeclared variable is used (in another macro or even module).

What do you mean there is no macro call? And what do you think this code does?
Code:
macro main_menu    

In the resource.inc. file, the menu macro is described like this:
Code:
macro menu label             
 { local data,size            
   label dd RVA data, size, 0, 0
   data dw 1,4,0,0
   menu_size equ size = $ - data
   menu_level = 1 }    

In the programmer's guide, item 3.1.8, it says that the menu macro takes one parameter. What causes an error in my code?
Quote:
To make menu appear, it is not enough to simply declare it. It should also be added to the dialog.

This may solve the problem of displaying the menu in the window, but how to do it?
Post 22 Oct 2024, 05:47
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1024
Location: Russia
macomics 22 Oct 2024, 07:24
zvn wrote:
What do you mean there is no macro call? And what do you think this code does?
Code:
macro main_menu ; Declares a new macro named main_menu    


zvn wrote:
In the resource.inc. file, the menu macro is described like this:
Code:
macro menu label             
 { local data,size            ; Declares new labels with local names: data, size
   label dd RVA data, size, 0, 0 ; And here these labels are used
   data dw 1,4,0,0 ; Here is the data label determined by the address (numerical equivalent is supplied)
   menu_size equ size = $ - data ; Here is the preprocessor constant to create a similar one with the size label
; This constant must now also be used so that size gets a numeric equivalent.
   menu_level = 1 }    
Code:
macro menuitem string,id,resinfo,status,type
 { dd MFT_STRING or type+0,status+0,id
   dw resinfo+0
   du string,0
   align 4
   if ~ resinfo eq
    if resinfo and MFR_END
     menu_level = menu_level - 1
    end if
    if resinfo and MFR_POPUP
     menu_level = menu_level + 1
     dd 0
    end if
   end if
   if menu_level = 0
    menu_size ; And it's only here that constant size, defined in the menu macro, gets its numerical equivalent so that it can be substituted when using
   end if }    


zvn wrote:
This may solve the problem of displaying the menu in the window, but how to do it?
Code:
; x86_64
WM_INITDIALOG: invoke GetModuleHandleA, NULL
invoke LoadMenuA, rax, RT_MENU
invoke SetMenu, [hWnd], rax
...    
Code:
; i386
WM_INITDIALOG: invoke GetModuleHandleA, NULL
invoke LoadMenuA, eax, RT_MENU
invoke SetMenu, [hWnd], eax
...    
Post 22 Oct 2024, 07:24
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1024
Location: Russia
macomics 22 Oct 2024, 08:23
zvn wrote:
What do you mean there is no macro call?
Try to feed this text to fasm1
Code:
macro my_macro { display "first", 13, 10 } ; Declare a new macro named my_macro
my_macro ; Call a macro named my_macro eg show "first"
macro my_macro args& { ; Redeclared a macro named my_macro
  display "second."
  my_macro ; Call a macro named my_macro (first) *
; * This call will be executed only when the newly declared macro is called
}
my_macro ; Call a macro named my_macro (redeclared) eg show "second." and then "first"
purge my_macro
my_macro ; Call a macro named my_macro (first) eg show "first"    


Code:
 $ fasm my_macro.asm
flat assembler  version 1.73.32  (16384 kilobytes memory)
first
second.first
first
1 passes, 0 bytes.    
Post 22 Oct 2024, 08:23
View user's profile Send private message Reply with quote
zvn



Joined: 21 Oct 2024
Posts: 12
zvn 22 Oct 2024, 09:29
Thanks guys! This is an example of menu resources:
Code:
 menu main_menu
       menuitem '&File',0,MFR_POPUP
                menuitem '&New',IDM_NEW
                menuseparator
                menuitem 'E&xit',IDM_EXIT,MFR_END
       menuitem '&Help',0,MFR_POPUP + MFR_END
                menuitem '&About...',IDM_ABOUT,MFR_END    

with calls to these functions:
Code:
invoke LoadMenuA, eax, RT_MENU
invoke SetMenu, [hWnd], eax    

solved my problem!
There is only one question left about this line:
Code:
label dd RVA data, size, 0, 0    

It is clear that the label is created on an array of elements of size dd, but what does RVA mean?
Quote:
macomics

Thank you, this was a fun experiment! You opened up the display command for me!
Post 22 Oct 2024, 09:29
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1024
Location: Russia
macomics 22 Oct 2024, 09:40
zvn wrote:
It is clear that the label is created on an array of elements of size dd, but what does RVA mean?

RVA - Relative Virtual Address
2.4.2 Portable Executable wrote:
The rva operator can be used inside the numerical expressions to obtain the RVA of the item addressed by the value it is applied to, that is the offset relative to the base of PE image.
Post 22 Oct 2024, 09:40
View user's profile Send private message Reply with quote
zvn



Joined: 21 Oct 2024
Posts: 12
zvn 22 Oct 2024, 10:51
Quote:
label dd RVA data, size, 0, 0

That is, the address of the first element (data) of this array dd will somehow depend on the offset relative to the end of the PE structure?
Or will the value of the first element (data) be somehow related to the offset?
Post 22 Oct 2024, 10:51
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1024
Location: Russia
macomics 22 Oct 2024, 11:01
zvn wrote:
That is, the address of the first element (data) of this array dd will somehow depend on the offset relative to the end of the PE structure?
Or will the value of the first element (data) be somehow related to the offset?
No. Relative to image base. (ImageBaseOfExe = GetModuleHandle(NULL))
Post 22 Oct 2024, 11:01
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4061
Location: vpcmpistri
bitRAKE 22 Oct 2024, 14:04
Another option is to specify the menu ID in the dialog statement:
Code:
dialog dialog_example,'In-Tale: Menu',0,0,256,128,\
        WS_VISIBLE or WS_CAPTION or WS_POPUP or WS_SYSMENU or DS_CENTERMOUSE,\
        WS_EX_TOOLWINDOW,IDM_MULTI,'Segoe UI',11
        ; nothing
enddialog    
... here IDM_MULTI is the menu id, no code is needed.
(Making everything static is very limited though.)

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 22 Oct 2024, 14:04
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.