Can I expand my SVB by calling external DLLs?
There are two ways in which you can access external libraries from Statistica Visual Basic. The first method is the easiest, but relies on the external DLL's compliance with Visual Basic standards. In other words, if the external DLL (program) supports Visual Basic (e.g., such as Microsoft Excel), you can select Tools - References from the Statistica Visual Basic toolbar to load the respective libraries. The objects, functions, methods, etc. in that library are now accessible like all Statistica Visual Basic functions. So you could, for example, create from within Statistica Visual Basic an Excel Spreadsheet, perform some spreadsheet operations and computations, and then transfer the results back to a Statistica Spreadsheet (e.g., via the .Copy and .Paste methods).
There are a number of things to consider when writing your own DLLs that are to be called by Statistica Visual Basic, or when writing Statistica Visual Basic programs to access functions in such DLLs.
extern "C" int AFX_API_EXPORT WINAPI SampleFunction(int x);
extern "C" void AFX_API_EXPORT WINAPI SampleSubroutine(double q);
where:
extern "C" | means this name is not "decorated" with C++ type information. Because of function overloading (a feature specific to C++), C++ compilers must "decorate" (or add extra unique characters) to function names internally to tell functions with the same names apart from each other. |
AFX_API_EXPORT | is defined to __declspec(dllexport), which tells the compiler to export this name; |
WINAPI | is defined to __stdcall, meaning use "standard calling conventions." |
Private Declare Sub SampleSubroutine Lib _ "C:\DLLTest\Debug\DLLTest" _ Alias "_SampleSubroutine@4" (ByVal X As Integer)
Private Declare Function SampleFunction Lib _ "C:\DLLTest\Debug\DLLTest" _ Alias "_SampleFunction@4" (ByVal X As Integer) _ As Integer
Sub Main
Dim ii As Integer
Dim jj As Integer
jj = 1
ii = SampleFunction(jj)
SampleSubroutine(jj)
End Sub
This assumes that the DLL these routines are located in is DLLTest.dll, and that this DLL is located in the C:\DLLTest\Debug\ directory. Note that if the DLL was located in the system search path (like the SYSTEM32 directory), then only the DLL name is needed.
The Alias statement is used to define the exact name the compiler defines for this function. The __stdcall calling conventions dictate that the function name is prepended by an underscore ("_"), and appended by an at-sign ("@") followed by the size in bytes of all the parameters. Since the example function is passing a 4-byte integer, then the name will have "@4" appended. Note that you can omit the Alias clause if you make an entry in the .DEF file for the custom DLL. If you add an entry for SampleFunction and SampleSubroutine, then the linker will create an alias without the underscore and the @XXX suffix.