<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Load .NET dll and call a function in JSL in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Load-NET-dll-and-call-a-function-in-JSL/m-p/716198#M89839</link>
    <description>&lt;P&gt;Hi I am very beginner of JSL and am trying to create a JMP application for our team.&lt;/P&gt;&lt;P&gt;To do this, I realized that I have to load c# dll to the JSL and call a function from there.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have read the part of DLLs in JMP scripting guide but I am not so sure this can be applied for .NET dll.&lt;/P&gt;&lt;P&gt;Does anyone have an experience of loading .NET dll and calling a function from there in the JSL?&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jan 2024 04:38:36 GMT</pubDate>
    <dc:creator>ejesjh</dc:creator>
    <dc:date>2024-01-12T04:38:36Z</dc:date>
    <item>
      <title>Load .NET dll and call a function in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Load-NET-dll-and-call-a-function-in-JSL/m-p/716198#M89839</link>
      <description>&lt;P&gt;Hi I am very beginner of JSL and am trying to create a JMP application for our team.&lt;/P&gt;&lt;P&gt;To do this, I realized that I have to load c# dll to the JSL and call a function from there.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have read the part of DLLs in JMP scripting guide but I am not so sure this can be applied for .NET dll.&lt;/P&gt;&lt;P&gt;Does anyone have an experience of loading .NET dll and calling a function from there in the JSL?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 04:38:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Load-NET-dll-and-call-a-function-in-JSL/m-p/716198#M89839</guid>
      <dc:creator>ejesjh</dc:creator>
      <dc:date>2024-01-12T04:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: Load .NET dll and call a function in JSL</title>
      <link>https://community.jmp.com/t5/Discussions/Load-NET-dll-and-call-a-function-in-JSL/m-p/716386#M89847</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/54237"&gt;@ejesjh&lt;/a&gt;, I'll try to help you out here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first thing to know is that calling from JMP into a .NET DLL (Assembly) is a bit trickier than calling into native DLLs because .NET assemblies do not normally export their entry points.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Internally, JMP uses the &lt;A href="https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress" target="_self"&gt;GetProcAddress&lt;/A&gt;&amp;nbsp;Windows API to locate functions to call. So, the key to having JMP call into your code is having the entry point properly exported.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can recommend two possible approaches you can use to call from JMP into a .NET assembly:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;1. Use one of the publicly-available Nuget packages which allow marking methods so that they are exported. One such package is DllExport (&lt;A href="https://github.com/3F/DllExport" target="_blank" rel="noopener"&gt;https://github.com/3F/DllExport&lt;/A&gt;) Using that particular package requires a bit of extra work as it will modify your csproj file to add the necessary code to enable a [DllExport] attribute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To test this approach, I created a WinForms (.NET Framework) Class Library. First I had to create a&amp;nbsp;&lt;STRONG&gt;x64&amp;nbsp;&lt;/STRONG&gt;configuration as the default&amp;nbsp;&lt;STRONG&gt;AnyCPU&lt;/STRONG&gt;&amp;nbsp;config does not generate a 64-bit DLL. Then, I used the batch file provided with that package to add the DllExport machinery. Then, I exported a method:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;    public static class MyExportedClass
    {
        [DllExport("MyMethod")]
        public static void MyMethod()
        {
            MessageBox.Show("Called into MyMethod");
        }
    }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I built the assembly and finally used the following JSL to call it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;myDLL = LoadDLL("C:\MyLibrary\bin\x64\Debug\MyLibrary.dll");
myDLL &amp;lt;&amp;lt; Declare Function( "MyMethod" );
myDLL &amp;lt;&amp;lt; MyMethod();
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. The other option I can recommend is to create a C++ DLL which is an intermediary between JMP and your C# code. The DLL would export functions for JMP to call and within the DLL, you would call your C# code. To allow C++ code to call into C#, you use the C++/CLI language feature. This means the C++ code is built with the /clr option and references .NET assemblies. You would add a reference to your C# assembly and make calls into your C# code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get started in this direction, I would use Visual Studio and create a new project using the&amp;nbsp;&lt;STRONG&gt;CLR Class Library (.NET Framework)&amp;nbsp;&lt;/STRONG&gt;template. If you get stuck on this approach, post what you've tried and perhaps I can offer more guidance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;John&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jan 2024 15:44:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Load-NET-dll-and-call-a-function-in-JSL/m-p/716386#M89847</guid>
      <dc:creator>jschroedl</dc:creator>
      <dc:date>2024-01-12T15:44:31Z</dc:date>
    </item>
  </channel>
</rss>

