- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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
링크가 복사됨
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Steve
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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
