flat assembler
Message board for the users of flat assembler.

Index > Windows > Use a pointer of string in dialogs

Author
Thread Post new topic Reply to topic
FoXx



Joined: 25 Feb 2025
Posts: 18
FoXx 03 Mar 2025, 11:42
How do I use a pointer to a string?
\fasm\INCLUDE\MACRO\IMPORT32.INC (I'm not very familiar with macros).

This example shows how to best use the data section.
Code:
section '.data' data readable writeable
szTypeStatic            db "STATIC",0
szTypeButton            db "BUTTON",0
szTypeEdit              db "EDIT",0
szTypeList              db "LIST",0
;       ...

section '.rsrc' resource data readable
directory RT_DIALOG, Dialogs

;       ...

dialog DialogBox1,"Dialogs 1",70,70,120,40,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME
        dialogitem szTypeButton,"Ok",IDOK,8,20,50,20,WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON
        dialogitem szTypeButton,"Cancel",IDCANCEL,60,20,50,20,WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON
;       ...
enddialog    
Post 03 Mar 2025, 11:42
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1708
Location: Toronto, Canada
AsmGuru62 03 Mar 2025, 12:56
You can just use text for types of dialog items as you do with "Ok":
Code:
dialog add_class_dlg, 'New Class', 0, 0, 300, 143, WS_OVERLAPPEDWINDOW + DS_MODALFRAME + DS_CENTER,,,'Verdana',12
    dialogitem 'button', 'OK', IDOK, 155, 123, 60, 15, WS_VISIBLE + WS_TABSTOP + BS_DEFPUSHBUTTON
    dialogitem 'button', 'Cancel', IDCANCEL, 235, 123, 60, 15, WS_VISIBLE + WS_TABSTOP
enddialog
    
Post 03 Mar 2025, 12:56
View user's profile Send private message Send e-mail Reply with quote
FoXx



Joined: 25 Feb 2025
Posts: 18
FoXx 03 Mar 2025, 18:29
The menu is created from several types of windows. Why duplicate byte arrays when you can just use references to them?
Post 03 Mar 2025, 18:29
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1708
Location: Toronto, Canada
AsmGuru62 03 Mar 2025, 23:32
From what we can see in a macro for dialogitem:
Code:
macro dialogitem class,title,id,x,y,cx,cy,style,exstyle
 { dd style or WS_CHILD,exstyle +0
   dw x,y,cx,cy,id
   if class eq 'BUTTON'
    dw 0FFFFh,80h
   else if class eq 'EDIT'
    dw 0FFFFh,81h
   else if class eq 'STATIC'
    dw 0FFFFh,82h
   else if class eq 'LISTBOX'
    dw 0FFFFh,83h
   else if class eq 'SCROLLBAR'
    dw 0FFFFh,84h
   else if class eq 'COMBOBOX'
    dw 0FFFFh,85h
   else
    du class,0
   end if
   if title eqtype 0
    dw 0FFFFh,title
   else
    du title,0
   end if
   dw 0
   align 4
   dialog_items_counter = dialog_items_counter + 1 }
    

The strings for classes of Dialog Controls are turned into 16-bit values (BUTTON turns into 0FFFFh,80h).
I am not sure that replacing them (in this case) with text declared with DB will actually work.
In the FASM Manual for Windows Programming the dialogitem example shows using 'BUTTON', so that is the way, I guess.
Also, I think, LIST should be LISTBOX.
What I mean was, that there is no duplicates of BUTTON,EDIT, etc. in the compiled resource.
Post 03 Mar 2025, 23:32
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20625
Location: In your JS exploiting you and your system
revolution 04 Mar 2025, 01:09
This can also verified by searching the output.
Code:
$ grep --count "'BUTTON'" ./source/win32/fasmw/fasmw.asm
24

$ grep --count BUTTON fasmw.exe 
0

$     
Post 04 Mar 2025, 01:09
View user's profile Send private message Visit poster's website Reply with quote
FoXx



Joined: 25 Feb 2025
Posts: 18
FoXx 04 Mar 2025, 12:50
Thank! I looked at the exe-file in an hex-editor and couldn't find the names of classes.

I thought it was similar to importing libraries. The procedure name is used in the error message.

Code:
;------------------------------------------------
;   * * *  Import Library Procedures * * *
;------------------------------------------------
section '.idata' import data readable writeable

DD 0,0,0,  RVA szKernel32,      RVA LibraryKernel32
DD 0,0,0,  RVA szUser32,        RVA LibraryUser32
DD 0,0,0,0,0
;------------------------------------------------
;   * * *  Import Proc Kernel32 * * *
;------------------------------------------------
LibraryKernel32:

GetCommandLine          DD RVA szGetCommandLine
ExitProcess             DD RVA szExitProcess
end_Kernel32            DD NULL
;------------------------------------------------
;   * * *  Import Proc User32 * * *
;------------------------------------------------
LibraryUser32:

MessageBox              DD RVA szMessageBox
end_User32              DD NULL
;------------------------------------------------
;       * * *  WinAPI ProcNames
;------------------------------------------------
szKernel32              DB 'KERNEL32.DLL',0
szUser32                DB 'USER32.DLL',0

szGetCommandLine        DB 0,0, 'GetCommandLineA',0
szExitProcess           DB 0,0, 'ExitProcess',0

szMessageBox            DB 0,0, 'MessageBoxA',0
    
Post 04 Mar 2025, 12:50
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.