Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem when Importing a LabVIEW DLL in Visual Studio.Net, I doesn't see any function of my DLL.

I would like build a LabVIEW DLL and i want to use it in visual studio.net (C#). I have read an NI article which talk on this (see the attach file).

I have follow the directive of the article : I have convert my LabVIEW DLL (version 7.1) into an ASSEMBLY .NET DLL using TlbImp.exe. But when i add a reference to this in visual studio, i doesn't see my function. If i use the Ildasm.exe utility i got the same result.

In the article i read : To use your DLL (COM component) in .NET, the TypeLib of the COM component should be imported into an interop assembly in .NET. This allows managed clients to create instances of the COM type and call its methods, just
as if it were a .NET instance.

So if a use for example, the constructor of the .NET node (in LabVIEW), i must be able to create an instance of the COM objet and then using the method node to see my function. When i use the constructor node, i see the name of the assemby dll, it's revision number but the interface of object is empty and i doesn't see any function.

So i think i must missed something or i do not realise this in a correct manner.

Can someone give me the procedure to do this ?

To test this i have create a simple LabVIEW DLL math.dll(an addition VI) convert it in an assembly DLL (math2.dll) and try to import it in visual C#.

Thanks, Derek
0 Kudos
Message 1 of 13
(7,436 Views)
Hello

The document that you are referencing needs corrections and has been pulled off the web. LV dll's are not COM objects. They are standard unmanaged dll and .NET provides a rich interop framework for this purpose. The KB was referring to how you could use ActiveX controls and servers from .NET, but that would not work for your case.

I have attached a simple example of how you would call a LabVIEW dll from C#. My VI basically takes in 2 doubles and returns the result. I built the VI into a dll ( I used the stdcall calling convention ) with the desired inputs and outputs.

LV's application builder generates a header file along with the dll as well. My function had the following prototype according to the header file.

void __stdcall Test(double y, double x, double *xY);

Then in my C#, I made use of the DllImport attribute to call this function. DllImport is one of the interop features provided by .NET, part of Platform Invoke or (P/Invoke)

So I define the dll function in my C# application in the following manner.

[DllImport("Test.dll"/*name of the dll*/,CallingConvention=CallingConvention.StdCall)]
public static extern void Test /*name of the function*/(double x,double y, ref double xy);

Test.dll is the name of my dll. Test was also the name of the function. And I explicitly specified the calling convention. Now I can call the dll function from my C# application.

So you would need to define each function in the dll that you wish to call in this manner. And in this case, the data types are simpler so passing data around is simpler. But if you start getting into passing LV clusters and arrays, data marshalling ( being able to represent the data type in C# ) becomes complicated.
DllImport has several properties you can set, dependending on the data types you are using.

Hope this helps
I am attaching the project I used. I used LV 7.1 but the VI was just adding 2 numbers.

Hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 2 of 13
(7,436 Views)
Thank you very much Bilal. I got now the information I need.

Thanks, Derek
0 Kudos
Message 3 of 13
(7,439 Views)
>>But if you start getting into passing LV clusters >>and arrays, data marshalling ( being able to >>represent the data type in C# ) becomes complicated.

Even more reason for NI to document it
0 Kudos
Message 4 of 13
(7,439 Views)
I want to transfer arrays from LV to C#. Does someone has experience how the data marshalling in the case works and what I have to do to transfer arrays?
0 Kudos
Message 5 of 13
(6,800 Views)
HI Matthias,

The key to passing an array parameter from LV is that you will need to pass the array as a double array by reference and you will also have to pass the length of the array by value. Although it uses VB.NET syntax, the discussion forum found at http://forums.ni.com/ni/board/message?board.id=170&message.id=93010&requireLogin=False should give you some more information about passing Arrays to .NET. IF you have any additional questions, feel free to repost. Thanks and have a good one.

Adam B.
Applications Engineer
National Instruments
0 Kudos
Message 6 of 13
(6,747 Views)
Is there more required to specify input and output parameters that should show up on the method call than to set them as terminals on the connector? I have three required inputs (one floating point and two arrays of IMAQPoint) and one output (Line Segment result of IMAQ Fit Line). I keep getting void __stdcall FindMidline(void) in the generated .h file.

-Matthew
0 Kudos
Message 7 of 13
(7,101 Views)
Hi MatthewB

Try posting this question on the LabVIEW forum, since it looks like you're having problems building a VI to a DLL with the correct prototype.
Bilal Durrani
NI
0 Kudos
Message 8 of 13
(7,078 Views)

Yes, it turns out that the problem was with how LabVIEW build of the dll was working and I had to add parameters for the terminals.  I've also defined the terminals as .Net Objects that are converted to variants and then on to the appropriate structures within LabVIEW for processing.  However, LabVIEW now defines the function prototype with variables of type "LVRefNum *".  Can you offer any guidance on what the equivalent .Net data type would be?  Do I set up the extern method definition as though the areguments are of type object?

-Matthew

0 Kudos
Message 9 of 13
(7,073 Views)

Hi Matthew,

I would suggest starting with DF: How can I calling LabView DLL within LabView and pass similar Data Types? for some information on LVRefNum.

In addition I would recommend looking at example program: Using VB.NET to Call LabVIEW DLLs That Use 2D Numeric Arrays

Finally, please provide more information on your application so I can reply on those lines.

Regards,
Ankita

0 Kudos
Message 10 of 13
(7,040 Views)