tags:

views:

198

answers:

7

VB6 had a reputation for being too forgiving (and thereby allowing bad practices) and hiding complexities that perhaps developers would be better off needing to know. But I found that, say, 90% of applications could be done in VB6.

But I'd like to see more examples of pushing-the-envelope to work round VB6's limitations. For example, I once found some code for using pointers in VB6 by making calls to the Windows OS. The result was that some string manipulation on largish documents (about 2MB) was brought down from 30 minutes to just over 3 seconds. Does anyone have other examples of going past the limits of VB6?

N.B. not VB.Net.

+5  A: 

One nasty trick was to abuse CallWindowProc to call arbitrary code by passing a pointer to it. This is technically breaking that function's contract, since it's only supposed to be used with handles (not direct code pointers) obtained via GetWindowLong; but in practice so few people actually know this that the implementation is forced to allow arbitrary code pointers. This lets you call any function pointer, so long as it's stdcall, and takes 4 arguments of the same sizes as WndProc arguments.

One even nastier trick that is a consequence of the above is that you can dynamically generate code that way - just stick it in a byte array, and use CallWindowProc to jump to it. This way you can embed non-VB6-produced native code into a VB6 application without any external DLLs. Of course, in this age of NX bit enabled by default, it's probably not such a good idea anymore (if it ever was, that is)...

Pavel Minaev
@Pavel: thank you for your input - just the kind of thing I was looking for.
davek
+3  A: 

I'm not sure what he puts in his sandwiches but pretty much everything found in Matthew Curland's Advanced Visual Basic 6 is push-the-envelope programming usage of VB6. Truly great stuff.

onedaywhen
+1. Don't push the envelope any harder than this, it'll burst!
MarkJ
+3  A: 

Joel said some good stuff about VB6 back in 2001.

Many VB6 programs are spaghetti, either because they're done as quick and dirty one-offs, or because they're written by hack programmers without training in object oriented programming, or even structured programming.

What I wondered was, what happens if you take top-notch C++ programmers who dream in pointers, and let them code in VB6. What I discovered at Fog Creek was that they become super-efficient coding machines. The code looks pretty good, it's object-oriented and robust, but you don't waste time using tools that are at a level lower than you need. I've spent years writing code for C++/MFC and years writing code in Visual Basic, and let me tell you, VB6 is just much, much more productive...

One of the things about Visual Basic 6 is that it doesn't always give you access to the full repertoire of Windows goodies that you need to make a polished application. But what it does do, better than almost any other programming environment, is let you drop into C++ code (or call C APIs) when you're desperate or when you need that extra speed.

That was written in 2001: when creating a new Windows program today, IMHO the obvious choice for best productivity is VB.Net or C#. (JOKE: C# is just Visual Basic with semicolons.)

Getting back to VB6: there are many good examples of how to call C APIs to do something special or just to run faster. Here's some of my favourite links:

MarkJ
@MarkJ: Great resources - thank you. I'd forgotten about Joel's article, too, so thanks for the reminder.
davek
My favourite is Visual Basic Shell Programming by J.P Hamilton
ejspencer
@DaveK. It was reading that particular article that first made me a fan of Joel's blog, so writing this answer was quite nostalgic!
MarkJ
Thanks for the suggestions. The one book I didn't have has been orderd from Ebay.
Tony Toews
+2  A: 

Realizing that most of the Gang of Four design patterns rely on implementing an interface, not inheritance and thus can be easily used in Visual BASIC 6.

Being able to do so greatly improved the design of my CAD/CAM application.

RS Conley
+1  A: 
AngryHacker
+2  A: 

Can't let this question go by without an answer mentioning Bruce McKinney's Hardcore Visual Basic, which is now (wonderfully) available online:

http://vb.mvps.org/hcvb.asp

It's a great read by an author who clearly loves the spirit of Basic.

AakashM
great resource - thank you!
davek
A: 

Paul Caton's Subclassing, continued by LaVolpe (http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=68737) allows you to do whatever you need, hooking into windows events, with no IDE crashing. With this you can implement whatever is necessary in Windows. The samples have crazy things that you may never thought could be possible.

Luis Lobo Borobia