Subscribe Bookmark RSS Feed

Using a delphi dll from JMP

swaiper

Community Trekker

Joined:

Apr 28, 2015

Hi,

I want to create a dll in Delphi to save differents graphs in JMP. I know the <<Save Function() work, but impossible to personalize it.

I have try this code :

dll_obj = Load DLL("C:\Users\rroustan\Desktop\Delphi\first dll\Win32\Debug\Project1.dll");

result = dll_obj << CallDLL( "AddIntegers", "n", 2 );

show(result);

dll_obj << UnLoadDLL

But in register  I saw this :

result = .;

My function in the dll just return the number 2.

How can I receive this number ?

Thanks per advance,

Sincerely

7 REPLIES
Eric_Hill

Staff

Joined:

Oct 1, 2013

Hey, swaiper,

The first question is, is the function AddIntegers exported by your DLL, so external programs that load your DLL can call the function?  To determine this, you can run DUMPBIN.EXE, as follows, in the directory where your DLL is located:

dumpbin /exports Project1.dll

That will dump out a list of symbols that are exported by your DLL, and we can see if AddIntegers is there.

Also, what version of JMP are you using?  There is an improved DLL interface that I believe shipped in JMP 10 that may give us better diagnostic information.

Thanks,

Eric

swaiper

Community Trekker

Joined:

Apr 28, 2015

Hi,

Thank you for your answer.

I'm actually using the 12 version of JMP.

I try to create a test program in delphi and it work fine. I get the result.

I think I need to use this to have an answer by the DLL :

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

Eric_Hill

Staff

Joined:

Oct 1, 2013

Hey, swaiper,

Yes, Declare Function is part of the "improved DLL interface" I mentioned.  The DLL interface that existed previously that supported only 3 fixed function signatures did *not* support returning a value, as you've figured out.  But Declare Function does allow you to declare the return type of the function and then get it back in JSL.  Something close to this should work:

dll << DeclareFunction( "AddIntegers", Convention( STDCALL ),

   Arg( Int32 ), Arg( Int32 ), Returns( Int32 ) );

That declares a function named AddIntegers that takes two integer arguments and returns an integer.  You just need to make sure that the Convention argument matches what you specified on your function declaration in Delphi.  My example assumes STDCALL, but it could be CDECL.  From what I can glean from web searches, your Delphi function declaration might look something like this:

     Function AddIntegers( i1: Integer; i2: Integer ): Integer; stdcall;

where the argument after the return type declares the calling convention.

Hope this helps.

Eric

swaiper

Community Trekker

Joined:

Apr 28, 2015

Thank you, that's very helpful !!

swaiper

Community Trekker

Joined:

Apr 28, 2015

Hi again,

I come back because I can't resolve my problem again with DLLs.

I have try this :

dll_obj = Load DLL("C:\Users\rroustan\Desktop\Delphi\first dll\Win32\Debug\creatorPDF.dll");

dll_obj <<DeclareFunction(

    "CreatePDF",

    Convention(STDCALL),

    Alias( "CreatePDF" ),   

    Arg( AnsiString(254), "title" ),

    Arg( AnsiString(254), "path" ),

    Arg( AnsiString(254), "graphs" ),

    Arg( AnsiString(254), "fileOpen" ),

    Returns( Int32 )

);

rc = dll_obj << CreatePDF("title", "C:\test\", "1;2","file");

Show( result );

dll_obj << UnLoadDLL

or try this :

dll_obj = Load DLL("C:\Users\rroustan\Desktop\Delphi\first dll\Win32\Debug\creatorPDF.dll");

result = dll_obj << CallDLL( "creatorPDF", "c", "title","C:\test\","1;2;3","file" );

But in each case, I have a big failure of JMP :


I don't understand. My DLL works fine with a delphi program. And I'm sure Delphi is using AinsiString.

Hope you can help me, again.

Thanks per advance,

Eric_Hill

Staff

Joined:

Oct 1, 2013

Your JMP Exception could be caused by your use of the Debug build of your DLL with the Release build of JMP (which is the only build available to you).  I would suggest building the Release build of your Delphi DLL and trying that.  If that still fails, and if you are willing to do so, attach both the Debug build and the Release build of your Delphi DLL to this thread.  You may have to start a new thread to be able to attach things; I don't see an "Attach" option for my reply. 

Jeff_Perkinson

Community Manager

Joined:

Jun 23, 2011

When composing your response look for the "Use advanced editor" link in the upper right of the editor box. The Attach option is in the advanced editor.

-Jeff

-Jeff