Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you have examples of push-the-envelope programming usage of VB6?

Tags:

vb6

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.

like image 377
davek Avatar asked Oct 01 '09 06:10

davek


People also ask

What type of language is VB?

Visual Basic is an object-oriented programming language developed by Microsoft. Using Visual Basic makes it fast and easy to create type-safe .

Is Visual Basic and c++ the same?

In brief, Visual Basic refers to a programming language while Visual C++ refers to an IDE. The main difference between Visual Basic and Visual C++ is that Visual Basic is an Object Oriented Programming Language while Visual C++ is an Integrated Development Environment (IDE).

Is VB net high level language?

VB.NET is also known as Visual Basic.NET. It stands for Visual Basic . Network Enabled Technologies. It is a simple, high-level, object-oriented programming language developed by Microsoft in 2002.

Is Visual Basic AC language?

The main difference between VB and C is that VB or Visual Basic refers to an event-driven programming language designed for making computer programming simpler and easier for beginners. On the other hand, C refers to a programming language that is used for the general computer.


4 Answers

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)...

like image 161
Pavel Minaev Avatar answered Sep 19 '22 17:09

Pavel Minaev


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:

  • Karl E Peterson's One Stop VB Shop - his StringBuilder sounds like your example, although it doesn't use API calls
  • Steve McMahon's VBAccelerator
  • And I give +10 for OneDayWhen for listing Matthew Curland's Advanced Visual Basic 6. Probably pushed the envelope further than anyone (and didn't quite burst it).
like image 22
MarkJ Avatar answered Sep 21 '22 17:09

MarkJ


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.

like image 31
onedaywhen Avatar answered Sep 18 '22 17:09

onedaywhen


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.

like image 39
AakashM Avatar answered Sep 17 '22 17:09

AakashM