- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
call errsns (, code) ! --- Fortran intrinsic
call FormatMessage (..., code, ..., message, ...) ! --- DFWIN
to give me message texts like "The system cannot find the file specified."
But if I use this now, then the call to errsns returns zero and not the system error code that I expected. Is this change in operation intentional, and if so then how can I get at the texts of system error messages.
geoff wright
computable functions
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is what I'm using, but the message returned is always composed of junk characters:
LAST_ERROR = GETLASTERROR() ! is returning a system code
CALL FORMATMESSAGE(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER .OR.
+ FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL,
+ LAST_ERROR,
+ 0,
+ ERROR_MSG,
+ 0,
+ NULL )
WRITE(*,*) ERROR_MSG ! declared as CHARACTER*(80)
! value returned is composed of WingDings style characters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My code to get the message text is:-
character*256 message
integer*4 msg_len
msg_len = FormatMessage (
(FORMAT_MESSAGE_FROM_SYSTEM .OR.
FORMAT_MESSAGE_IGNORE_INSERTS .OR.
FORMAT_MESSAGE_MAX_WIDTH_MASK),
%val(0), code, 0, message, len(message), 0)
message(msg_len+1:msg_len+1) = ' '
But remember that this was written many years ago when I thought that I understood what I was doing. I do know that the last line was there to remove the null that terminated the C-style string.
geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Under Visual FORTRAN 6.6A (OS Windows) I have gotten calls to the win32 functions GETLASTERROR and FORMATMESSAGE to work:
subroutine Report_Sys_Error()
! When a win32 routine has returned an error code
! call this subroutine.
! LpBuffer below is the win32 error message
USE DFWIN
integer(DWORD) dwFlags ! DWORD dwFlags
integer(LPCVOID) lpSource ! LPCVOID lpSource
integer(DWORD) dwMessageId ! DWORD dwMessageId
integer(DWORD) dwLanguageId ! DWORD dwLanguageId
character*256 lpBuffer ! LPSTR lpBuffer
! integer(DWORD) nSize ! DWORD nSize
TYPE(T_VA_LIST) Arguments ! va_list* Arguments
INTEGER FuncOut, IER
ier= GetLastError()
DWflags = IOR(FORMAT_MESSAGE_IGNORE_INSERTS,FORMAT_MESSAGE_FROM_SYSTEM)
dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)
FuncOut = FormatMessage_G1( &
dwFlags, &
NULL, & ! lpSource,
ier, &
dwLanguageId, &
lpBuffer, &
len(lpBuffer), &
Arguments)
! Write to the error message to console if this a console application
! write(*,*) 'Error: ' // lpBuffer
end subroutine Report_Sys_Error

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page