flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Marut 18 Jun 2017, 16:23
Hi everyone,
I've been programming using FASM for a few years now, without too many headaches (quite powerful programming environment, in fact), and until now I've always compiled resources using internal macroinstructions. Recently I started a more "serious" project which needs a lot of fiddling with GDI and the user interface; since using an IDE to design dialog boxes and stuff is way faster and less cumbersome, I tried including an external resource file using: Code: section '.rsrc' data readable resource from 'resource.res' but it gave me an "Error: invalid file format" message. I also tried including a .rc file, with the same result. Peeking inside the source code, I found out that the file must start with: Quote: 00 00 00 00 - 20 00 00 00 - FF FF 00 00 - ? ? ? ? - ? ? FF FF - 00 00 ? ? --- (SOURCE\FORMATS.INC lines 1688-1698) in order not to be immediately discarded, so it must be a binary file (certainly not .rc); but the MS format specifications for resource files indicate that, in short, the first DWORD in a .res file is the size (in bytes) of the first resource included, which shouldn't be 0, so it's not that format, either. (See https://msdn.microsoft.com/en-us/library/windows/desktop/ms648007(v=vs.85).aspx and https://msdn.microsoft.com/en-us/library/windows/desktop/ms648027(v=vs.85).aspx) So, it would really help me if someone could kindly point me to the format accepted by FASM. P.S.: IMHO this should be included in FASM.PDF too; given how powerful the macro system is, even the fact that .rc files are not supported is not all that obvious to me... |
|||
![]() |
|
Tomasz Grysztar 18 Jun 2017, 20:31
Is your resource file a 16-bit one? This special header that fasm is checking for is there to distinguish 32-bit resources from 16-bit ones.
You can read about it in these old specs: http://www.csn.ul.ie/~caolan/pub/winresdump/winresdump/doc/resfmt.txt Quote: Because it might be desirable for an ISV's tool that reads and writes |
|||
![]() |
|
dancho 19 Jun 2017, 09:28
@Marut
try to use PellesC Ide as resource editor to create res file, in my experience fasm have no problem with it... http://smorgasbordet.com/pellesc/ |
|||
![]() |
|
Mikl___ 19 Jun 2017, 12:29
Hi, Marut!
ftut-08-01.asm Code: format PE GUI include 'win32ax.inc' ; import data in the same section ZZZ_TEST equ 0 ZZZ_OPEN equ 1 ZZZ_SAVE equ 2 ZZZ_EXIT equ 3 xor ebx,ebx mov edi,wTitle mov esi,400000h ; +------------------------------+ ; | registering the window class | ; +------------------------------+ invoke RegisterClass,esp,ebx,WndProc,ebx,\ ebx,esi,ebx,10011h,COLOR_WINDOW+1,menu_name,edi ; +--------------------------+ ; | creating the main window | ; +--------------------------+ push ebx esi ebx ebx shl esi,9 invoke CreateWindowEx,ebx,edi,edi,WS_OVERLAPPEDWINDOW+\ WS_VISIBLE,esi,esi,esi,esi mov ebp,esp ; +---------------------------+ ; | entering the message loop | ; +---------------------------+ message_loop: invoke GetMessage,ebp,ebx,ebx,ebx invoke DispatchMessage,ebp jmp message_loop ; +----------------------+ ; | the window procedure | ; +----------------------+ proc WndProc,hWnd,uMsg,wParam,lParam mov eax,[uMsg] dec eax; cmp uMsg,WM_DESTROY dec eax je wmDESTROY sub eax,WM_COMMAND-WM_DESTROY; cmp uMsg,WM_PAINT je wmCOMMAND leave jmp dword [DefWindowProc] wmCOMMAND: mov ebx,[wParam] cmp ebx,ZZZ_EXIT je wmDESTROY;menu_exit show_msg: invoke MessageBox,[hWnd],[menu_handlers+ebx*4],menu_name,eax ret wmDESTROY: invoke ExitProcess,ebx endp ;-------------------------------------------------------------------- ;exp = experiment wTitle db 'Iczelion Tutorial #8-1:Creating a menu through a resource file in FASM',0 ;name of our window menu_name db 'ZZZ_Menu',0 test_msg db 'You select menu item TEST',0 open_msg db 'You select menu item OPEN',0 save_msg db 'You select menu item SAVE',0 menu_handlers dd test_msg, open_msg, save_msg ;--------------------------------------------------------------------- data import library KERNEL32, 'KERNEL32.DLL',\ user32, 'USER32.DLL' import KERNEL32,\ ExitProcess, 'ExitProcess' import user32,\ RegisterClass, 'RegisterClassA',\ CreateWindowEx, 'CreateWindowExA',\ DefWindowProc, 'DefWindowProcA',\ GetMessage, 'GetMessageA',\ DispatchMessage, 'DispatchMessageA',\ DestroyWindow, 'DestroyWindow',\ MessageBox, 'MessageBoxA' end data section '.rsrc' resource from 'ftut_08-01.res' data readable Code: #define ZZZ_TEST 0 #define ZZZ_OPEN 1 #define ZZZ_SAVE 2 #define ZZZ_EXIT 3 ZZZ_Menu MENU { POPUP "&File" { MENUITEM "&Test",ZZZ_TEST MENUITEM "&Open",ZZZ_OPEN MENUITEM "&Save",ZZZ_SAVE MENUITEM SEPARATOR MENUITEM "&Exit",ZZZ_EXIT } MENUITEM "&Exit",ZZZ_EXIT } Code: set masm32_path=\masm32\ set filename=ftut_08-01 %masm32_path%\bin\RC /r /i"%masm32_path%\Include" %filename%.rc
|
||||||||||||||||||||
![]() |
|
Marut 21 Jun 2017, 17:05
Hi everyone, thank you all for your help.
It looks like Privalov is right: my .res file was 16-bit (probably), so that's one mistery solved. I managed to make it work by using the resource compiler in VS 2017 Community, since I already had it lying around for other reasons; it's a bit bulky, but it works well for the moment. Let me insist though, it would be wise in my opinion to add a line to the documentation pointing out what type of resource file FASM is exactly expecting to read. Note for Privalov: while tinkering with Visual Studio at some point it spit out an empty/corrupted .res file, which is basically just the first 0x20 bytes stub header. I'm not sure if the part of code in FASM dedicated to resource importing is supposed to be fail-proof or not, but anyway merely importing that file makes both FASMW and FASM crash during compilation. Just in case you wanted to investigate the problem. The following is for the posterity, in case someone in need chances upon this thread. Info for anyone having problems importing/designing resources for FASM:
|
|||
![]() |
|
revolution 21 Jun 2017, 18:56
The macros in fasm and fasmg are reasonably powerful. It would also be possible to make a resource compiler using macros.
|
|||
![]() |
|
Furs 21 Jun 2017, 21:22
BTW off topic but, since you mentioned a Hex Editor, I'd recommend instead HxD, it can also deal with larger files than 2GB (doesn't memory map it, and only writes the part of the file actually modified when saving).
![]() |
|||
![]() |
|
TheRaven 15 Sep 2017, 20:51
Furs wrote: BTW off topic but, since you mentioned a Hex Editor, I'd recommend instead HxD, it can also deal with larger files than 2GB (doesn't memory map it, and only writes the part of the file actually modified when saving). Agreed. DMA -RAM -etc. --HxD is quite powerful. _________________ Nothing so sought and avoided more than the truth. I'm not insane, I know the voices in my head aren't real! |
|||
![]() |
|
ctl3d32 18 Sep 2017, 10:52
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.