Scott Hanselman

Screencast: Writing Managed .NET Plugins for the Optimus Mini Three Keyboard

March 8, '07 Comments [9] Posted in Coding4Fun | Learning .NET | Programming | Screencasts | Tools
Sponsored By

Here's a screencast demoing writing Managed .NET Plugins for the Optimus Mini Three Keyboard.

I'm a fan of the Optimus Mini-Three Keyboard for its potential. It's a harbinger of things to come, like someday a complete keyboard with screens for keys. Their hardware is wonderful. But, as a design shop with a specialization in hardware, not software, their software plugin model leaves much to be desired.

When I did my video on an Optimus Mini Three post in managed code, I ended up P/Invoking into their library, bypassing their plugin model and opting instead for a command line experience. Bummer, right?

The Optimus Configurator is pretty, to be sure, but it's programming model is obtuse and trapped in the C++ world. And not the nice OOP C++ world, the nasty part of that world.

The "implement these dozen virtual methods that tunnel strings via magic indexes" world:

virtual BOOL Paint(int button, HDC hdc) = 0;

// to collect INFO_* values from plugin 
virtual LPARAM GetInfo(int index) = 0;

 Meh. When your unmanaged C++ plugin gets called, the configuration app will call your GetInfo at least 20 times, passing in different magic numbers to get information about your plugin like name, webpage, version, etc. Not only are there these internal semantics to grok, there's a whole get/setProperties state bag thing to manage as well.

It's a common pattern for plugins though, especially when you as the host want to provide persistence to your plugins. The Windows Live Writer plugin model is similar...I had to maintain state for my Insert Amazon Links WLW Plugin via the same pattern.

On the other hand, the Paint stuff is very clever, actually. You get an HDC (handle to a device context) passed in, you paint to it, and they handle getting the resulting image over to the Optimus via their USB to Serial Bridge.

Screencast of managed Optimus Mini Three Keyboard PluginsBut, their plugins aren't managed code, and I believe that this more difficult model explains the fact that while the device is selling well, there are only (as of the writing of this post) three 3rd party plugins.

Harald Röxeisen went off (he says after reading my post...Cool!) and has released an alpha of a .NET library for Optimus Support. However, rather than supporting managed plugins in the Optimus Configurator, he's written his own configurator from scratch in .NET, and built a plugin model on top of that. It's basic, but a fantastic start. He proves my point about writing plugins, as even his alpha include THREE all new plugins written against his managed API. Excellent.

For me, I've done the inverse of Harald, and got managed plugins to work inside the existing configurator. After my last post, I got great ideas from Matt Davis of DocumentCommand and Jason Copenhaver. Jason's was managed/unmanaged C++ that would provide a bridge, and Matt's used COM and the .NET COM Interop stuff as a middleman. For me, Matt's was faster as I know that stuff pretty well.

Here's the general idea...Matt's shim implements the C++ virtuals that the configurator expects and calls CoCreateInstance on a known ProgId, in my example it's "Optimus.Nothing." Could be whatever. You'll need one shim and one ProgId per managed plugin as far as I can see. That call to CoCreateInstance is actually activating a .NET assembly that is implementing Matt's COM interface (that we might want to make even more COMish) created via TlbImp. Since we're .NET, the runtime and we get loaded, and wackiness ensues. 

We're in a no-man's land between managed and unmanaged code (and I'm sure we're leaking like a sieve) but we do things like Marshal.StringToHGlobalAnsi(managedString).ToInt32(); and

static int i = 0;
public int Paint(int button, IntPtr HDC)
{
    i++;
    DebugWrite(button);
    using (Graphics g = Graphics.FromHdc(HDC))
    {
        Brush b = ((i % 2 == 0) ? Brushes.Blue : Brushes.Red);
        g.FillRectangle(b, new Rectangle(0, 0, 96, 96));
    }
    if (i > 100) i = 0;
    return 1;
}

...for example. But, happily, we seem to not be noteworthy because the Mini Configurator loads us just fine.

