RegisterFunction

RegisterFunction registers a function from a dynamic link library (DLL) to the UniScript symbol table. After a function is registered, the function can be called directly by UniScript.

nValue = RegisterFunction(ssDLL, ssExternalName, ssReturnType, ssInternalName, svParamTypes)

Return Value

nValue is a scalar value greater than 0, if the function was successfully called. In case an error occurred, nValue is one of the following values:

Value Meaning
-1 The DLL ssDLL cannot be found or cannot be loaded.
-2 The function ssExternalName cannot be found in the DLL.
-3 The Parameter ssReturnType is not specified correctly.
-4 The Parameter ssInternalName is not specified correctly.
-5 The Parameter ssParamTypes is not specified correctly.

Parameters

ssDLL

ssDLL is the name of the DLL. If the extension is not specified, the function will use the extension .DLL. If no path name is specified or associated executable modules must be loaded, the function will search for the DLLs in the following order:

  • In the UniPlot directory

  • In the current directory

  • In the Windows System directory

  • In the Windows directory

  • In the directories, specified in the PATH environment variable. Example to add a directory to the PATH environment variable:

    ssPath = getenv("path");
    putenv("path=" ssPath + ";" + ssDir);
    

If the DLL is specified with a full path all DLLs which might be loaded by the given DLL must be located in one of the directories specified above. I one of the DLL cannot be accessed the function returns the error value -1.

ssExternalName

ssExternalName is the external function name. If the name is not found in the DLL, RegisterFunction will return -2. The name is case sensitive. Instead of the name, the ordinal number can be used starting with a # sign, e.g. #123.

ssReturnType

ssReturnType specifies the return value of the function ssExternalName. Possible data types are listed in the table below. In case the function does not return a value, "void" must be specified. Because functions in UniScript always return a value, UniScript will return 1 for such a function. If the function returns a pointer to a structure, "void*" can be specified.

ssInternalName

ssInternalName is the function name used used to call the function from UniScript. The function name must begin with a letter or an underscore, followed by any number of underscores, letters or digits (e.g. ThisIsAValidName).

svParamTypes

svParamTypes is a vector of strings. Each element specifies one data type or the function ssExternalName. The following table specifies possible data types. The left column lists the data type of the function in the DLL. The right column lists the corresponding UniScript data types. When a DLL function is called, UniScript will convert the data to the specified type listed in the left column.

Value Meaning
“void” “void” is used for the Parameter ssReturnType, if the DLL function does not return a value. Because functions in UniScript always return a value, UniScript will return the value 1. “void” for the parameter svParamTypes should only be specified if the function does not have any parameter.
“char” (1 byte) Real scalar or scalar string with one character.
“wchar_t” (2 bytes) Real scalar or scalar string with one unicode character.
“uchar” (1 byte) Real scalar or scalar string with one character.
“short” (2 bytes) Real scalar.
“ushort” (2 bytes) Real scalar.
“int” (4 bytes) Real scalar.
“uint” (4 bytes) Real scalar.
“int64” (8 bytes) Real scalar.
“uint64” (8 bytes) Real scalar.
“size_t” (4 Bytes or 8 Bytes depending on the UniPlot version. For the 64-bit version of UniPlot the size_t is a “unsigned long long”).
“intptr_t” This is the data type for pointers, Size for x86: 4 Bytes, x64: 8 Bytes.
“float” (4 bytes) Real scalar.
“double” (8 bytes) Real scalar.
“fcomplex” (2 * 4 bytes) Complex scalar.
“complex” (16 bytes) Complex scalar.
“void*” Address.
“char*” Address or string scalar.
“wchar_t*” Address oder string skalar.
“uchar*” Address or string scalar.
“byte*” Address of string scalar.
“short*” Address or real vector/matrix.
“ushort*” Address or real vector/matrix.
“int*” Address or real vector/matrix.
“uint*” Address or real vector/matrix.
“int64*” Address or real vector/matrix.
“uint64*” Address or real vector/matrix.
“float*” Address or real vector/matrix.
“double*” Address or real vector/matrix.
“fcomplex*” Complex scalar/vector/matrix.
“complex*” Complex scalar/vector/matrix.

Comment

Caution: The RegisterFunction function can only perform a limited error check. An incorrect call can cause a crash of UniPlot.

Example

The following function call registers the function FindWinowA which is located in the DLL User32.dll. After the registration is finished, the function can be called with its UniScript name "_FindWindow".

RegisterFunction("USER32",..
     "FindWindowA", "uint", ..
     "_FindWindow", ["char*", "char*"]);

Example of _FindWindow function call. The function returns 0 if Excel is not running. The return value is not equal to 0 if Excel is already running.

h = _FindWindow("XLMAIN", strempty(1,1));

Comment

UniPlot 64-bit uses the libffi library - a portable foreign function interface library. This is the copyright notice:

ffi.c - Copyright (c) 1996, 1998, 1999, 2001  Red Hat, Inc.
Copyright (c) 2002  Ranjit Mathew
Copyright (c) 2002  Bo Thorsen
Copyright (c) 2002  Roger Sayle

x86 Foreign Function Interface

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
``Software''), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

History

Version Description
5.20.0 New type “intptr_t”. This type can be used for pointers (x86: 4 Bytes, x64: 8 Bytes).
5.10.0 New types “int64”, “uint64” and “size_t”
5.0.0 New type “wchar_t”.
4.2.0 For svParamTypes the new datatype byte* was added. In opposite to char* and uchar* the result will not be truncated at the first “\x00”-character.

See also

loadlib, loadiclib

id-30251