Author Archives: admin

Public Interfaces

0
Filed under Rants, Software Architecture, VB Feng Shui

image I’m guessing that the vast majority of VB apps (VB6, or .NET), have no public interface. After all, VB is the prototyping language, not an actual project development language, right? </sarcasm>

Well, if you do eventually find yourself in need of exposing a public interface from your application, what’s the right way to do it?

First, a definition, though.

By public interface, I’m talking about some manner of exposing functionality within your application to the outside world. What you do with your BAS files, and private CLS files, not to mention FRM’s, or the all-encompassing  VB.NET *.VB file is your own business. But what the world sees, or, more appropriately, has to deal with, is another matter altogether.

There’s a pile o’ ways to expose functionality from an app, especially a VB app.

First, a few old school methods….

  • DDE – Yeah, it’s still alive. Want proof? Just boot up a copy of Vista, load REGEDIT and search for DDEEXEC in the HKCR hive. But seriously, you don’t want to go there.
  • Windows Messages – SendMessage/PostMessage. They’re not just for subclassing and peeping toms. DDE and even COM relies on the Window Messaging subsystem to work. Your apps can leverage it too. But really, that’s a whole lot of pain for not a lot of gain, so why bother?
  • DLL Entry Points – There are several tools out there that make exposing DLL entry points from a VB application relatively easy to do. In some cases, this is how you have to expose functionality (as in when some other app only makes calls to DLL entry points, and you want that app to talk to yours). But using this technique to expose your own functionality to the world just seems so, well, reagan-omic.

And the more common techniques….

  • COM – The classic VB PUBLIC class. All you gotta do is change your class’s interface type to PUBLICNOTCREATABLE, MULTIUSE, or GLOBALMULTIUSE and biff boom pow! Anyone can use your class, right?
  • .NET Assemblies – Same as COM, but shinier

OK, COM (or .NET assemblies) it is (I’m going to consider the two the same for now, what sacrilege!)

So how do you do it?

There’s piles of books on the mechanics of the task, so I’m not going there. Just look at Kurata’s Doing Objects in Visual Basic 2005 or Dan Appleman’s various books on ActiveX techniques for those kinds of details.

What I’m talking about is which interface design is most appropriate.

Kinds of Interfaces

Generally, I’ve seen these designs gather into 3 camps:

  • The massive wad of hierarchically related objects. This is the Outlook, Word or Excel object models.
  • The single public class containing all the functions you could ever want. Not terribly common; I see it most is 3’rd party utility libraries.
  • And finally, the single class with a single (or at most very limited set of) functions that serve as a “command line” of sorts where you might pass in a parameter that is the “operation” and that additional parameters that are the “arguments for the operation”. The GroupWise API is a great example of this.

The Massive Hierarchical Wad

Pros

  • Easiest to program against. Intellisense, separate objects, etc speed working with your model.

Cons

  • Hardest to keep compatible. Even minor changes from one version to the next of your application can render it incompatible with previous versions of your application, causing loads of headaches for your users.

The Single Class

Pros

  • Relatively easy to program against. Intellisense will help. So does consistent naming of all those methods and properties.
  • Works well for relatively minor amounts of exposed functionality.

Cons

  • Generally considered bad practice.
  • Suffers from compatibility headaches much like the Massive Wad.

The Command Line Class

Pros

  • Essentially immune from direct interface compatibility issues, since the lone interface is flexible enough initially to never have to be changed.

Cons

  • More difficult to code against. Intellisense only helps with the command line function itself, not with each of the commands that can be sent.
  • Moves compatibility issues to the user. If new functions are introduced, it’s the users responsibility to test for the version of the application and react appropriately.

So, what’s the final word?

As usual, there’s really no right answer.

Personally, I tend to stay away from the “Single Class”, simply because it has all the difficulties associated with the Massive Wad, and none of the immunity of the Command Line Class; the worst of both worlds.

