Declare Statement

Declares an external function in a dynamic link library (DLL).

Syntax
Declare funcName, “dllFile”, “alias” [, (argList)] As type

Parameters

funcName
Specify the name of the function as it will be called from your program.
dllFile
Specify the path and name of the library file as a string enclosed in quotation marks (“”) or as a macro defined by #define.
If there is no path specified, then RC+ will look for the file in the current project directory. If not found, then it is assumed that the file is in the Windows system32 directory. The file extension can be omitted, but is always assumed to be .DLL.
alias
This parameter is optional. The actual name of the function in the DLL or the function index. The name is case sensitive. The alias must be a literal string (characters delimited by quotation marks). If you use an index, you must use a # character before the index. If omitted, a function name specified by funcName can be used as a name of function in DLL.
argList
Optional. List of the DLL arguments. See syntax below.

[ {ByRef | ByVal}​ ] varName [( )] As varType

ByRef
Specify ByRef to refer to a variable of the function to be called. In this case, the argument change in a function can be reflected to the variable of the calling side. You can change the values received as a reference.
ByVal
This is the default setting. Parameters are passed by value (ByVal). Since only values are passed, when the function returns, the variable cannot be changed. Specified when the calling function does not change the value of a variable. This value is optional.
varName
This parameter is required. Name of the variable representing the argument; follows standard variable naming conventions. If you use an array variable as argument, you must specify ByRef.
VarType
This parameter is required. You must declare the type of argument.
Function type
This parameter is required. You must declare the type.

Description
Use Declare to call DLL functions from the current program. Declare must be used outside of functions.

The Declare statement checks that the DLL file and function exist at compile time.

If the error 2473 “Cooperation function with Epson RC+ failed (busy or uninitialized)” occurs, follow the steps below.

  • Make sure the Epson RC+ is connected to the controller. DLL functions are executed on the PC.
  • Use the WindowsStatus function to verify that the DLL call is available.

Passing Numeric Variables ByVal

SPEL: Declare MyDLLFunc, "mystuff.dll", "MyDLLFunc", (a As Long) As Long
VC++ long _stdcall MyDllFunc(long a);

Passing String Variables ByVal

SPEL: Declare MyDLLFunc, "mystuff.dll", "MyDLLFunc", (a$ As String) As Long
VC++ long _stdcall MyDllFunc(char *a);

Passing Numeric Variables ByRef

SPEL: Declare MyDLLFunc, "mystuff.dll", "MyDLLFunc", (ByRef a As Long) As Long
VC++ long _stdcall MyDllFunc(long *a);

Passing String Variables ByRef

SPEL: Declare MyDLLFunc, "mystuff.dll", "MyDLLFunc", (ByRef a$ As String) As Long
VC++ long _stdcall MyDllFunc(char *a);

When you pass a string using ByRef, you can change the string in the DLL. Maximum string length is 255 characters. You must ensure that you do not exceed the maximum length.

Passing Numeric Arrays ByRef

SPEL: Declare MyDLLFunc, "mystuff.dll", "MyDLLFunc", (ByRef a() As Long) As Long
VC++ long _stdcall MyDllFunc(long *a);

Returning Values from DLL Function
The DLL function can return a returning value for any data type, except String.

When it is needed to return string, refer to “Passing String Variables ByRef” described above and specify string variables as an argument.

If string variables are specified to a returning value, error 3614 “You cannot specify a String for Declare return data type.” will occur.

VarType
Following shows table of data type of Epson RC+ 8.0 and variable type of C/C++.

Since there is no data for Epson RC+ 8.0, byte type of C/C++ and structure cannot be used.

Table of data type for Epson RC+ 8.0 and C/C++

Epson RC+ 8.0 C/C++
Boolean short
Byte short
Short short
Integer short
Long int
Real float
Double double
String char [256] * includes Null

For example:

Declare ReturnLong, "mystuff.dll", "ReturnLong", As Long

Function main

    Print "ReturnLong = ", ReturnLong
Fend

See Also
Function...Fend

Declare Statement Example

' Declare a DLL function.
’ Since there is no path specified, the file can be in the current project directory
’ or in the Windows system32 directory

Declare MyDLLTest, "mystuff.dll", "MyDLLTest" As Long

Function main
    Print MyDLLTest
Fend

' Declare a DLL function with two integer arguments and use a #define to define the DLL file name

 #define MYSTUFF "mystuff.dll"

Declare MyDLLCall, MYSTUFF, "MyTestFunc", (var1 As Integer, var2 As Integer) As Integer

’ Define an external function by specifying the full path of the external function
’ in the Declare instruction and specifying the function by index.

Declare MyDLLTest, "c:\mydlls\mystuff.dll", "#1" As Long