FILE.DLL: 

    A simple dll to handle file io in VB. I know VB has its own file routines which are a little
vexing to use, and there is the Microsoft Scripting Runtime object, however the textstream object
is a "forward only" object and if you want to reposition the file pointer to a prior position, you
have to close and reopen the stream. This dll is simple and flexible and allows movement in either
direction. It uses the low level file routines found in msvcrt.dll which is not available to VB
directly.

    Another reason I created this is to show how simple it is to create a 'C' based dll for VB. For
some reason, this is not well documented. You can find lots of resoures on the internet to make VB
dlls, but none really explain it well and it is not that hard. The stumbling block is pointers. VB
does not make available to the developer pointer routines, and that is a good thing actually. You
can use the Windows api to manipulate pointers but I think it is simpler to let the dll handle
that. VB does however manage pointers for itself. VB can pass information to dlls either by value
(ByVal) or by reference (ByRef) which would be a pointer in C.  However Strings are passed by the
ByVal keyword! Why? because any user defined type, array or string is automatically passed by
reference. So you are actually passing a POINTER to the object which has to be passed "ByVal". You
can pass numerics either way, ByVal works better unless you need the number updated in which case
you use the ByRef keyword. All parameters sent to the dll should have the ByVal or ByRef keyword,
except for the "As Any" type which may or may not need it. VB can also receive char* pointers as a
return type from the dll, but VB sees them as longs and need additional work to get them into a VB
string. Plus you still need to delete the pointer! It is simpler to pass to the dll function a
pointer to a VB string as a parameter to act as the return string, no conversion required.

    The dll receives strings as char* (assuming you are working in C), and can treat it as such.
The same goes for numbers and if you pass numbers using ByRef then the dll function receives them
as pointers like int*. Other types have to be made known to the function with the appropriate
declaration. User defined types are structs in C.

Nothing special has to be done in the c code when dealing with VB data except for the declaration
of the function if it is going to be visible to VB. You need the following

	__declspec( dllexport ) __stdcall 
	
to precede the function declaration. This tells the compiler to make the function public and
establish the order of parameter passing. As far as I know, this syntax is used with all Windows
C/C++ compilers.  

    Microsoft adds a decoration to the dll function name indicating the number of parameters using
the symbol @ and a number that is 4 times the number of parameters. I have never fully understood
why since it is not really required. To VB it is just more characters in the function name. The
reason you can declare api functions without the @n is because the plain names are in the
associated lib file that is normally used. However, you can directly access the dll itself without
using the lib file, just remember you may need to add the "@n" to the function name in the case of
Microsoft dlls. Mingw can make dlls without the @n decoration. This particular dll is an example.


You can send any questions or coments to mredlon@yahoo.com. I am now considering putting some
network functions in a dll for VB.
