Scripting Guide > Extending JMP > Dynamic Link Libraries (DLLs)
发布日期: 09/18/2023

Dynamic Link Libraries (DLLs)

You can extend JMP functionality by using JMP Scripting Language (JSL) to load a DLL and call functions exported by that DLL. There is one JSL command and six messages that implement this functionality.

dll_obj = Load DLL("path" <, AutoDeclare(Boolean | Quiet | Verbose) |Quiet | Verbose > )

Load DLL() loads the DLL in the specified path. Use the AutoDeclare(Quiet) argument to suppress log window messaging.

Note: 64-bit JMP cannot load 32-bit DLLs. You must recompile a 32-bit DLL for JMP to be able to load it.

Use the Declare Function message to declare a function that is defined in the DLL.After you declare the function, you can call it.

dll_obj <<Declare Function("name", Convention(named_argument), Alias("string"), Arg(type, "string"), Returns(type), other_named_arguments)

The Alias defines an alternate name that you can use in JSL. For example, if you declared Alias("MsgBox") for a function that is named "Message Box" in the DLL, then you would call it as follows:

result = dll_obj <<MsgBox(...)

Here are the named arguments for Convention:

STDCALL or PASCAL

CDECL

The type argument for both Arg and Returns can be one of the following:

Table 14.2 Types for Arg and Returns

Int8

UInt8

Int16

UInt16

Int32

UInt32

Int64

UInt64

Float

Double

AnsiString

UnicodeString

Struct

IntPtr

UIntPtr

ObjPtr

See Dynamic Link Libraries (DLLs) in the JSL Syntax Reference for the Declare Function message arguments.

Finally, use the UnLoadDLL message to unload the DLL:

dll_obj << UnLoadDLL

Note: Refer to the documentation for that function provided by the DLL author when you declare a function. If the argument types and calling convention declared do not match the actual function in the DLL, calling the function could cause JMP to terminate.

Example

In the following example, the DLL contains a function named netPresentValue, which takes four parameters. Declare Function() defines these parameters and the data type that the function returns so that JMP can successfully call the function.

 
xftdll = Load Dll( "C:\ExtFunctionTests\ExtFunctionTests_x64.dll" ),
 
Show( xftdll );
 
xftdll << Declare Function(
  "netPresentValue",
 Convention( CDECL ),
  Alias( "npv" ), // use this name to call the function in JMP
  Arg( Double, "discount rate" ),
  Arg( Double, "cash flows per period" ),
  Arg( Int32, "number of cash flows" ),
  Arg( Double, Array, "array of cash flow values" ),
  Returns( Double )
);
 
result = xftdll << npv( 0.10, 1, 10, [ 100, 100, 100, 100, 100,
  100, 100, 100, 100, 100 ]
);

Other DLL Messages

The Show Functions message sends any functions that have been declared using Declare Function() to the log:

dll_obj << Show Functions;

If you are writing your own DLL, you can create functions in it using JSL. The Get Declaration JSL message sends any JSL functions in your DLL to the log:

dll_obj << Get Declaration JSL;
需要更多信息?有问题?从 JMP 用户社区得到解答 (community.jmp.com).