Author Topic: Examples built with the -pe option  (Read 308 times)

Vortex

  • Member
  • *****
  • Posts: 2032
Examples built with the -pe option
« on: November 10, 2019, 04:58:24 AM »
The -pe option of ASMC builds executables without the need of a linker. Here is a dialog box built with the -pe switch. It uses HLL constructs and the INCBIN statement to extract data from a compiled ( .res ) file :

Code: [Select]
Resource    LABEL Byte
INCBIN      "Rsrc.res",DLG_OFFSET,RSRC1_SIZE

Menu        LABEL Byte
INCBIN      "Rsrc.res",MENU_OFFSET,RSRC2_SIZE
« Last Edit: November 10, 2019, 06:43:23 AM by Vortex »

Vortex

  • Member
  • *****
  • Posts: 2032
Re: Examples built with the -pe option
« Reply #1 on: November 21, 2019, 08:00:36 AM »
Hi nidud,

I managed to build the resource section with your macros defined in winres.inc :

Code: [Select]
RCBEGIN

 RCTYPES 2

 RCENTRY RT_MENU
 RCENTRY RT_DIALOG

 RCENUMN 1
 RCENUMX IDR_MENU
 RCENUMN 1
 RCENUMX IDD_DIALOG

 RCLANGX LANGID_US
 RCLANGX LANGID_US

 MENUBEGIN
    MENUNAME "&File"
    MENUITEM IDM_ABOUT,"&About"
    MENUITEM IDM_MNMIZE,"&Minimize"
    MENUITEM IDM_EXIT,"&Exit"
 MENUEND

DLGFLAGS equ DS_MODALFRAME or DS_SETFONT or WS_POPUP or WS_VISIBLE or WS_CAPTION or WS_SYSMENU

DLGBEGIN DLGFLAGS,4,20, 10, 186, 104

CAPTION "Dialog box"
FONT 12, "System"

    CONTROL "&About", 110, RC_BUTTON, WS_TABSTOP, 116, 8, 50, 20
    CONTROL "&Minimize",120, RC_BUTTON, WS_TABSTOP, 116, 36, 50, 20
    CONTROL "&Exit",130, RC_BUTTON, WS_TABSTOP, 116, 64, 50, 20
    CONTROL "   Asmc Dialog Box", 4000, RC_EDIT, ES_AUTOHSCROLL or WS_BORDER or WS_TABSTOP, 16, 8, 72, 20

DLGEND

RCEND

Could you provide a macro to incorporate the menu to the dialog box? The executable in the attachment does not display the menu.

In a classical resource script, adding a menu is easy : MENU IDR_MENU

Code: [Select]
IDD_DIALOG DIALOGEX DISCARDABLE 20, 10, 186, 104, 18481280
STYLE DS_3DLOOK|DS_CENTER|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_VISIBLE
CAPTION "Dialog box"
FONT 12, "System", 700, 0, 1
MENU IDR_MENU
{
  CONTROL "&About", 110, "Button", WS_TABSTOP, 116, 8, 50, 20, 0, 1234049503
  CONTROL "&Minimize",120, "Button", WS_TABSTOP, 116, 36, 50, 20, 0, 1234049503
  CONTROL "&Exit",130, "Button", WS_TABSTOP, 116, 64, 50, 20
  CONTROL "   Asmc Dialog Box", 4000, "Edit", ES_AUTOHSCROLL|WS_BORDER|WS_TABSTOP, 16, 8, 72, 20
}

Vortex

  • Member
  • *****
  • Posts: 2032
Re: Examples built with the -pe option
« Reply #2 on: November 22, 2019, 05:06:06 AM »
Hi nidud,

I guess the MenuName item should be added to the DLGBEGIN macro.

Code: [Select]
struct DialogBoxHeader {
  DWORD  lStyle;
  DWORD  lExtendedStyle;     // new for NT
  WORD   NumberOfItems;
  WORD   x;
  WORD   y;
  WORD   cx;
  WORD   cy;
  [Name or Ordinal] MenuName;
  [Name or Ordinal] ClassName;
  WCHAR  szCaption[];
  WORD   wPointSize;         // Only here if FONT set for dialog
  WCHAR  szFontName[];       // This too
  };

nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Examples built with the -pe option
« Reply #3 on: November 22, 2019, 05:56:31 AM »
Yes. I think it should be inserted as the first item after the DLGTEMPLATE.

typedef struct {
  WORD      dlgVer;
  WORD      signature;
  DWORD     helpID;
  DWORD     exStyle;
  DWORD     style;
  WORD      cDlgItems;
  short     x;
  short     y;
  short     cx;
  short     cy;
  sz_Or_Ord menu;
  sz_Or_Ord windowClass;
  WCHAR     title[titleLen];
  WORD      pointsize;
  WORD      weight;
  BYTE      italic;
  BYTE      charset;
  WCHAR     typeface[stringLen];
} DLGTEMPLATEEX;

I added dw -1, ID, 0 but no luck (it crashed)...
Guess maybe something else has to be changed as well.

nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Examples built with the -pe option
« Reply #4 on: November 22, 2019, 07:14:13 AM »
https://docs.microsoft.com/en-us/windows/win32/dlgbox/dlgtemplateex
Quote
menu

Type: sz_Or_Ord

A variable-length array of 16-bit elements that identifies a menu resource for the dialog box. If the first element of this array is 0x0000, the dialog box has no menu and the array has no other elements. If the first element is 0xFFFF, the array has one additional element that specifies the ordinal value of a menu resource in an executable file. If the first element has any other value, the system treats the array as a null-terminated Unicode string that specifies the name of a menu resource in an executable file.

nidud

  • Member
  • *****
  • Posts: 1800
    • https://github.com/nidud/asmc
Re: Examples built with the -pe option
« Reply #5 on: November 22, 2019, 07:29:32 AM »
So the new macro goes like this:

DLGBEGIN macro flags,items,x,y,w,h,exflags:=<0>,menu:=<0>,CodePage:=<0>
    RCDIALOG CodePage
    if exflags
     dd 0xFFFF0001, 0x00000000
     dd exflags, flags
     RCENUM3 = 1
    else
     dd flags, 0
     RCENUM3 = 0
    endif
    dw items,x,y,w,h
    if menu
     dw -1
     dd menu
    else
     dd 0
    endif
    endm

And the new resource:

RCBEGIN

 RCTYPES 2

 RCENTRY RT_MENU
 RCENTRY RT_DIALOG

 RCENUMN 1
 RCENUMX IDR_MENU
 RCENUMN 1
 RCENUMX IDD_DIALOG

 RCLANGX LANGID_US
 RCLANGX LANGID_US

 MENUBEGIN
    MENUNAME "&File", MF_END
    MENUITEM IDM_ABOUT,"&About"
    MENUITEM IDM_MNMIZE,"&Minimize"
    MENUITEM IDM_EXIT,"&Exit", MF_END
 MENUEND

 DLGFLAGS equ DS_MODALFRAME or DS_SETFONT or WS_POPUP or WS_VISIBLE or WS_CAPTION or WS_SYSMENU

 DLGBEGIN DLGFLAGS,4,20, 10, 186, 104, 0, IDR_MENU

    CAPTION "Dialog box"
    FONT 12, "System"

    CONTROL "&About", 110, RC_BUTTON, WS_TABSTOP, 116, 8, 50, 20
    CONTROL "&Minimize",120, RC_BUTTON, WS_TABSTOP, 116, 36, 50, 20
    CONTROL "&Exit",130, RC_BUTTON, WS_TABSTOP, 116, 64, 50, 20
    CONTROL "   Asmc Dialog Box", 4000, RC_EDIT, ES_AUTOHSCROLL or WS_BORDER or WS_TABSTOP, 16, 8, 72, 20

 DLGEND

RCEND

Vortex

  • Member
  • *****
  • Posts: 2032
Re: Examples built with the -pe option
« Reply #6 on: November 22, 2019, 07:33:31 AM »
Many thanks nidud :thumbsup:

Vortex

  • Member
  • *****
  • Posts: 2032
Re: Examples built with the -pe option
« Reply #7 on: November 23, 2019, 06:50:59 AM »
Here is the project built with the new macros.