LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Call Library Function Node not showing Function Names of the .dll created in Visual Studio C#

Solved!
Go to solution

Hi,

I created a simple Visual Studio C# program which is a .dll file. The program is a simple calculator that has four functions, each function accepting two inputs and giving one ouput. As you can imagine the four functions are add, subtract, multiply and subtract. Now I try to use this .dll file in labview using Call Library Function Node but it is not working. The function name is not being showed. Why is that. I have attached the .dll program folder as zip file  and also have put the program below. I have also uploaded screenshots of what is happening in labview. Thank You. 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyMathLibrary
{
public class Calculator
{
public int Add(int a, int b)
{
return a + b;
}
public int Subtract(int a, int b)
{
return a - b;
}
public int Multiply(int a, int b)
{
return a * b;
}
public int Divide(int a, int b)
{
return a / b;
}
}
}

0 Kudos
Message 1 of 4
(2,753 Views)

You’re not creating a normal old style DLL but a .Net assembly here. As such the Call Library Node is useless for this. 

You need to use the .Net nodes in LabVIEW to use this assembly!

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 4
(2,735 Views)

I have used the .net nodes in LabVIEW and it worked, but if you know then can you explain to me or give me any link on how to create a .dll in C# visual studio that can used in Call Library Node of LabVIEW. 

0 Kudos
Message 3 of 4
(2,724 Views)
Solution
Accepted by topic author govindsankar

My first question: Why??

 

But if you really can't control your masochistic desires and want to do that despite the extra pain you will cause yourself with that, you'll need to do something like this for every class method you want to have exported as a global DLL function callable through LoadLibrary()/GetProcAddress(), which is what the Call Library Node does internally.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyMathLibrary
{
    public class Calculator
    {
        [DllExport("Add", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
        public int Add(int a, int b)
        {
            return a + b;
        }
        public int Subtract(int a, int b)
        {
            return a - b;
        }
        public int Multiply(int a, int b)
        {
            return a * b;
        }
        public int Divide(int a, int b)
        {
             return a / b;
        }
    }
}

 

This will still create the actual .Net assembly but also a wrapper function for each exported method that is then exported. While an extra calling level is not a performance shock, you need to be aware of that.

Rolf Kalbermatter
My Blog
Message 4 of 4
(2,715 Views)