I've approached Harald and perhaps we'll figure out a better bridge for .NET plugins where I could write a plugin that supports his managed API and use it in either his configurator, or the original configurator from Optimus. If I'm going to be promoting writing these plugins, we'll want the interface to hide a lot of the dispatchy stuff, more like the plugin model Bryan Batchelder and I did for the USB Security Key Fobs.

In Harald's .NET configurator, the abstract class you derive from to create a "Harald plugin" is very clean and includes new features like OnKeyHold and OnKeyDoublePress that the Optimus software doesn't make easy. He also, of course, uses BCL types like Bitmap over HDCs.

public abstract class OptimusMiniPlugin
{
    protected OptimusMiniPlugin();
    public abstract void Initialize();
    public virtual void OnKeyDoublePress();
    public virtual void OnKeyDown();
    public virtual void OnKeyHold();
    public virtual void OnKeyPress();
    public virtual void OnKeyRelease();
    public virtual void OnKeyUp();
    public abstract void Repaint();
    public void RequestNextUpdate(TimeSpan interval);
    public abstract void Terminate();
    public abstract void Update();
    public void UpdateImage(Bitmap image);
}

I'm excited to see the possibilities for this little device. Perhaps between my stuff and Haralds (and someone elses?) we can get a Windows Vista Side Show driver working for this thing...probably time for YAGCP (Yet Another Google Code Project). For now, here's what I've got. I'll do a Coding4Fun article on this in much more detail this weekend perhaps, for now, it's just scribbles and it works on my system. ;)

I wonder if the Optimus Keyboard folks care...I hope so. I'm convinced that writing managed plugins is easier than unmanaged (on Windows or in Mono). Is this even worth debating?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Email Signature Etiquette - Too Much Flair?

March 8, '07 Comments [23] Posted in Musings
Sponsored By

The topic came up on a mailing list this morning, when a colleague (whom I respect and am friendly with, to be clear) posted an email where his email signature was, according to Scott Stanfield's measurements, about 810 pixels tall. It is recreated here in a two-page format, because the signature was too long to fit on one page.

I responded, in jest,

Could you speak up? I couldn’t hear you over your email signature…

...and a discussion about Email Signature Etiquette ensued. Adam Cogan has some good suggestions on signatures:

  • They should include the phone number – if you want business
  • They should *not* have the address/location – rarely needed so find it on the website
  • They should have a URL
  • They should have a tag line (Scott: I disagree)
  • They should *not* have the email address
  • I don’t believe in images in footers – although I now have an exception for photos as they make things more personal
  • I believe in a tiny bit of corporate colour – for branding purposes
  • Your big signature should only be included *once* a thread

Looking back in time through the list server, with Scott Stanfield's help, we see a lot of different email signature styles.

Now, none of these are REALLY obnoxious...Some are classy and understated, with small icons as flair:

Some are a little louder and include a picture of a bull horn and a human ear:

 

Some are quick minimalist and to the point. Phone, Messenger, Blog. Full stop. I like.

Some use five different fonts and 7 colors, without being too garish:

Some have the audacity to include a picture of the author's huge head and an animation. Apparently you can get banner ad space on the forehead for a price.

Some have logos and certifications as pictures...

Others include everything there is to know about that person, including a quote from Einstein.

After we teased him, Joel went minimalist, and it was good.

 

The he went more minimalist...

Then he, apparently, became a Buddhist, threw out all his worldly possessions and became like Prince, recognizable only as a symbol. ;)

 

I think a good email signature says what you need it to say without distracting from the message.

As far as the address to my work, my phone number, these are things I'll send them out of band via Plaxo or IM, or whatever. Email is the primary way I start a conversation, and phones, IM, and other things are easily exchanged later, so I don't need them in my sig.

Now, go audit yourself. How long is your signature? Are you including inspirational quotes that might not be germaine to the conversation, or is your address and phone number on 8 lines instead of 2? Maybe we need a Daily WTF for Email Signatures?

If you have some REALLY obnoxious signature examples, post them on flickr, or on your site, link to them in HTML in the comments, or link back to this post.

