1. Win32Lib Release resources
- Posted by Tommy Carlier <tommy.carlier at pandora.be> Jun 12, 2004
- 450 views
I know there's a attachCleanup-function where you can attach a cleanup routine, but that's only called when an error occurs. Is there also a similar function to attach a routine that is called when the application ends without errors, so that a library/application can release its resources? -- tommy online: http://users.pandora.be/tommycarlier
2. Re: Win32Lib Release resources
- Posted by Al Getz <Xaxo at aol.com> Jun 12, 2004
- 452 views
Hello there, It's easy to add a cleanup manager to any program. Keep a list of rid's of your local cleanup routines and have each one called as the program exits, for whatever reason. You'll have to find the best spot in the library to call this as it should get called no matter how the process decides to end, barring major catastrophe Take a look at WinClass for an idea how to go about adding it to your library. It's easy Take care, Al And, good luck with your programming! My bumper sticker: "I brake for LED's"
3. Re: Win32Lib Release resources
- Posted by Tommy Carlier <tommy.carlier at pandora.be> Jun 12, 2004
- 459 views
Al Getz wrote: > It's easy to add a cleanup manager to any program. > Keep a list of rid's of your local cleanup routines > and have each one called as the program exits, for > whatever reason. You'll have to find the best > spot in the library to call this as it should get > called no matter how the process decides to end, > barring major catastrophe > Take a look at WinClass for an idea how to go > about adding it to your library. It's easy For an application, it's not hard: just after WinMain(). But for a library, it's not that easy. I could create a cleanup-procedure and ask the programmer that uses the library to call that procedure manually (like I do in Win32Dib), but I want the library to do it automatically. -- tommy online: http://users.pandora.be/tommycarlier
4. Re: Win32Lib Release resources
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Jun 12, 2004
- 440 views
On Sat, 12 Jun 2004 04:06:25 -0700, Tommy Carlier <guest at RapidEuphoria.com> wrote: >For an application, it's not hard: just after WinMain(). But for a >library, it's not that easy. I could create a cleanup-procedure and >ask the programmer that uses the library to call that procedure >manually (like I do in Win32Dib), but I want the library to do it >automatically. Maybe Derek could add something like this (untested) to win32lib: (or like as not he'll tell me the name of a routine which already does this, or explain how they should be attached to the w32HClose of the main window or something else altogether) sequence finalCleanup finalCleanup={} global procedure SetFinalCleanup(object rid) -- -- usage: -- SetFinalCleanup(routine_id("name")) adds a final handler -- with no parameters to the list of routines to be called when -- WinMain terminates. -- SetFinalCleanup({routine_id("name"),{3,5,7}}) adds a final handler -- with three parameters (passed the values shown) to the list of -- routines to be called when WinMain terminates. -- SetFinalCleanup({-1,routine_id("name")}) removes a final handler. -- "name" must be a procedure, not a function! -- if integer(rid) then finalCleanup=append(finalCleanup,{rid,{}}) else if rid[1]=-1 then for i=1 to length(finalCleanup) do if finalCleanup[i][1]=rid[2] then finalCleanup=finalCleanup[1..i-1]& finalCleanup[i+1..length(finalCleanup)] exit end if end for else finalCleanup=append(finalCleanup,rid) end if end if end procedure and at the end of WinMain: for i=1 to length(finalCleanup) do call_proc(finalCleanup[i][1],finalCleanup[i][2]) end for The above should allow several third party libraries to attach and detach cleanup handlers to WinMain, as well as allow a single library to attach several copies of a shutdown routine, eg one for each file open. Regards, Pete PS I did say, but I'll say again, the above is untested, that's Tommy's job PPS you might want a warning if the detach entry cannot be found, or if rid as passed is -1 (or {-1,-1}).
5. Re: Win32Lib Release resources
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 12, 2004
- 438 views
Tommy Carlier wrote: > > I know there's a attachCleanup-function where you can attach a cleanup > routine, but > that's only called when an error occurs. Is there also a similar function to > attach > a routine that is called when the application ends without errors, so that a > library/application > can release its resources? Yes there is . Try including this in your library code. procedure Close_Screen(integer self, integer event, sequence parms) integer lRealId lRealId = getSelf() if lRealId = getId(w32GetMainWindow) then . . . Clean up code goes here . . . end if end procedure setHandler(Screen, w32HClose, routine_id("Close_Screen")) Each library (independant or otherwise) can insert this into their code and expect it to get called when the Main Window is closed. Actually it gets called whenever ANY window closes, so you have to detect when it happens for the main window. That's why the getSelf() call is there. setHandler() will create a chain of event handlers and call each one of them when the event occurs. Note that this will be called prior to any application handler for the w32HClose event on the Main Window itself. Hope this helps. -- Derek Parnell Melbourne, Australia
6. Re: Win32Lib Release resources
- Posted by Tommy Carlier <tommy.carlier at pandora.be> Jun 13, 2004
- 470 views
Derek Parnell wrote: > Each library (independant or otherwise) can insert this into their > code and expect it to get called when the Main Window is closed. Actually > it gets called whenever ANY window closes, so you have to detect when > it happens for the main window. That's why the getSelf() call is > there. > > setHandler() will create a chain of event handlers and call each one of > them when the event occurs. > > Note that this will be called prior to any application handler for the > w32HClose event on the Main Window itself. Thank you, but that doesn't really help: if you look at Win32Dib, you have to call finalizeDib() after you don't need Win32Dib anymore, to release memory allocated by the library. I've seen people forget this. That's why I want the library to do it automatically. If I use your technique, and I use getSelf() to get the window to be closed, there are 2 problems: 1. The w32HClose-event is called after this event, and it might still use Win32Dib-routines. finalizeDib() should be called after all bitmaps are removed (killDib()), preferably after WinMain(). 2. The library doesn't know what the main window is, so it can't compare it to getSelf(). Can't you just call the attachCleanup()-attached routines if the program ends? That would just do it, and I think it's logical: resources shouldn't only be released when an error occurs, but also when no error occurs. -- tommy online: http://users.pandora.be/tommycarlier
7. Re: Win32Lib Release resources
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 13, 2004
- 476 views
Ok for now, if you need to do stuff after the application has completed but before it returns to the DOS prompt, code this into your library...
constant LastEvent = {WM_NCDESTROY,0,0,0} procedure test_for_app_close(integer self, integer event, sequence p) if equal(p, LastEvent) then Do_DIB_Cleanup() end if end procedure setHandler(Screen, w32HAfterEvent, routine_id("test_for_app_close"))
In the meantime, I'll add a cleanup hook to the win32lib library for just this situation. -- Derek Parnell Melbourne, Australia
8. Re: Win32Lib Release resources
- Posted by Tommy Carlier <tommy.carlier at pandora.be> Jun 13, 2004
- 453 views
Derek Parnell wrote: > Ok for now, if you need to do stuff after the application has completed but > before it returns to the DOS prompt, code this into your library... > In the meantime, I'll add a cleanup hook to the win32lib library for just > this situation. Thanks a lot. Although you're not getting paid for Win32Lib, you offer a great support to the users. -- tommy online: http://users.pandora.be/tommycarlier