XSUB(<file ID>, <ordinal function number> or <function name> {, <parameter1>, <parameter2>...})
XSUB(Interface,1, 5)
XSUB(LogDLL, “_Log_B_of_X”,10,5)
Calls an external subroutine inside a DLL file. XSUB() is perhaps the most powerful statement in
The subroutine inside the DLL must have been compiled as exportable by a Windows 32-bit compiler and have a return type of IEEE format double real. XSUB() will copy the parameters following the function name to a block of memory, then pass the function a pointer to that block of memory.
The function can take only one parameter: a pointer to void. But the function may access any number of parameters through structure overlaying. The function should define a structure to match the type and order of the parameters, and assign the pointer just passed to a pointer to that type of structure. The parameters can then be used through structure overlaying. Integers are passed as four byte values and reals are passed as eight byte IEEE values.
Please Note: For Windows Programmers Only The handle to the run-time simulation frame window will be the last parameter passed. Most subroutines can completely ignore this parameter, but it will be needed if the subroutine displays a window.
Any expression or logic.
<file ID>
The file ID assigned to an external DLL file as defined in the External Files editor. This file should be a 32-bit Windows DLL file.
<ordinal function number>
The ordinal number of the function inside the DLL. This function must be exportable. When DLL’s are compiled, every exported function inside them is numbered. The individual functions can then be accessed by calling the program by number. This field may be an expression that evaluates to an ordinal function number that is valid inside the DLL. Use an ordinal function number or the function name.
<function name>
The name of the function inside the DLL. This function must be exportable. Note that when most compilers compile DLL’s, they adjust the name of the functions inside them. The function name inside the XSUB statement must be the adjusted name, not the original name.
Most C compilers add an underscore to the function name; so a function called “Test1” would be compiled as “_Test1.” For most C++ compilers, valid
<parameters>
The parameters to pass to the function. These may be any variable, number, or expression. They are only limited by the type of field or logic that uses the XSUB function. Each parameter should be separated by a comma. See above for how the external subroutine will access these parameters.
An external function written to the
The
R2 = XSUB(Log, “@Log_B_X$pv”,5.0,R1)
R2 = XSUB(Log, ”_Log_B_X”,5.0,R1)
R2 = XSUB(Log, 2, 5.0, R1)
XSUB.CPP Logic
struct TEST_SUB_PARAMS
{
double base;
double x;
HWND hWndFrame;
};
// This makes it a C function rather than a C++
extern “C”
{
/* On compile, Borland and Microsoft add a leading underscore to a 'C' name! */
double _export Log_B_of_X(void *p)
{
// Parameters come in a
// structure pointed to by p
TEST_SUB_PARAMS * params;
params = (TEST_SUB_PARAMS*) p;
MessageBox (GetTopWindow
(params->hWndFrame),
“Executing Log_B_of_X function.”,
“XSUB”, MB_OK);
return log (params->x) / log(params->base);
}
}
See Also
External Subroutines (normal subroutines are less powerful, but much easier to create and use).
![]() |
© 2012 ProModel Corporation • 556 East Technology Avenue • Orem, UT 84097 • Support: 888-776-6633 • www.promodel.com |