Software Archive
Read-only legacy content
17061 Discussions

run-time error messages

Intel_C_Intel
Employee
564 Views
I have just returned to using Visual Fortran after a gap of about 3 years. With the version at that time (version 5?) I was able to get at the text of system error messages (e.g. after using an ERR=) by :-

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
0 Kudos
4 Replies
Steven_L_Intel1
Employee
564 Views
I suggest sending an example of the problem to vf-support@compaq.com. I am not aware of any changes in this area, but the experts for this don't read this forum.

Steve
0 Kudos
Intel_C_Intel
Employee
564 Views
BTW, what are the correct values for the first two parameters?
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
0 Kudos
Intel_C_Intel
Employee
564 Views
Thank, GetLastError seems to do the trick, but it doesn't explain why ERRSNS has stopped returning the system error code.

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
0 Kudos
Deleted_U_Intel
Employee
564 Views

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

0 Kudos
Reply