UPDATE: I've since changed my mind and I'm against pics in signatures. I just have two dashes, then my name and domain. Like this:

--

Scott Hanselman http://hanselman.com

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

NewsBreak RSS Feed Reader and Podcasts on PocketPCs

March 7, '07 Comments [9] Posted in Reviews | Tools
Sponsored By

If you're looking to read feeds on a PocketPC or SmartPhone and listen to podcasts, there's a number of choices. NewsBreak 2.0 just came out, and this site's feed looks pretty decent on it.

While this blog renders pretty nicely on a PocketPC due to DasBlog's mobile support, the site isn't very bandwidth friendly, nor, of course, is it available offline.

The screenshot on the left is the site in PocketIE, and the screenshot next to it (and the one at far right) is my blog's Feed in NewsBreak. Notice that NewsBreak uses ClearType in its reading view - not sure why that's not working in PocketIE or in NewsBreak's view showing list of posts.

   

It also supports podcasts, which is pretty sweet. I'm still evaluating options, but seems to be that $8 for a piece of software is pretty cheap. It supports PocketPCs and SmartPhones.

For now, NewsBreak is US$7.95 until it's not, then it'll be $19.95. Check it out.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Is the Library at Alexandria burning every day? How do we cluster the cluster?

March 7, '07 Comments [4] Posted in Musings
Sponsored By

Stuart discovered splogs today and Jeff learned to lower his blog's bandwidth. Hard learned lessons both, but both got me thinking.

Splogs: If you look at SplogSpot, their weekly splog dump XML file is 56Megs this week. I guess if you filled a library with 90% pron and 10% content (or 99% and 1%) you'd have a pretty interesting library. Does it make things hard to find? Sure, especially if the goo is mixed in along site the good stuff.

Distribution of Responsibility: Jeff's starting to distribute his content. Images here, feed there, markup here. Ideally his images would be referenced relatively in the markup and stored locally, and he'd rewrite the URLs of those images on the way out, be they hosted on S3 or Akamai, or Flickr.

Aside: The Rails guys are definitely ahead of the .NET folks on this stuff, with things like asset_host, and gems that support hosting of files at S3 and elsewhere. Distribution of content and load is a good thing, but only if you can turn it off at any time, and easily. Every external dependency you add is a potential weak point in your content delivery - and content permanence - strategy.

I went looking for something yesterday and found it, I thought, on an old broken-down Tripod.com site. When I got there, however, it was just the text, the links to CSS, some JavaScript and more importantly, images, were long gone.

