home *** CD-ROM | disk | FTP | other *** search
- VBPOINT.LL
- by Jonathan Zuck
- Copyright 1991 User Friendly, Inc.
- "You are hereby granted liscence to use and distribute this DLL along with
- your software. If you distribute the DLL and API to other programers, you
- must distribute it with *at least* all of the files in this ZIP file:
-
- VBPOINT.DLL The DLL for pointer support
- VBPOINT.MAK The VB MAK file for the demo
- VBPOINT.FRM The VB form for the demo
- VBPOINT.TXT This DOC file
-
- As long as this condition is met, you owe no restitution to UFI."
-
- What is VBPOINT.DLL?
- This is a dynamic link library, written in Turbo Pascal for Windows that
- adds some much needed pointer support to Visual Basic. There are two
- exported routines in VBPoint: LP2Str$ and Str2LP.
-
- LP2Str$ is a string function that copies data, pointed to by a so-called
- "Long Pointer" into a Visual Basic proprietary string variable. In many
- instances the long pointer will be the pointer to a null-terminated string
- and many DLLs return this sort of string in their exported functions.
- However, you are by no means limited to string data. This might be a pointer
- to global memory, an integer or an record variable array. Here lies the
- solution to the missing keywords: MK? and BSAVE.
-
- Str2LP is a subroutine that will copy data from one address to another. With
- this function you can create the CV? and BLOAD commands.
-
- When am I passing a long pointer?
- In VB you are passing a long pointer to a DLL routine when pass a string
- variable, using the ByVal keyword and when you pass any other variable
- type without it. This includes passing a record variable or the first
- element of a numeric array.
-
- In a Windows DLL API, you are using a long pointer anytime the variable
- type that is specified begins with the letters 'LP' such as LPSTR, LPVOID
- etc. A number of DLLs return long pointers in their functions. Two that
- come to mind in the Windows API are GetDosEnvironment which returns the
- address of the environment table and GlobalLock which locks an area of
- global memory.
-
- The environment table is an example of one type of string array used in C.
- It is one contiguous blob of memory with each variable separated by a NULL.
- This sort of array is popular in network APIs. So, even though you have
- the ENVIRON$ function in VB, it is instructive to see how to walk through
- one of these sorts of arrays. One of the most powerful things about these
- functions is that you can simply add to the LONG variable and you will
- be pointing further into memory. This is the technique used in the example.
-
- Through a combination of GlobalAlloc and GlobalLock, you could easily
- mimic the functionality of HUGEARR.DLL. All that DLL does is GlobalAlloc
- a big chunk of memory and returns the handle to you. When you want to
- access an element in the array, the DLL does a GlobalLock on the memory
- handle which returns a...that's right class, a long pointer. The DLL
- then calculates the offset into that memory where your data should go
- and you are in business. For simplicity, let's take the example of a huge
- integer array where each element is two bytes: We want 50,000 elements so
- we GlobalAlloc 100,000 bytes. Now we want to insert a value at element
- number 10,000 (or byte 20,000). We GlobalLock the memory handle we got
- back with our call to GlobalAlloc and that returns us a long pointer to our
- memory chunk. We then add 20,000 to that pointer and:
-
- Str2LP (MyInt, ByVal NewPointer&, 2)
-
- Hopefully you start to see the power of this little function!
-
- I hope this was helpful and not too confusing! Eeep! I will try to do an
- even better job of explaining all this in Visual Basic Techniques and
- Utilities coming out first quarter next year. Hope you grab a copy!<g>
-
- Jonathan Zuck
- October 4, 1991
- Washington, DC
-