If I want to find out about anything in Windows, you have to go through one of the bazillion Enum functions. These creatures take a callback function which they invoke with information on what is being enumerated, along with a variable (typically a void *) that contains data where you can put the results of the information (for example putting it on a list).
Interestingly, there are a few exceptions to the rule. File I/O tends to be of a different character – FindFirstFile(Ex), FindNextFile, FindClose. Of course the person writing the API could have added the word ‘File’ to the end of ‘FindClose’. That way they would all have a matching function style. But there’s no accounting for taste.
We wander over to the C++ (or practically all OO languages) and the design immediately changes to an enumerator. For C++ it’s the iterator, You get an enumerator in Java (and C#). The Enumerator doesn’t look like the old create another stub function to implement this handler trick, the handling code is inside a set of braces ({}).
I presume it’s the vagaries of the different teams working on the solutions to the problem and the fact that at the time people were designing the solutions they didn’t think there was a better way. With the enumerator, the caller keeps the state of the enumeration to themselves, they pass the current item and a pointer to the handling function. When the enumeration is finished you are guaranteed that there is no remaining state left over and that all the handles are cleaned up before you return to the caller.
It seems to be more of a caller vs. callee cleanup exercise. Nowadays we have scoped destruction of objects and garbage collection to deal with the state destruction. What’s more it means that you still aren’t depending on the potential binary instability of the oo function call definition. The typical OO implementation uses an implied this parameter passed to methods to carry the object information. It allows clever developers to create functions that mimic OO methods without actually being functions of the objects themselves.
If you’re clever, you can replace VMT entries with functions of your own creation that can be written in C. Convenient that.
An annoyance of programming Windows is that WinMain must be a static function. If you want to have a WinMain method, you need to perform trickery. One of the most regular methods of doing this is to use SetWindowLongPtr and store the address of the object in the private window information. This has the potential of being quite expensive. Every time you invoke the method you have to issue a GetWindowLongPtr call to extract the pointer, and then indirectly invoke the object’s implementation of WinMain.
There is a more evil mechanism that uses self rewriting code. But that’s for another time.
Cable Guy
This one is annoying – I have to download the meter readings from the diabetic meter for my father. The connection is serial. It’s using some fricking wierd ass connection (looks like a headphone jack) to connect it to the meter. The problem was it was missing. My brother, being a pharmacist has several meter connectors. Every one of them are different. Granted there is an age variation between the hardware, but it’s now cheaper to make a USB connection rather than a plain serial connection and as an added bonus you can use the same connector for all of them! Think of those of us who have to keep one of each effing connection around the shop. What’s worse is that some of them look similar, but don’t work with the meter.
Then let’s not start talking about the reporting software. It’s some ancient thing. It can’t print to a network printer, so I have to print to a pdf and then print the PDF. Granted, there is the if it’s not broke don’t fix it, but I had to rearrange the serial port configuration on the machine – the USB adaptor assigned COM18 for the serial connection, and the software goes to 4. Yes, you read correctly; 4.
Probably something written with visual basic too (cheap shot).
Let’s not talk about power connectors. Most nokia chargers are compatible – but beware of chargers from other countries. Sony-Ericcson have this wierd connection which regulary does not work because of grit in the connector. Motorola change their connectors regularly. I’ve not seen a panasonic phone in a while, but I would not be surprised. That’s just the phones. Then there’s the camera, the PDA, the external hard drive, the iPod, the other PDA.
Curses: E1026
I keep getting this bloody error in the Delphi IDE: E1026 file not found: ‘importcore.drf’
The .drf file varies depending on the project being built. It seems to work itself out after a while (I went looking for bugs).
Politics Test
Who’d a thunk it? I’m a socialist.
You are a Social Liberal (70% permissive)
and an… Economic Liberal (18% permissive)
You are best described as a: Socialist
You too can take The Politics Test on Ok Cupid
This has to make you laugh
It’s time for the Fantasy League… the Indie Fantasy League. Just when you thought it was safe to get out of the house.
Solid snake grows up
Looking at the teaser trailer for Metal Gear Solid 4 for the PS3. Looks really impressive. I hope that it will live up to the trailer hype. I have never really been into consoles, for the simple reason that I can’t easily program them, and that’s part of the fun of computers.
God, but snake looks ancient in this trailer.
Notebook
Tonight is the night to consider changing the simulation routines. Currently they are very hard loops being performed to issue the water and power around the map. It’s guaranteed to work correctly, but it’s awfully slow when the map becomes densely populated.
Ermmm, it’s about midnight, I’m watching ‘Lost In Translation‘. I don’t think I’m going to get much more musings done tonight.
All Upgraded
Well we’re all upgraded to MT-3.2 here. There are a few changes. There’s a bug in the archive listing code – The loop counter is incremented three times, during the loop, rather than the once it should be.
I’ve introduced dynamic theming. The menu option is yet to come, but click the links below to see the different themes on offer.
Old Theme (Using Helvetica) Theme,
Old Theme (Using Verdana) Theme,
Default 3.2 Theme (Vicksburg) Theme,
Beckett Theme,
Folio Theme,
Masala Theme
Powell Street Theme
*** ContextHandlers.pm 2005-09-20 22:34:21.000000000 +0100 --- /home/petesh/.backup/ContextHandlers.pm~ 2005-09-20 22:32:47.000000000 +0100 *************** *** 2162,2171 **** my ($next_cnt, @next_grp) = $group_iter->(); while ((($cnt, @grp) = ($next_cnt, @next_grp)) && defined($cnt)) { my($start, $end) = $sec_ts->($ctx, \@grp); - # Changed by Pete Shanahan - too many i++'s $i++; ($next_cnt, @next_grp) = $group_iter->(); ! $last = 1 if $n && $i >= $n-1; $last = 1 unless $next_cnt; local $ctx->{current_timestamp} = $start; local $ctx->{current_timestamp_end} = $end; --- 2162,2170 ---- my ($next_cnt, @next_grp) = $group_iter->(); while ((($cnt, @grp) = ($next_cnt, @next_grp)) && defined($cnt)) { my($start, $end) = $sec_ts->($ctx, \@grp); $i++; ($next_cnt, @next_grp) = $group_iter->(); ! $last = 1 if $n && $i++ >= $n-1; $last = 1 unless $next_cnt; local $ctx->{current_timestamp} = $start; local $ctx->{current_timestamp_end} = $end; *************** *** 2182,2188 **** return $ctx->error( $builder->errstr ); $res .= $out; $first = 0; ! last if $n && $i >= $n-1; } } else { my $iter = MT::Entry->load_iter({ blog_id => $blog->id, --- 2181,2187 ---- return $ctx->error( $builder->errstr ); $res .= $out; $first = 0; ! last if $n && $i++ >= $n-1; } } else { my $iter = MT::Entry->load_iter({ blog_id => $blog->id,
A link for Rob
I’ve been getting a few podcasts lately. I had subscribed to a few long ones, but had to give up on them – they’re too much like talk radio and a lot less like entertainment. Recently, I was pointed at Spaceship radio, which is public domain radio plays from the 50’s. I’ve only listened to three of them, and all I have to say is that they’re great. I really enjoy the classic radio plays and it being science fiction really brings it into focus for me.
Upgrade duration
Not technically programming, but computers in general. We were upgrading from one server to another last night. Microsoft SBS 2000 -> SBS 2003. The issues were security related. Most of the shares were naïvely configured, so a tightening of the security was on order. All the accounts were changed to Domain Users, from the domain administrators that they had been before. New security groups were added to keep data separate.
The problem was the machines themselves. Currently the machines are running with the account of the login as an administrator of the computer. This should be changable to an ordinary user, as I’ve put the respective privileges into the registry for the BDE.
Long and short of it. The upgrade was scheduled to take 1 hour. It took 2. Reasons – machines upgraded to XP service pack 2 along the way, unforseen security issues as some files within the shares were owned by a domain admin, not by the owner of the containing folder; caused by copying files from one dorectory to another – which brings along the privilege information (NTFS->NTFS). The security is really worth it! honest!
Of course, wireless is not enabled on the network.
Handy link for the day: RunAs with Explorer.