- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Rather than have a special source for exiting, in that it was an example of a real program as opposed to the real thing, I have moved the code back to the sources. In doing that, I now have an accvio.
I guess I better explain what this does. First there's a handler that's setup. When a number event occurs the handler is called. Parsing for the argument occurs. The code "does the right thing" based on an argument on what event is occurring.
Part of the reason why I am having trouble debugging is that I'm used to a debbuger that uses addresses which MS doesn't. The handler does generate an address but it's not the correct one and because addresses are not used I can't tell how far off I am.
The code is:
SUBROUTINE SetupExit
USE KERNEL32, ONLY: SetConsoleCtrlHandler, BOOL, TRUE
INTEGER(BOOL) :: ff
ff = SetConsoleCtrlHandler(LOC(CloseWindow), TRUE)
END SUBROUTINE SetupExit
FUNCTION CloseWindow(number)
USE KERNEL32, ONLY: BOOL, DWORD, TRUE, FALSE
INTEGER(DWORD), INTENT(IN) :: number
INTEGER(BOOL) :: CloseWindow
!DEC$ ATTRIBUTES STDCALL :: CloseWindow
SELECT CASE (number)
CASE (0) ! Ctrl c
PRINT "('Oi!! Stop pressing Ctrl-C!')"
CloseWindow = TRUE
CASE (1) ! Ctrl break
PRINT "('Ouch!! That Ctrl-Break hurt!')"
CloseWindow = TRUE
CASE (2) ! Console Window close
PRINT "('Wait a tick - I don''t want to go away!')"
CloseWindow = TRUE
CASE DEFAULT ! 5 for log off, 6 for shutdown -
PRINT "('Bye bye!!')"
CloseWindow = FALSE
END SELECT
END FUNCTION CloseWindow
I haven't altered the code yet. It's still Ians.
The first accvio I get is:
Unhandled exception at 0x002ab537 in Adventure.exe: 0xC0000005: Access violation writing location 0x0000000000000000. It occurs when I try to close the window with the X that occurs at the top right of all windows.
Renee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tested your code with a test program and it seems fine. My code is:
[fortran]module my_setconsole contains SUBROUTINE SetupExit USE KERNEL32, ONLY: SetConsoleCtrlHandler, BOOL, TRUE INTEGER(BOOL) :: ff ff = SetConsoleCtrlHandler(loc(CloseWindow), TRUE) continue END SUBROUTINE SetupExit INTEGER(BOOL) FUNCTION CloseWindow(number) !DEC$ ATTRIBUTES STDCALL :: CloseWindow USE KERNEL32, ONLY: BOOL, DWORD, TRUE, FALSE INTEGER(DWORD) :: number SELECT CASE (number) CASE (0) ! Ctrl c PRINT "('Oi!! Stop pressing Ctrl-C!')" CloseWindow = TRUE CASE (1) ! Ctrl break PRINT "('Ouch!! That Ctrl-Break hurt!')" CloseWindow = TRUE CASE (2) ! Console Window close PRINT "('Wait a tick - I don''t want to go away!')" CloseWindow = TRUE CASE DEFAULT ! 5 for log off, 6 for shutdown - PRINT "('Bye bye!!')" CloseWindow = FALSE END SELECT END FUNCTION CloseWindow end module my_setconsole program close_handle USE IFCORE USE my_setconsole implicit none ! Variables logical :: pressed=.false. ! Body of close_handle Call SetupExit print *, 'Hello World' DO WHILE (.NOT. pressed) pressed = PEEKCHARQQ ( ) CALL SLEEPQQ (200) END DO end program close_handle[/fortran]
I've just inserted the subroutines inside a module and I've created a test program. Please try it and tell me if it works for you.
Pedro
Link Copied
- « Previous
-
- 1
- 2
- Next »
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The closing was a wild guess. That file drives Adventure and is open the whole time Adventure is open.
I will be happy to send you the project. That file is the first thing opened after the commons in the source.
Renee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Pedro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How do you use it? I have adventure.zip right here and I can't ship it because that stupid system does not work as far as I can tell......or should I read the release notes? :)
Renee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using the instructions I managed to attach a file. No problem. I think Steve Lionel explanation is concise and clear. I will rate as 5 stars.
Pedro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It was "just" the STOP statement when handling the program close event. I also put the subroutines inside a module. There is another problem with the ctrl+c event. It is related to the fact that the program waits for keyboard user inputs. So it is trapped inside a read statement. I've corrected this in the first question (when it asks if the "gamer" wants help). The function I changed is named "yes". Take a look. If you only want to handle the window close event just forget this.
Pedro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Allow me to tell you a couple of things about me. I was a high ranking engineer for the company that produced the compiler. Steve worked in the same building. We were the second largest computer company in the world. One of the things that made us so good, is that we wouldn't not have settled to such a message to customers. We were meticulous.
This really doesn't bother me. But it's the principle of the the thing. It's sloppy and DEC wouldn't have settled for it. That's why I am as meticulous as I am.
I deeply appreciate what you have done for me.
Renee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No problem. We are here to help each other.
Pedro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Many years ago Igot into a lot of trouble for being (very) late to pick up my daughter because I was engrossed in playing the game and lost track of time.
Mother and daughter have forgiven me, for the moment.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think I know what you mean.
Once again, I'd like to thank Pedro.
Renee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
CNTRL-C will generate no message at all as the windows leaves which is the behavior I am looking for. I know Pedro has worked on CNTRL-Y. Currently without Pedro's fix, CNTRL-Y just shows up on the screen.
What does CNTRL-C do that the others dont do? There has to be a call to get the same behavior that CNTRL-C gets......
Renee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Right now, what I need is a clean exit (without an error message) like what CNTRL-C gets from a console task like Adventure. Right now even a STOP in the SetConsoleCrtlHandler produces a Window Error. What I need is a call like Call Exit(1) that does will not have a error in Fortran. You know...a clean Exit.
Renee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Renee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You were right!!! The STOP was the problem which I never would have guessed.
Thank you so much!!!
Renee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I still don't know why no stop goes in there? By the way, I did not return to the module. Although there is a debugger breakpoint where ever I place, I still can't single step through it.
[bash] INTEGER(BOOL) FUNCTION CloseWindow(number) !DEC$ ATTRIBUTES STDCALL :: CloseWindow USE KERNEL32, ONLY: BOOL, DWORD, TRUE, FALSE implicit none INTEGER(DWORD) :: number CloseWindow = TRUE SELECT CASE (number) CASE (0) ! Ctrl c CASE (1) ! Ctrl break CASE (2) ! Console Window close CASE DEFAULT ! 5 for log off, 6 for shutdown - CloseWindow = FALSE END SELECT END FUNCTION CloseWindow [/bash]The code now looks like the above:
Renee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hitting the breakpoint is not an issue. Single stepping through CloseWindow after I hit the breakpoint is an issue. I still dont understand why it was the stop but the error message was basically about a stack imbalance. I wonder if the the STOP cause that stack imbalance to be reported?
Once again. thank you so much!!!
Renee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- « Previous
-
- 1
- 2
- Next »