cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
phillipmilne
Level I

Custom DLLs for use in JSL

I want to use the Load DLL() with my own DLL built in Visual Studio. Has anyone done this successfully?

Where can I find sample source code for that shows how to do this on the DLL side.

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: Custom DLLs for use in JSL

Maybe you can get something from tech support; there might be a file called ExtFunctionTests that is a C++ program with a complete set of examples for passing data types in and out of a DLL.

 

Or maybe this will steer in the right direction (this was built in 2009 with whatever version of visual studio was popular at the time. Here are the important sections. "sound" because this DLL was used to let JMP play sound)

 

The JMP interface functions in the DLL:

EXPORTFUNC int __cdecl init( int nCols, int channelMask, int samplesPerSecond, int nRows )
{
	if ( theApp.mSoundThread == NULL )
	{
		theApp.mSoundThread = (SoundThread*)AfxBeginThread( RUNTIME_CLASS(SoundThread), 0, 0, CREATE_SUSPENDED, 0 );
		theApp.mSoundThread->init( nCols, channelMask, samplesPerSecond, nRows );
		theApp.mSoundThread->ResumeThread();
		return 1;
	}
	return 0;
}

EXPORTFUNC double __cdecl feed( double * matrix, int elements )
{
	return theApp.mSoundThread->feed( matrix, elements );
}

LPWSTR g_Declarations = L"\
DeclareFunction(\"init\", Convention( CDECL ), \n\
	Arg( Int32, \"nCols\" ),	Arg( Int32, \"channelMask\" ),	Arg( Int32, \"samplesPerSecond\" ),	Arg( Int32, \"nRows\" ),	Returns( Int32 ) ) << \n\
DeclareFunction(\"feed\", Convention( CDECL ),\n\
	Arg(Double, Array, \"array of nCols channels X nRows samples, -1..+1 \"), Arg(Int32), Returns(Double) );\n\
";



LPCWSTR __stdcall _JMP_Declarations()
{
	return g_Declarations;
}

The .DEF file

; JMPSound.def : Declares the module parameters for the DLL.

LIBRARY      "JMPSound"

EXPORTS
    ; Explicit exports can go here
	_JMP_Declarations
	

The JSL to init the DLL is simple because of the g_Declarations above:

dll = loaddll("C:\Documents and Settings\L\Desktop\JMPSound.dll");
dll<<init(6,1+2+4+8+16+32,48000,3*fullStroke);

"init()" just works. And "feed()" is similar, passing arrays...

	data = leftchan || rightchan || col1:*alternate || col2:*alternate || col3:*alternate || col4:*alternate;
	dll << feed( data, 0 );

(The purpose of the DLL was to accept audio samples through the feed function and play them...while JMP was computing the next set of samples. The threading stuff was specific to this DLL, you don't need to use threads.)

 

 

 

Craige

View solution in original post

5 REPLIES 5
ian_jmp
Level X

Re: Custom DLLs for use in JSL

If you do 'Help > Scripting Index' and search for 'DLL' you should see a number of examples to get you started:

Screenshot 2021-02-12 at 10.49.04.png

Re: Custom DLLs for use in JSL

And there is this entry in the JMP Help for DLLs.

Craige_Hales
Super User

Re: Custom DLLs for use in JSL

See Mark's link for JMP-aware DLLs. I made one, a long time ago. To be clear, there are two kinds: JMP-aware DLLs, and all the rest. A JMP-aware DLL has some extra information that makes it a little easier to use, and probably doesn't have entry points that are unusable. Entry points that use complicated structures and pointers that don't map nicely into JMP data types are probably unusable. 

I'll look and see if I can find it, it is pretty dusty wherever I left it...

Here's an example of a non-aware use of "PlaySound in the multimedia DLL" Audio Note in an Envelope 

@jschroedl 

Craige
Craige_Hales
Super User

Re: Custom DLLs for use in JSL

Maybe you can get something from tech support; there might be a file called ExtFunctionTests that is a C++ program with a complete set of examples for passing data types in and out of a DLL.

 

Or maybe this will steer in the right direction (this was built in 2009 with whatever version of visual studio was popular at the time. Here are the important sections. "sound" because this DLL was used to let JMP play sound)

 

The JMP interface functions in the DLL:

EXPORTFUNC int __cdecl init( int nCols, int channelMask, int samplesPerSecond, int nRows )
{
	if ( theApp.mSoundThread == NULL )
	{
		theApp.mSoundThread = (SoundThread*)AfxBeginThread( RUNTIME_CLASS(SoundThread), 0, 0, CREATE_SUSPENDED, 0 );
		theApp.mSoundThread->init( nCols, channelMask, samplesPerSecond, nRows );
		theApp.mSoundThread->ResumeThread();
		return 1;
	}
	return 0;
}

EXPORTFUNC double __cdecl feed( double * matrix, int elements )
{
	return theApp.mSoundThread->feed( matrix, elements );
}

LPWSTR g_Declarations = L"\
DeclareFunction(\"init\", Convention( CDECL ), \n\
	Arg( Int32, \"nCols\" ),	Arg( Int32, \"channelMask\" ),	Arg( Int32, \"samplesPerSecond\" ),	Arg( Int32, \"nRows\" ),	Returns( Int32 ) ) << \n\
DeclareFunction(\"feed\", Convention( CDECL ),\n\
	Arg(Double, Array, \"array of nCols channels X nRows samples, -1..+1 \"), Arg(Int32), Returns(Double) );\n\
";



LPCWSTR __stdcall _JMP_Declarations()
{
	return g_Declarations;
}

The .DEF file

; JMPSound.def : Declares the module parameters for the DLL.

LIBRARY      "JMPSound"

EXPORTS
    ; Explicit exports can go here
	_JMP_Declarations
	

The JSL to init the DLL is simple because of the g_Declarations above:

dll = loaddll("C:\Documents and Settings\L\Desktop\JMPSound.dll");
dll<<init(6,1+2+4+8+16+32,48000,3*fullStroke);

"init()" just works. And "feed()" is similar, passing arrays...

	data = leftchan || rightchan || col1:*alternate || col2:*alternate || col3:*alternate || col4:*alternate;
	dll << feed( data, 0 );

(The purpose of the DLL was to accept audio samples through the feed function and play them...while JMP was computing the next set of samples. The threading stuff was specific to this DLL, you don't need to use threads.)

 

 

 

Craige
phillipmilne
Level I

Re: Custom DLLs for use in JSL

This is the direction that I want to go. Thanks!
It would be great to have a sample VS Solution/Project to download and compile.