Pastey redy_error wrap demo end of file
- Posted by ne1uno Dec 28, 2016
--** -- public function GetLastError() integer cGetLastError = define_c_func(kernel32, "GetLastError", {}, C_DWORD) return c_func(cGetLastError,{}) end function public function FormatMessage(atom dwFlags, atom lpSource , atom dwMessageId, atom dwLanguageId ,object lpBuffer, atom nSize, atom Arguments) integer xFormatMessage = define_c_func(kernel32, "FormatMessageA" ,{C_DWORD, C_POINTER, C_DWORD, C_DWORD ,C_POINTER, C_DWORD, C_POINTER}, C_DWORD) if sequence(lpBuffer) then lpBuffer = allocate_string(lpBuffer, 1) end if return c_func(xFormatMessage ,{dwFlags,lpSource,dwMessageId,dwLanguageId ,lpBuffer,nSize, Arguments}) end function --kind of hardwired for getlasterror for now. --are defult params late binding? hope so -- -- printf(1," er=%s ",{get_winerror_string() }) -- c_proc( xSetLastError, {0} ) -- public function get_winerror_string(atom eror = GetLastError() ) integer MSGSIZE = 1022 atom lpMsgBuf = allocate(MSGSIZE+2, 1) FormatMessage( or_all({ --FORMAT_MESSAGE_ALLOCATE_BUFFER, FORMAT_MESSAGE_FROM_SYSTEM, FORMAT_MESSAGE_IGNORE_INSERTS}), NULL, eror, 0, -- Default language lpMsgBuf, --NULL MSGSIZE, --0 NULL ) return sprintf("0x%x %s", {eror, peek_string(lpMsgBuf)}) end function --may duplicate error to stdout and/or ring a bell --option overwrite log file then write_lines first call, then reset flag? procedure log_file(object fn, sequence lines, sequence mode="a") object rtn --~ if atom(fn) then --~ else --~ ?1/0 --~ end if --its putting a \n after every char pass strings as {"string"} if eu:compare(mode, "a")=0 then rtn = io:append_lines(fn, lines) else rtn = io:write_lines(fn, lines) end if if rtn then --can't write? end if end procedure atom wav_file = allocate_string(getenv("windir")&`\Media\tada.wav`, 1) PlaySound(wav_file, or_bits(SND_FILENAME, SND_ASYNC)) -- NULL, --possibly old bug workaround or demo: -- eu404 minGW can't resolve forward ref inside ifdef -- isn't caught till runtime inside an if hwnd=0 calls -- geterror is inside a default arg in a function -- guess will have to paste this at the top of a program? -- -- <eucode> -- usage -- sequence convert = "window error report" -- atom hwnd = 0 -- -- OutputDebugString(sprintf("convert %s ", {convert})) -- log_file("fname.log", {"some line","someother line"} ) -- -- c_proc( xSetLastError, {31} ) --create a fake error to show the text translation of the error number -- if hwnd = 0 then -- any_key("hit key to crash...\n Window Error ->>"& get_winerror_string()) -- crash("fake Window error reporting demo") -- end if --
OutputDebugString("eu4 Dbg ") ?4.10
MessageBeep(BEEP)
/* untested
- /
</eucode>
1. Comment by ne1uno Dec 28, 2016
for OutputDebugString(), one option: https://technet.microsoft.com/en-us/sysinternals/debugview.aspx
many editors and IDE have debug viewers