Broken images on a web site are the equivalent to broken windows in a building; fix them, or they mark the beginning of the end. - Me.
(Call back to old partially-related-but-not-really-but-he'll-tell-me-it-is Atwood post :P )

Which leads us to the Day's Questions:

  • Is the addition of splogs to the Global Index representative of a watering-down of content? Does the proliferation of content-free MySpace pages increase the internet's usefulness, or decrease it?
  • Does the breaking apart of "atoms" of content - like this post, for example - into "quarks" of text, images, styles, etc, all hosted at different locations, affect it's permanence and, forgive me, historical relevance?

I would propose that in both cases, there are emerging problems. Spam and Splogs must exist because there are eyeballs looking at them. Otherwise they (the evil-doers) would stop, right?

Breaking apart content into multiple delivery channels at different hosts helps to offset the cost to host the content. Right now the bandwidth costs for hosting this blog are covered by advertising because I update the blog regularly.

But, if I stopped adding new content, I'd stop getting advertisers, then I'd stop paying the bandwidth bill and the blog would rot. Folks might stumble upon the rotting carcass of this blog in some far-flung theoretical future (like two years from now...WAY out there in Internet Time, people) and find only text, no images, broken javascript and wonder if a library burned? How is content permanence possible? If I don't pay my DNS bill, the site disappears. If my ISP goes out of business, the site disappears. If flickr goes out of business, many photo links on this site disappear. Is it reasonable to depend on these external services?

When the Library at Alexandria was at its peak, apparently 100 scholars lived and worked there. In the time it took to read this sentence, I'm sure 100 MySpacers have joined up. Not exactly scholars, but you get the idea. Things are moving fast, and they aren't lasting long. Some might argue that Wikipedia itself isn't "scholarly" and lowers the bar as well, although I find it useful more often than not. Either way, there's a crapload of information out there with 20% of the planet adding new content everyday.

Alexandria failed because it had no geo-located redundancy. Like the vast majority of of human knowledge, it wasn't clustered. The internet, on the other hand, is a cluster in more ways than one. But is it useful and is its usefulness permanent?

If I may mix my metaphors, is the future of the Internet a worldwide library like Alexandria at its peak, or are we doomed to collectively search a Bathroom Wall for the wisdom of the ages?

I don't know if the flash-mob that is Digg qualifies as a good filter.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

March 2007 My Reading List - Home

March 6, '07 Comments [17] Posted in Musings
Sponsored By

I've been reading less and less lately. It takes about 90 minutes to get Z to sleep, from the time we announce "night-night" through bathtime, and reading of five or six (of his) books, and then rubbing his head until he finally passes out. These aren't things to be rushed, so one has less time to read. Here's what's on my night-stand right now (compared to October last year, and compared to two months before he was born).

  • The State of Africa - I picked this up on our trip to Tanzania in the airport store. It's fantastically dense with information, each chapter is almost a book itself. It feels balanced and thoughtful and the author is well thought of on the 'net and has an extensive bibliography and there's clearly a great deal of research and thought behind the book. I'm still learning, but it sure is whirlwind coverage of the last hundred years in Africa. Recommended if you're interested in the continent.
  • Phantoms in the Brain by V.S. Ramachandran- This was loaned to me by my friend Michael Stanford. It's a very accessible book on neurology, dealing specifically with phantom limbs and phantom pain, and how the body remaps its image of itself. A fascinating read, much lighter than you'd think.
  • Killing Rain (John Rain Thrillers) by Barry Eisler - I love the whole Barry Eisler "Rain" series. John Rain is a half-Japanese, half-American professional assassin who specializes in making it look like a natural death. Because he's in Japan, he doesn't have a car, so there's incredibly detailed (and apparently, accurate) descriptions on how he gets to and from his target's final resting places. He's an assassin on foot, using crowds and organizational behavior to stay in the shadows.
    UPDATE: Barry Eisler, the author, just left a comment below that the sixth installment, Requiem for an Assassin, comes out on May 22! That's so cool. I love blogs.
  • Cell by Stephen King - Folks are picking on this book, but you either like Stephen King or you don't. In this book, the end of civilization starts with a cell phone call...how can you not like a book that starts like that? Can you hear me now?
  • Smoke and Mirrors: Short Fictions and Illusions by Neil Gaiman - I can't remember who in my blog posts recommended Gaiman, but I'm hooked. My family is hooked. My parents are hooked. Stardust the Movie is coming out this summer and I just ordered the BBC Miniseries of Neverwhere, for Pete's Sake. This compilation of short stories is great "bathroom reading." Just put it in there and you'll eventually make it all the way through. 
  • Good Omens: The Nice and Accurate Prophecies of Agnes Nutter, Witch by Neil Gaiman - More Gold from Gaiman (Neil Gaiman blogs here), another Armageddon novel I'm reading, although this one is decidedly "jollyer" than Cell. It involves a mixup in the birth of the Anti-Christ and wackiness ensues along with an unusual partnership between a demon and an angel.
  • The Honor of the Queen (Honor Harrington (Paperback)) by David Weber - Darn that Chris Sells, he told me to read the first Honor Harrington novel and now I have to read all, what, eleven of them? The first one started slow...real slow, and then something like fifty pages in, I was hooked. It's better than Star Trek (in terms of space combat) when Star Trek was great. My dad's hooked too. I keep wanting Angelina Jolie to play Honor in a movie, but that would cheapen it, wouldn't it?

By the way, all the links and pictures in this post were quickly and easily added using my CueCat for Windows LiveWriter Plugin that you can download and use as well!

What are you reading?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.