Re: Win32Lib Release resources

new topic     » goto parent     » topic index » view thread      » older message » newer message

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 blink
PPS you might want a warning if the detach entry cannot be found, or
if rid as passed is -1 (or {-1,-1}).

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu