Newb question - external DLLs

Blitz3D Forums/Blitz3D Beginners Area/Newb question - external DLLs

EddieRay(Posted 2004) [#1]
Can someone direct me to some documentation on how to set up calls to functions in an external DLL? In the official B3D docs, I only see "CallDLL" which has a fixed "prototype". However, from some of the forum posts I see what looks like B3D code with ".libs" and ".decls" stuff in it, that appears to be making function prototypes for DLLs... but I just can't find any docs describing those features...

Thanks!

Ed


Kanati(Posted 2004) [#2]
Look up... Specs and Utils. :)


soja(Posted 2004) [#3]
Yes, go to Community->Specs and Utils->Userlib Specification

As you can see, there are numerous examples floating around that use exported WinAPI functions.

<edit> what are the odds? the post sits there for over an hour and then it gets two responses within 10 seconds of each other... =)


Oldefoxx(Posted 2004) [#4]
There are several aspects of external DLLs that you need to consider. First, you have to tell your program what library (DLL) it needs to reference to use some function(s) in that library. You can either give a specific path to the library, or you can leave it to the system to try and locate the library when it is needed. In general, the system will search application-specific paths as found the register, the system directory (usually \windows\system), then the windows directory (usually \windows), then it will search the application directory (where the executable file loaded from), then it will search the current directory (which may be different from the application directory), and finally it will search along the path provided in the environment. If your library can be found, then it will be loaded when needed (and kept in memory until released by all requesting processes).

Second, The function information you provide must match the number of parameters and the type of parameters (or at least the number of bytes per parameter) required for the function. You must also provide an exact name for the function as it is found in the library, since an exact match (including case) is required.

Third, some functions provide multiple ways of processing that are controlled by certain values passed to it. A zero may mean no parameter is passed. A -1 may mean a default parameter is assumed. These parameters are often related to certain constants that may be defined in files related to a given library, such as a header file (.h) for c/c++ programs, or an Include (.INC file with some Basics. You can either define those constants in your own program, or just pass the raw value as a parameter.

Blitz3D assumes that all library (DLL) and external functions will be defined in one or more .DECLS files that may be edited and placed in the \PureBasic\UserLibs folder.
Most Basics (and c/c++) compilers assume you will have both "Include" and "Library" directives to permit certain functions and DLLs to be associated with different programs. But Blitz3D actually acts by adding the external functions to its own internal references, so that all those functions and DLLs become extensions of the Blitz3D environment. The problem at this point, is that I don't see where it also provides for universal recognition of the associated constants that go with these libraries. You do not really need them, because you can use the raw values, but it feels like something left incomplete as a result.

It is a very interesting approach, and gives everyone the ability to enhance their copy of Blitz3D in some unique ways. The down side is that if you mess up a .DECLS file, you can prevent Blitz3D from being able to start up, and if you misidentify a function or its parameters in a given library, it may well prevent a program from running or causing a process crash, terminating your program abnormally. However, if you are careful, and get a good handle on the \PureBasic\UserLibs and .DECLS relationships, you are going to have a lot of fun working with this feature.


EddieRay(Posted 2004) [#5]
Great info... thanks guys!