1. Another Puzzle
- Posted by Urzumph at HotPOP.com
Aug 28, 2003
/me is good at finding (or falling over, more like) bind bugs
The following Script Works when Interpreted, but not when compiled...
I get Win32Lib error code 461, Failed to aquire a hWnd
The Main Script :
-- code generated by Win32Lib IDE v0.17.0
without warning
include OE-POST.EW
include compress.e
include Win32lib.ew
include Urzwin32Inc.ew
include b_Urzinclude.e
constant BUFFER_SIZE = 4096
-- This is hack'n'slash from COMPRESS.EX the compresso example
integer inp, finp, fout, stream, abufferlen
sequence abuffer
sequence out
procedure do_compress (sequence inpfile,sequence outfile)
-- open the files; report error if cannot open
finp = open (inpfile, "rb")
if (finp = -1) then
fatal_error(inpfile&" cannot be opened!")
end if
fout = open (outfile, "wb")
if (fout = -1) then
fatal_error(inpfile&" cannot be opened for writing!")
end if
-- setup the compression stream
stream = open_compress_stream ()
-- actually move the data
abuffer = get_bytes (finp, BUFFER_SIZE)
while (length (abuffer) >= BUFFER_SIZE) do
out = compress (stream, abuffer)
puts (fout, out)
abuffer = get_bytes (finp, BUFFER_SIZE)
end while
out = compress (stream, abuffer)
puts (fout, out)
-- we're done, so clean up...
out = close_compress_stream (stream)
puts (fout, out)
close (finp)
close (fout)
end procedure
procedure do_decompress(sequence inpfile, sequence outfile)
finp = open (inpfile, "rb")
if (finp = -1) then
fatal_error(inpfile&" cannot be opened!")
end if
fout = open (outfile, "wb")
if (fout = -1) then
fatal_error(inpfile&" cannot be opened for writing!")
end if
-- setup the decompression stream
stream = open_decompress_stream ()
-- actually move the data
abuffer = get_bytes (finp, BUFFER_SIZE)
while (length (abuffer) >= BUFFER_SIZE) do
out = decompress (stream, abuffer)
puts (fout, out)
abuffer = get_bytes (finp, BUFFER_SIZE)
end while
out = decompress (stream, abuffer)
puts (fout, out)
-- we're done, so clean up...
out = close_decompress_stream (stream)
puts (fout, out)
close (finp)
close (fout)
end procedure
object direc
object foobar
sequence calanderevents
atom filehandle
sequence dadate
atom repeatdays
repeatdays = 0
atom repeatcheck
repeatcheck = FALSE
sequence Inf_Repeatlookup
Inf_Repeatlookup = {{"No
Repeat","Daily","Weekly","Fortnightly"},{0,1,7,14}}
direc = dir(mydir() & "calender.cal")
if sequence(direc) then
do_decompress("calender.cal","temp.tmp")
filehandle = open("temp.tmp","r")
calanderevents = get(filehandle)
calanderevents = calanderevents[2]
else
calanderevents = {{{2,8,2003},"TESTEVENT","TEST COMMENT","TEST
TIME","TESTWHO",0}}
end if
-- calanderevents = {{dadate,Eventname,Comemnts,Start/Fin time,Who,atom
repeatdate},{dadate,Eventname,Comemnts,Start/Fin time,Who,atom repeatdate}}
----------------------------------------------------------------------
function repeat_applies(sequence event)
sequence startdate
sequence datecomparereturn
if length(event) > 5 and event[6] != 0 then
startdate = event[1]
datecomparereturn = Date_Compare(startdate,dadate)
if compare(datecomparereturn,"SAME") = 0 then
return TRUE
end if
while compare(datecomparereturn,"BEFORE") = 0 do
startdate =
add_days(startdate[1],startdate[2],startdate[3],
event[6])
datecomparereturn = Date_Compare(startdate,dadate)
if compare(datecomparereturn,"SAME") = 0 then
return TRUE
end if
end while
-- we have made it after the date without hitting the date
return FALSE
end if
end function
--------------------------------------------------------------------------------
-- Window Window1
constant Window1 = createEx( Window, "Little Black Calender, By
Urzumph", 0, Default, Default,
416, 529, 0, 0 )
--EZdumpinit(routine_id("do_w32dump"),routine_id("Windump"),{Window1})
send2dump("It Worked.... yay")
constant MonthCalendar2 = createEx( MonthCalendar, "MonthCalendar2",
Window1, 32, 20, 250, 200,
0, 0 )
object EditText3
EditText3 = createEx( EditText, "", Window1, 32, 248, 272, 28, 0,
{WS_BORDER} )
object EditText4
EditText4 = createEx( MleText, "", Window1, 32, 300, 272, 56, 0,
{WS_BORDER} )
object EditText5
EditText5 = createEx( MleText, "", Window1, 32, 380, 272, 40, 0,
{WS_BORDER} )
object EditText6
EditText6 = createEx( MleText, "", Window1, 32, 448, 272, 40, 0,
{WS_BORDER} )
constant PushButton8 = createEx( PushButton, "Save", Window1, 308, 228,
88, 28, 0, 0 )
constant PushButton9 = createEx( PushButton, "Add Event", Window1, 308,
300, 88, 28, 0, 0 )
constant LText10 = createEx( LText, "Event Name", Window1, 32, 224, 148,
20, 0, 0 )
constant LText11 = createEx( LText, "Comments", Window1, 32, 280, 148,
20, 0, 0 )
constant LText13 = createEx( LText, "Start/Finnish Time", Window1, 32,
356, 148, 20, 0, 0 )
constant List14 = createEx( List, "Event List", Window1, 300, 32, 72,
188, 0, 0 )
constant LText15 = createEx( LText, "Who", Window1, 32, 424, 148, 20, 0, 0 )
constant List18 = createEx( List, "List18", Window1, 312, 340, 76, 152,
0, 0 )
constant PushButton21 = createEx( PushButton, "Delete Record", Window1,
308, 264, 88, 28, 0, 0 )
for i = 1 to length(Inf_Repeatlookup[1]) do
addItem( List18, Inf_Repeatlookup[1][i] )
end for
foobar = getSelectedDate ( MonthCalendar2 )
dadate = {foobar[4],foobar[2],foobar[1]}
---------------------------------------------------------
procedure MonthCalendar2_onChange (integer self, integer event, sequence
params)--params is ()
--do load list
-- params = ({yyyy,mm,??,dd},{yyyy,mm,??,dd}}
-- calanderevents = {{dadate,Eventname,Comemnts,Start/Fin time,Who,atom
repeatdate}}
sequence repeathelper
sequence datecomparereturn
if compare(params,{}) != 0 then
send2dump("Date changed to
"&sprint({params[1][4],params[1][2],params[1][1]}))
eraseItems( List14 )
dadate = {params[1][4],params[1][2],params[1][1]}
for i = 1 to length(calanderevents) do
if compare(calanderevents[i][1],dadate) = 0 then
addItem( List14, calanderevents[i][2] )
end if
end for
for i = 1 to length(calanderevents) do
if length(calanderevents[i]) > 5 and calanderevents[i][6]
!= 0 then
repeathelper = calanderevents[i][1]
datecomparereturn = Date_Compare(repeathelper,dadate)
while compare(datecomparereturn,"BEFORE") = 0 do
repeathelper =
add_days(repeathelper[1],repeathelper[2],repeathelper[3],
calanderevents[i][6])
datecomparereturn = Date_Compare(repeathelper,dadate)
if compare(datecomparereturn,"SAME") = 0 then
addItem( List14, calanderevents[i][2] )
end if
end while
end if
end for
end if
end procedure
setHandler( MonthCalendar2, w32HChange,
routine_id("MonthCalendar2_onChange"))
--------------------------------------------------------------------------------
procedure List14_onChange (integer self, integer event, sequence
params)--params is ()
-- load text boxes
atom index
sequence eventname
atom calandereventindex
calandereventindex = 0
index = getIndex( List14 )
eventname = getItem( List14, index )
for i = 1 to length(calanderevents) do
if compare(calanderevents[i][1],dadate) = 0 and
compare(calanderevents[i][2],eventname
) = 0 then
calandereventindex = i
end if
end for
if calandereventindex != 0 then
destroy( EditText3 )
destroy( EditText4 )
destroy( EditText5 )
destroy( EditText6 )
EditText6 = createEx(
EditText,calanderevents[calandereventindex][5], Window1, 32, 448,
272, 40, 0, {WS_BORDER} )
EditText5 = createEx(
EditText,calanderevents[calandereventindex][4], Window1, 32, 380,
272, 40, 0, {WS_BORDER} )
EditText4 = createEx(
EditText,calanderevents[calandereventindex][3], Window1, 32, 300,
272, 56, 0, {WS_BORDER} )
EditText3 = createEx(
EditText,calanderevents[calandereventindex][2], Window1, 32, 248,
272, 28, 0, {WS_BORDER} )
end if
end procedure
setHandler( List14, w32HChange, routine_id("List14_onChange"))
--------------------------------------------------------------------------------
procedure PushButton8_onClick (integer self, integer event, sequence
params)--params is ()
-- save & compress
atom postreturnval
send2dump("Save Clicked")
filehandle = open("temp.tmp","w")
if filehandle = -1 then
error("temp.tmp cannot be opened for writing!")
else
print(filehandle,calanderevents)
close(filehandle)
do_compress("temp.tmp","calender.cal")
postreturnval = sendfile ( "anemail at Hotpop.com", "Cal Update", mydir()
& "calender.cal")
if postreturnval != 0 then
fatal_error("Failed to send mail to outlook express!
("&mapi_error[postreturnval+1]&")")
end if
error("Please Open outlook Express and send this mail.")
end if
end procedure
setHandler( PushButton8, w32HClick, routine_id("PushButton8_onClick"))
--------------------------------------------------------------------------------
procedure PushButton9_onClick (integer self, integer event, sequence
params)--params is ()
atom finder
sequence tosave
atom calandereventindex
calandereventindex = 0
--text = getText( TheTextEdit )
tosave =
{dadate,getText(EditText3),getText(EditText4),getText(EditText5),getText(
EditText6
),
repeatdays}
for i = 1 to length(calanderevents) do
if compare(calanderevents[i][1],tosave[1]) = 0 and
compare(calanderevents[i][2],tosave
[2])
= 0 then
calandereventindex = i
end if
end for
if calandereventindex = 0 then
calanderevents = append(calanderevents,tosave)
end if
MonthCalendar2_onChange (0, 0, {{dadate[3],dadate[2],0,dadate[1]},{}})
end procedure
setHandler( PushButton9, w32HClick, routine_id("PushButton9_onClick"))
procedure PushButton21_onClick (integer self, integer event, sequence
params)--params is ()
sequence name
sequence thelist
atom loopy
atom index
thelist = {}
index = getIndex( List14 )
if index != 0 then
name = getItem( List14, index )
for i = 1 to length(calanderevents) do
if compare(calanderevents[i][2],name) = 0 then
thelist = append(thelist,i)
end if
end for
if length(thelist) > 1 then
loopy = 1
for i = 1 to length(thelist) do
if repeat_applies(calanderevents[thelist[loopy]]) = FALSE then
thelist = delete_element(thelist,i)
else
loopy +=1
end if
end for
end if
if length(thelist) > 1 then
for i = 1 to length(thelist) do
if compare(calanderevents[thelist[i]][2..5],
{getText(EditText3),getText(EditText4),getText(EditText5),getText(EditText6)})
!= 0 then
thelist = delete_element(thelist,i)
end if
end for
end if
calanderevents = delete_element(calanderevents,thelist[1])
MonthCalendar2_onChange (0, 0, {{dadate[3],dadate[2],0,dadate[1]},{}})
end if
end procedure
setHandler( PushButton21, w32HClick,
routine_id("PushButton21_onClick"))
procedure List18_onChange (integer self, integer event, sequence
params)--params is ()
-- load text boxes
atom index
sequence repeatname
atom check
index = getIndex( List18 )
repeatname = getItem( List18, index )
check = Inf_Lookup(Inf_Repeatlookup,repeatname)
if check != -1 then
repeatdays = check
else
error("The impossible has happened! check = -1 in procedure
List18_onChange")
end if
end procedure
setHandler( List18, w32HChange, routine_id("List18_onChange"))
WinMain( Window1,Normal )
Now, the include files :
include OE-POST.EW
-- Part of the E-Post MAPI library, used in the Save button (pushbutton 8)
include compress.e
--Compresso v. 1.1 by Rob Jackson
include Win32lib.ew
-- Win32Lib 0.59.1
include Urzwin32Inc.ew
-- My Windows Library
Relavent sections here :
integer PopupWindow
integer LabeLPopup
integer PopupOKButton
procedure closewindow (integer self, integer event, sequence
params)--params is ()
closeWindow (PopupWindow)
end procedure
procedure quit (integer self, integer event, sequence params)--params is ()
abort(0)
end procedure
global procedure error(sequence sequence_to_popup)
PopupWindow = createEx( Window, "Something Happened!", 0, Default,
Default, 400, 153, 0, 0 )
LabeLPopup = createEx( LText, sequence_to_popup, PopupWindow, 32, 16,
324, 52, 0, 0 )
PopupOKButton = createEx( PushButton, "Ok!", PopupWindow, 88, 72, 192,
48, 0, 0 )
setHandler(PopupOKButton, w32HClick, routine_id("closewindow"))
openWindow(PopupWindow, Normal)
end procedure
global procedure fatal_error(sequence sequence_to_popup)
PopupWindow = createEx( Window, "Something Happened!", 0, Default,
Default, 400, 153, 0, 0 )
LabeLPopup = createEx( LText, sequence_to_popup, PopupWindow, 32, 16,
324, 52, 0, 0 )
PopupOKButton = createEx( PushButton, "Ok!", PopupWindow, 88, 72, 192,
48, 0, 0 )
setHandler(PopupOKButton, w32HClick, routine_id("quit"))
openWindow(PopupWindow, Normal)
end procedure
include b_Urzinclude.e
the beta EZdump version of my personal library, it's quite large > 1.5k
lines, so here are all the bits I think are relavent. If I am missing
anything, give a shout.
global constant notok = -1
global constant statnotok = "notok"
global constant on = 0
global constant off = -1
global constant ok = 0
global constant TRUE = 0
global constant FALSE = -1
object foobar
global atom dump
global atom dump_location
global atom searchseqdumplength
searchseqdumplength = 10
dump = off
dump_location = 0
global atom dumproutine
dumproutine = -1
-- EZ DUMP :
-- for windows applications, initialize with
--EZdumpinit(routine_id("do_w32dump"),routine_id("Windump"),{%MainWindowHandle%})
-- for DOS / Console Linux
--EZdumpinit(routine_id("do_dump"),routine_id("dosdump"),{%Filehandle (
1 for screen)%})
-----------------------------------------------------------------------------------
global procedure dosdump(sequence data)
puts(dump_location,data)
end procedure
-----------------------------------------------------------------------------------
global procedure do_dump(atom filehandle) -- for dump to screen, use
filehandle = 1
dump_location = filehandle
puts(dump_location,"Starting Dump :\n")
end procedure
----------------------------------------------------------------------------------
global procedure EZdumpinit(atom routineidinit,atom dumpID,sequence params)
dump = on
dumproutine = dumpID
call_proc(routineidinit, params)
end procedure
---------------------------------------------------------------------------------------
global procedure send2dump(sequence dumpdata)
if dumproutine != -1 then
call_proc(dumproutine,{dumpdata})
end if
end procedure
--------------------------------------------------------------------------------------
global function search(sequence tosearch,object tofind)
atom tosearchdepthchecker -- dump use only
tosearchdepthchecker = 0
if dump = on then
for i = 1 to length(tosearch) do
if sequence(tosearch[i]) then
tosearchdepthchecker = 1
end if
end for
if tosearchdepthchecker = 1 then
if length(tosearch) < searchseqdumplength then
send2dump(SMMP({{"u","Search> Called. Searching "},{"r",tosearch},{"u","
for "},{"u",tofind},{"u","\n"}}))
else
send2dump("Search> Called. Sequence to long to be stated, increase
length if nessisary\n")
end if
else
if length(tosearch) < searchseqdumplength then
send2dump(SMMP({{"u","Search> Called. Searching "},{"u",tosearch},{"u","
for "},{"u",tofind},{"u","\n"}}))
else
send2dump("Search> Called. Sequence to long to be stated, increase
length if nessisary\n")
end if
end if
end if
if length(tosearch) > 0 then
for i = 1 to length(tosearch) do
if compare(tosearch[i],tofind) = 0 then
if dump = on then
send2dump(SMMP({{"u","Search> returned "},{"r",i},{"u","\n"}}))
end if
return i
end if
end for
if dump = on then
send2dump(SMMP({{"u","Search> failed. (not found)"},{"u","\n"}}))
end if
return notok
else
if dump = on then
send2dump(SMMP({{"u","Search> failed. (length toseaerch <=
0)"},{"u","\n"}}))
end if
return notok
end if
end function
-----------------------------------------------------------------------------------
global function delete_element(sequence SEQ,atom elementnumber)
if dump = on then
send2dump(SMMP({{"u","Delete Element> Called. Deleting
"},{"r",elementnumber},{"u"," ( "},{"r",SEQ[elementnumber]},{"u","
)"},{"u","\n"}}))
end if
if elementnumber = 1 then
SEQ = SEQ[2..length(SEQ)]
elsif elementnumber = length(SEQ) then
SEQ = SEQ[1..length(SEQ)-1]
else
SEQ = SEQ[1..elementnumber-1] & SEQ[elementnumber+1..length(SEQ)]
end if
return SEQ
end function
-----------------------------------------------------------------------------------
-----------------------------------------------------------Date
Handling.....
global function daysinmonthlookup(atom month,atom year)
if month = 1 or month = 3 or month = 5 or month = 7 or month = 8 or
month = 10 or month = 12 then
return 31
end if
if month = 4 or month = 6 or month = 9 or month = 11 then
return 30
end if
if month = 2 then
if remainder(year,4) > 0 then
return 28
elsif remainder(year,4) = 0then
return 29
end if
end if
return notok
end function
global function add_days(atom day, atom month,atom year,atom daystoadd)
--if dump = on then
-- puts(dump_location,"add_days starting :\n")
-- puts(dump_location,"day : "&sprint(day) & "\n")
-- puts(dump_location,"month : "&sprint(month)& "\n")
-- puts(dump_location,"year : "&sprint(year)& "\n")
-- puts(dump_location,"days2add : "&sprint(daystoadd)& "\n")
-- puts(dump_location,"\n")
--end if
-- Commented because taking tooooooo much room in dump logs
while day + daystoadd > daysinmonthlookup(month,year) or month > 12 do
--if dump = on then
-- puts(dump_location,"add_days looping :\n")
-- puts(dump_location,"day : "&sprint(day) & "\n")
-- puts(dump_location,"month : "&sprint(month)& "\n")
-- puts(dump_location,"year : "&sprint(year)& "\n")
-- puts(dump_location,"days2add : "&sprint(daystoadd)& "\n")
-- puts(dump_location,"\n")
--end if
if month > 12 then
if dump = on then
puts(dump_location,"month > 12 (month = " &
sprint(month) &" ) \n")
end if
year += 1
month -= 12
end if
if day+daystoadd > daysinmonthlookup(month,year) then
--if dump = on then
--puts(dump_location,"day + daystoadd ( " &sprint(day)
& " + " & sprint(
--daystoadd
--
) &
-- " ) > "
-- & sprint(daysinmonthlookup(month,year)) & "\n")
--end if
daystoadd -= daysinmonthlookup(month,year)
month +=1
end if
end while
day += daystoadd
return {day,month,year}
end function
global function minus_days(atom day, atom month,atom year,atom daystoadd)
--if dump = on then
-- puts(dump_location,"minus_days starting :\n")
-- puts(dump_location,"day : "&sprint(day) & "\n")
-- puts(dump_location,"month : "&sprint(month)& "\n")
-- puts(dump_location,"year : "&sprint(year)& "\n")
-- puts(dump_location,"days2minus : "&sprint(daystoadd)& "\n")
-- puts(dump_location,"\n")
--end if
while day - daystoadd < 1 or month < 1 do
--if dump = on then
-- puts(dump_location,"minus_days looping :\n")
-- puts(dump_location,"day : "&sprint(day) & "\n")
-- puts(dump_location,"month : "&sprint(month)& "\n")
-- puts(dump_location,"year : "&sprint(year)& "\n")
-- puts(dump_location,"days2minus : "&sprint(daystoadd)& "\n")
-- puts(dump_location,"\n")
--end if
if month < 1 then
if dump = on then
puts(dump_location,"month < 1 (month = " &
sprint(month) &" ) \n")
end if
year -= 1
month += 12
end if
if day-daystoadd < 1 then
--if dump = on then
-- puts(dump_location,"day - daystoadd ( " &sprint(day)
& " - " & sprint(
-- daystoadd
--
) &
-- " ) < 1\n")
--end if
day += daysinmonthlookup(month,year)
month -=1
end if
end while
day -= daystoadd
return {day,month,year}
end function
global function Date_Compare(sequence testee,sequence tester)
if testee[3] != tester[3] then
if testee[3] < tester[3] then
return "BEFORE"
elsif testee[3] > tester[3] then
return "AFTER"
end if
elsif testee[2] != tester[2] then
if testee[2] < tester[2] then
return "BEFORE"
elsif testee[2] > tester[2] then
return "AFTER"
end if
elsif testee[1] != tester[1] then
if testee[1] < tester[1] then
return "BEFORE"
elsif testee[1] > tester[1] then
return "AFTER"
end if
else
return "SAME"
end if
end function
----------------------------------------------------------------------------------------------
global function SMMP(sequence TPP) -- Sequence MultiPutsPrint
sequence toret
for i = 1 to length(TPP) do
if compare(TPP[i][1],"u") = 0 then
toret &= TPP[i][2]
elsif compare(TPP[i][1],"r") = 0 then
toret &= sprint(TPP[i][2])
end if
end for
return toret
end function
-----------------------------------------------------------------------------------------------
global function write_Inf_Var(sequence InfVar,object Var,object
towrite,atom overwrite)
atom searchreturn
if dump = on then
send2dump(SMMP({{"u","WriteInf> called. "},{"u"," Var =
"},{"u",Var},{"u","/"},{"r",Var},{"u"," towrite =
"},{"r",towrite},{"u","\n"}}))
end if
searchreturn = search(InfVar[1],Var)
if searchreturn = notok or overwrite = on then
InfVar[1] = append(InfVar[1],Var)
InfVar[2] = append(InfVar[2],towrite)
end if
return InfVar
end function
----------------------------------------------------------------------------------------
global function Inf_Lookup(sequence InfVar,object Var)
atom searchreturn
if dump = on then
send2dump(SMMP({{"u","InfLookup> called. "},{"u"," Var =
"},{"u",Var},{"u","/"},{"r",Var},{"u","\n"}}))
end if
searchreturn = search(InfVar[1],Var)
if searchreturn != notok then
if dump = on then
send2dump(SMMP({{"u","InfLookup> Var Found. Returning
"},{"r",InfVar[2][searchreturn]},{"u","\n"}}))
end if
return InfVar[2][searchreturn]
else
if dump = on then
send2dump(SMMP({{"u","InfLookup> Not Found."},{"u","\n"}}))
end if
return notok
end if
end function
-------------------------------------------------------------------------------------------
global function Rev_Inf_Lookup(sequence InfVar,object Val)
atom searchreturn
if dump = on then
send2dump(SMMP({{"u","RevInfLookup> called. "},{"u"," Value =
"},{"r",Val},{"u","\n"}}))
end if
searchreturn = search(InfVar[2],Val)
if searchreturn != notok then
if dump = on then
send2dump(SMMP({{"u","RevInfLookup> Value Found. Returning
"},{"r",InfVar[1][searchreturn]},{"u","\n"}}))
end if
return InfVar[1][searchreturn]
else
if dump = on then
send2dump(SMMP({{"u","RevInfLookup> Not Found."},{"u","\n"}}))
end if
return notok
end if
end function
------------------------------------------------------------------------------------------------
I Think That's it, lol
When I am less tired, and have more time (at least a week away), I'll
try and see specifically what the problem is and post a smaller example, lol