The Command Line Class is most useful when your exposed function points number in the 10-100’s. Any more than that, and it starts to become unwieldy, though it’s still perfectly workable.

The Massive Wad is the most traditional, most familiar style of public interface to those who’ve likely used public interfaces of other systems. That’s not to say it’s the best option, just that’s it’s the most typical.

How about it? What kinds of public interfaces have you built and put out there? Is there a style I’ve missed. Maybe something better than any of these?

Setting up a Shortcut to Connect to a Server Console Via Remote Administration

2
Filed under Uncategorized

image It’s pretty trivial to setup a shortcut to an RDP file to allow you to connect to a remote desktop session in Vista (or XP for that matter).

But I needed to remotely connect to the console session.

No big deal, I thought, so I started checking out all the various options available when you EDIT an RDP file.

Nothing there to let you connect to the console.

A quick Google turned up a KB article with the command line switches for mstsc, but it looks like it’s not possible to specify the /CONSOLE option inside the rdp file.

Rats.

Then I thought, why not just create a shortcut to mstsc directly, no RDP file at all.

I ended up with a shortcut using this command line

C:\Windows\System32\mstsc.exe /v:myserver /console /w:1024 /h:768

Just make sure your current user (on your desktop) is a member of Remote Desktop users (and possibly administrators, which I know, would be a “bad thing”).

 

 

image  At that point, just double clicking on the shortcut should drop you right on the console of the server (kicking anyone that was on the console off, BTW, which might be a problem in some environments<g>).

In the end, Remote Admin via Terminal Services still isn’t near as good as UltraVNC, but it does seem to work pretty good. If I had to admin a system that was really remote, I’d probably stick with VNC, but since my server is in the closet, about 10 feet away, Remote Admin is good enough.

Favorite FireFox Extensions

0
Filed under Uncategorized

I’ve seen a few “Best tools” lists over the years, but haven’t ever stumbled across a Best Tools for FireFox list.

So, in the grand tradition of probably reinventing the wheel, but not Googling about it first<g>….

Here’s my (quite short, but sweet), list of Favorite FireFox Extensions:

  • Theme: MacfoxIIGraphite 2.1.4
    OK technically not an extension, this theme really makes for a clean, uncluttered FireFox.
  • Tab Mix Pro 0.3.6
    What tabs in FireFox should have included from the start. Forcing popups to open in tabs is something I can’t do without now.
  • DownLoad Them All 0.9.9.10
    Ok, it’s technically not polite to snarf gobs of files from a site all at once. But, well, sometimes, rude is the word, I suppose.
  • IETab 1.3.3.20070528
    Essential if you want to stay away from opening IE but still need it for those nasty IE only sites (Parature, anyone).
  • DOM Inspector 1.8.1.9
    Quite handy for ripping into an existing webpage to see how it ticks.
  • FireBug 1.05
    Another handy little script debugger as well as CSS editor/debugger . I haven’t used it much to this point, but it seems to work quite well. Maybe there’s a better one someone can clue me in on?
  • Web Developer 1.1.4
    More CSS/DOM spelunking goodness

You can find them all by clicking Tools/Addons in FireFox and then click the Get Extensions link at the bottom right of that screen.

So how about it? Anyone with thoughts on any other really useful FireFox Addons?

This Device Cannot be Started (Code 10)

0
Filed under Uncategorized

image

I had opened up my machine to reformat a spare Harddrive last night. When I buttoned everything back up and restarted, I get network errors.

So I opened up My Computer, Device Manager and lo, my network card was “failing to start” with that wonderful code 10.

My machine has an Intel 975XBX2 motherboard, with those cool blue flame heatsinks<g>.

Pretty much best of breed stuff, and a gigabit net card is built in; swapping out cards was a “only if I absolutely have to” option.

Have you ever noticed that for virtually any other problem on a machine, you can just jump on Google, find the answer and be on down the road? But if your network card goes sour, ouch.

I tried all the obvious stuff, uninstalling the drivers, reinstalling them, using the “Update Drivers” option from Device manager, etc.

I’d almost given up, but then I decided to try one more thing.

The internal LAN adapter can be enabled or disabled through the system BIOS, so I rebooted, got into the BIOS, performed a “Load system Defaults”, then restored all those settings that I had to (like the RAID settings, Numlock off on boot, you know, important stuff), and then set the LAN card to disabled (it’s under Advanced/Peripherals).

Rebooted into Vista and sure enough, now it didn’t see the LAN adapter at all. Good sign.

Shutdown, power off, and restart. Back into the BIOS, reenable  the LAN adapter, save settings, and restart.

Boot back into Vista. Lo and behold, back in business.

Now, if only that 120 gb Western Digital Harddrive I picked up as a spare, would recognize properly and not as just 32gb, I’d be done with hardware (for a few days at least).

Reimagining MsgBox

0
Filed under Code Garage, Software Architecture, VB Feng Shui

Here’s a little trick I’m not sure many people know about, but that I’ve used for so long, I’d basically forgotten about it.

I wrote about overriding the ERR object in VB here, and also wrote a far more involved article about it.

But did you know you can also override the MSGBOX function?

Just create a function with the following signature in a BAS module of your choice:

Public Function MsgBox(ByVal Prompt$, Optional ByVal Buttons As VbMsgBoxStyle = vbOKOnly, Optional ByVal Title$ = "", Optional ByVal HelpFile$ = "", Optional ByVal Context As Long = 0) As VbMsgBoxResult

Put the appropriate code in it, and presto, custom msgbox.

Why, you might ask?

  • Personally, I like the option of logging every msgbox that’s displayed by my app. Errs are handier, but msgbox’s can be useful.
  • In addition, you have the option of calling the MessageBox API call directly yourself, which gives you access to additional flags that you can’t use with the VB version alone.
  • You might also decide that the MSGBOX proper just doesn’t look good, and craft up a modal, nicely skinned form to stand in its place.
  • And finally, in a particular app I worked on, I needed to call a function BEFORE and a different function AFTER displaying every msgbox. I certainly didn’t want to alter every call to MSGBOX and add those extra lines. Overriding it made that a trivial task.

Please let me know if you come up with any good uses for this trick.

Vista and the Phantom Floppy Drive B

2
Filed under Uncategorized

Ok, yeah, it’s probably, um, quaint?, to even have a floppy drive in a Core 2 Duo based machine, but still, that’ no excuse for Vista to mysteriously change my floppy drive to Drive B.

You can’t fix this with the Drive Management dialog, and I couldn’t find any place else to assign a drive letter to the floppy. And there’s no jumpers on floppies, so what the hell?

On a whim, I opened up the Device Manager and started looking for any drive letter controls on the floppy devices.

There weren’t any.

But then, I started wondering if just uninstalling the drivers and letting “scan for new hardware” do it’s thing would work. It usually does for network cards.

So I right-clicked on each and uninstalled the drivers for both the Floppy Drive and Controller:

image

Then right clicked on my computer and chose “Scan for new hardware”. In reality, just rebooting would also work.

A few seconds later, I’m back in the land of the whopping 1.4mb Drive A floppy!

Hey, you can get about a second and a half of HD Video on one of those things. Awesome.

Setting up a USB Memory Stick to Boot in VMWare

0
Filed under Uncategorized

You might think such a thing would be insane to attempt. And why bother?

Here’s a shot of GParted (a Linux based partition editor) booted from a USB stick (in the host machine). It’s quite handy in that it seems to work about as well as Partition Magic. It’ll copy partitions as well.

image

The main reason for all this is that it’s awfully handy to test USB bootable key configurations from a VM instead of having to constantly reboot a real machine. And why a bootable USB configuration? Well, if you’re in IT, you often find yourself sitting at a machine that won’t boot or that needs to low level lovin’ to get it back on track. And things like GParted, Partition Magic, Partition Commander, or SysInternal’s NTFSDOS, not to mention SPintrite can be awfully handy to have swinging from a gold chain around your neck.

