flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
MattDiesel 19 Jan 2011, 23:13
FASM has kept me hooked for a few months now, and I am getting the hang of asm
![]() Amongst other problems I'm facing is how to handle errors. Using lot's of strings is not easy in asm like it is at higher levels, so I looked for other solutions and found MESSAGETABLEs. These are exactly what I want, as it means I can use Get/SetLastError with system codes AND my own errors as well. Unfortunately they do not feature in the fasm resource macros (yet ![]() Msdn has structures which should show how they are arranged in the exe, here, so it should be possible for me to write some macros that end up with a load of db's... Unfortunately I can't see how those structures results in the numbers I get... Here's a little demo I put together that needs no other files to run: Code: format PE GUI 4.0 entry start include 'win32a.inc' ERROR_MYERROR = 0xC0020001 ; Generated by MC.EXE section '.text' code readable executable start: pushd 1 ; System Error (ERROR_INVALID_FUNCTION) call ShowErr pushd ERROR_MYERROR ; App error call ShowErr invoke ExitProcess,0 ; Simple error handling proc proc ShowErr,iErr local lpBuffer:DWORD lea eax,[lpBuffer] invoke FormatMessage,\ FORMAT_MESSAGE_ALLOCATE_BUFFER+\ FORMAT_MESSAGE_FROM_HMODULE+\ ; Using FROM_HMODULE | FROM_SYSTEM means FORMAT_MESSAGE_FROM_SYSTEM,\ ; it will check both for the error. NULL,\ [iErr],\ LANG_NEUTRAL,\ eax,\ 0,\ 0 invoke MessageBox,NULL,[lpBuffer],NULL,MB_OK+MB_SYSTEMMODAL+MB_ICONERROR invoke LocalFree,[lpBuffer] ret endp section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL' include 'api\kernel32.inc' include 'api\user32.inc' section '.rsrc' data readable resource directory RT_MESSAGETABLE,errors resource errors,\ 1,LANG_ENGLISH+SUBLANG_DEFAULT,error_table ; Must be 1. ; Data generated by MC.EXE. ; Would normally use: file 'MSG00409.bin' resdata error_table db 0x01,0x00,0x00,0x00,0x01,0x00,0x02,0xC0,0x01,0x00,0x02,0xC0,0x10,0x00,0x00,0x00,\ 0x84,0x00,0x01,0x00,0x54,0x00,0x68,0x00,0x69,0x00,0x73,0x00,0x20,0x00,0x69,0x00,\ 0x73,0x00,0x20,0x00,0x70,0x00,0x72,0x00,0x6F,0x00,0x62,0x00,0x61,0x00,0x62,0x00,\ 0x6C,0x00,0x79,0x00,0x20,0x00,0x74,0x00,0x68,0x00,0x65,0x00,0x20,0x00,0x6F,0x00,\ 0x6E,0x00,0x6C,0x00,0x79,0x00,0x20,0x00,0x65,0x00,0x72,0x00,0x72,0x00,0x6F,0x00,\ 0x72,0x00,0x20,0x00,0x6D,0x00,0x65,0x00,0x73,0x00,0x73,0x00,0x61,0x00,0x67,0x00,\ 0x65,0x00,0x20,0x00,0x74,0x00,0x68,0x00,0x61,0x00,0x74,0x00,0x20,0x00,0x6D,0x00,\ 0x65,0x00,0x61,0x00,0x6E,0x00,0x73,0x00,0x20,0x00,0x53,0x00,0x75,0x00,0x63,0x00,\ 0x63,0x00,0x65,0x00,0x73,0x00,0x73,0x00,0x20,0x00,0x3A,0x00,0x29,0x00,0x0D,0x00,\ 0x0A,0x00,0x00,0x00 endres That table was made from this (Slightly modified from msdn's example file): Code: MessageIdTypedef=DWORD SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS Informational=0x1:STATUS_SEVERITY_INFORMATIONAL Warning=0x2:STATUS_SEVERITY_WARNING Error=0x3:STATUS_SEVERITY_ERROR ) FacilityNames=(System=0x0:FACILITY_SYSTEM Runtime=0x2:FACILITY_RUNTIME Stubs=0x3:FACILITY_STUBS Io=0x4:FACILITY_IO_ERROR_CODE ) LanguageNames=(English=0x409:MSG00409) ; // The following are message definitions. MessageId=0x1 Severity=Error Facility=Runtime SymbolicName=ERROR_MYERROR Language=English This is probably the only error message that means Success Any pointers? Mat |
|||
![]() |
|
typedef 26 Jan 2011, 19:56
Nice, I'll be able to use this piece of code one day. I need to study more on macros
![]() ![]() Off topic The thing I like thte most is the speed and size. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.