- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I'm using CFV 6.5 in Windows 2000 to run an executable, and then read the screen output from that executable. Since FORTRAN only reads characters from the screen input (cursor line), I tried using some Windows SDK routines, like ReadConsoleOutput, or ReadConsoleOutputCharacter, but I can't get them to work.
Using ReadConsoleOutput, I get Error 87 (ERROR_INVALID_PARAMETER), and using ReadConsoleOutputCharacter, I'm getting Error 12 (ERROR_INVALID_ACCESS). I think my problem is with the declaration of the variables, can anyone help me on this?
The example I'm trying to follow declares chiBuffer as a CHAR_INFO structure of size 160 (two lines of 80 characters). How can I do that in FORTRAN?
Here's the code I have so far...
USE DFWIN
USE KERNEL32
Type(T_CHAR_INFO) chiBuffer
Type(T_COORD) coordBufSize
Type(T_COORD) coordBufCoord
Type(T_SMALL_RECT) srctReadRect
type(T_SECURITY_ATTRIBUTES) lpSecurityAttributes
INTEGER hStdout,hNewScreenBuffer,readLength,i
CHARACTER fullMessage*80
LOGICAL status,fSuccess,fSuccess2
hStdout = GetStdHandle(STD_OUTPUT_HANDLE)
hNewScreenBuffer = CreateConsoleScreenBuffer
& (GENERIC_WRITE,0,lpSecurityAttributes,CONSOLE_TEXTMODE_BUFFER,0)
srctReadRect.Top = 0
srctReadRect.Left = 0
srctReadRect.Bottom = 1
srctReadRect.Right = 79
coordBufSize.Y = 2
coordBufSize.X = 80
coordBufCoord.X = 0
coordBufCoord.Y = 0
fSuccess = ReadConsoleOutput(hStdout,chiBuffer,coordBufSize,
& coordBufCoord,srctReadRect)
tmp=GetLastError ()
c That's where I get Error 87
readLength=80
fsuccess2 = ReadConsoleOutputCharacter(hStdout,fullMessage,
& readLength,coordBufCoord,i)
write(*,*)chiBuffer.ASCIIChar,i
tmp=GetLastError ()
write(*,*)chiBuffer.ASCIIChar,tmp
c That's where I get Error 12
Thanks,
JP
Using ReadConsoleOutput, I get Error 87 (ERROR_INVALID_PARAMETER), and using ReadConsoleOutputCharacter, I'm getting Error 12 (ERROR_INVALID_ACCESS). I think my problem is with the declaration of the variables, can anyone help me on this?
The example I'm trying to follow declares chiBuffer as a CHAR_INFO structure of size 160 (two lines of 80 characters). How can I do that in FORTRAN?
Here's the code I have so far...
USE DFWIN
USE KERNEL32
Type(T_CHAR_INFO) chiBuffer
Type(T_COORD) coordBufSize
Type(T_COORD) coordBufCoord
Type(T_SMALL_RECT) srctReadRect
type(T_SECURITY_ATTRIBUTES) lpSecurityAttributes
INTEGER hStdout,hNewScreenBuffer,readLength,i
CHARACTER fullMessage*80
LOGICAL status,fSuccess,fSuccess2
hStdout = GetStdHandle(STD_OUTPUT_HANDLE)
hNewScreenBuffer = CreateConsoleScreenBuffer
& (GENERIC_WRITE,0,lpSecurityAttributes,CONSOLE_TEXTMODE_BUFFER,0)
srctReadRect.Top = 0
srctReadRect.Left = 0
srctReadRect.Bottom = 1
srctReadRect.Right = 79
coordBufSize.Y = 2
coordBufSize.X = 80
coordBufCoord.X = 0
coordBufCoord.Y = 0
fSuccess = ReadConsoleOutput(hStdout,chiBuffer,coordBufSize,
& coordBufCoord,srctReadRect)
tmp=GetLastError ()
c That's where I get Error 87
readLength=80
fsuccess2 = ReadConsoleOutputCharacter(hStdout,fullMessage,
& readLength,coordBufCoord,i)
write(*,*)chiBuffer.ASCIIChar,i
tmp=GetLastError ()
write(*,*)chiBuffer.ASCIIChar,tmp
c That's where I get Error 12
Thanks,
JP
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your "chiBuffer" for ReadConsoleOutput should be a two dimensional array to accept the data for each character cell. You probably have to redefined the interface for ReadConsoleOutput, I don't know what is provided with 6.5 though.
James
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There's more than that; the entire concept is wrong:
ReadConsoleOutput does not accept hStdOut handle (which is basically a file/pipe handle), but handle to screen buffer.
See this MSDN article. You can use READ(*,*) and WRITE(*,*) in the child process instead of ReadFile/WriteFile in the sample.
Jugoslav
hStdout = GetStdHandle(STD_OUTPUT_HANDLE) ... fSuccess = ReadConsoleOutput(hStdout, chiBuffer,coordBufSize, & coordBufCoord,srctReadRect)
ReadConsoleOutput does not accept hStdOut handle (which is basically a file/pipe handle), but handle to screen buffer.
See this MSDN article. You can use READ(*,*) and WRITE(*,*) in the child process instead of ReadFile/WriteFile in the sample.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually, there is nothing wrong with using the standard output handle in this fashion. Now, is there likely a better way, probably, but we don't know what the problem is that needs to be solved.
James
James

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