One caveat to this. Make SURE you DON’T access the USB key from your host machine while you do this. Doing so will likely trash the formatting on the key. You have been warned, young jedi.

Ok. Here we go…

Make sure you’ve inserted the USB Key and Windows “sees” it (doncha love that bong sound).

Start VMware (it will see the USB if it’s inserted, but it might not see it if you insert the USB key AFTER you’ve started VMWare).

Make sure the virtual machine in VMware is turned off.

image 

Click on the virtual machine settings and click Add:

image 

Choose “Hard Disk” from the device type list, then “Use a Physical Disk”, since we’ll be booting to the USB Key.

Here’s the important part. You should get a window like this:

image

See that drop down list with the PhysicalDrive0 in it? If you drop it down, you should see at least one other drive (Physical Drive 0 is typically the C: drive in your host machine, you DON’T want to use that drive!). In mine, it was PhysicalDrive5. Select which ever one is your USB Key drive.

And select “Use Entire Disk” (unless you’ve partitioned your USB Key drive).

Finally, give it a filename for the vmdk file (that’s a little config file that VMWare uses to keep track of what physical drive is mapped to what virtual drive).

Fire up the VM, and be quick about pressing F2. That’s how you get into the VMware bios for the vm.

image

It might take a few tries to get it, but eventually, you should get to the BIOS screen. Move over to BOOT and press Enter to expand the hard drive options:

image

On my system, that “VMware Virtual Scsi Hard Drive (0:0) entry was listed 3’rd. Use the “+” key to move it up to the top of the boot priority list.

Then save your changes.

If you did everything right, when you reboot the VM, you should boot to your USB drive.

How did I get GParted to actually be able to boot from a memory stick?

I’ve blogged about getting USB memory stick drives bootable here, and here.

But for GParted, there’s a little more wizardry at work. You’ll need to use fat32format to format the drive, then use SYSLINUX to make it linux bootable, then copy the GParted ISO contents to the stick. See the above links for details.

Finally, you’ll need to move a few files.

The root of the GParted image look like this:

image

Nav into the syslinux folder and move all the files there, down to the root of the drive.

Then nav to the boot folder, and move the gparted and gparted.igz files down to the root of the drive.

That should do it. Fire up a VM and give it the boot.

So what have you done with your USB key today? (absconding with company secrets doesn’t count, shame on you!)

No Nonsense Touch Utility

0
Filed under Uncategorized

I have to force timestamps so rarely, I just can’t justify spending money on such a utility.

But writing a little code to do it is annoying, so I went on a little hunt today to find a package that’s simple, quick and easy with little to no installation, drag and drop functionality (command line touch utils are a dime a dozen, after all), and straightforward date entry.

WinTouch fit the bill perfect for what I was looking for.

image

You can drag files to that top list box, set the date/time and go. It’s no Directory Opus, but then, it’s not 85$ either.

Unleash the Fury

0
Filed under Uncategorized

I’m generally not one to pass on those annoying joke emails, but this one (from here) I just can’t resist.

image

A Modern Undo

0
Filed under Uncategorized

I happened across an interesting post about Undo this afternoon.

The author is the guy behind “e – Textmate for Windows“, which looks to be a pretty slick little editor.

Now, I can’t say much to the editor (at least not yet, but I plan on taking a closer look).

But his comments on Undo struck me as particularly prescient.

I’ve had a nagging feeling for years that Undo (even of the “unlimited” variety that’s in just about every app out there now), was not really what it could or should be. The Undo Visualization is particularly nice, as is the idea of branching. I’ve seen something similar in graphics packages before (though I can’t remember which ones off hand). Never seen anything like it in a text editor or IDE, though.

His solution and implementation really points out the inadequacies of the typical modern undo. Granted, some of it might be a little advanced for a casual user. But for a casual user, the standard Ctrl-Z multi level undo should continue to work just fine anyway.