LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in calling C# dll

Solved!
Go to solution

Hi,

 

I'm new to C# but I have to write dll for LabVIEW that reads information about windows processes. I've prepared code (working as Win32 application), built it as dll and used Call Library Function to call it. I've tried another C-language code before and it worked fine. But when I do the same with C#, I have an error in LabVIEW:

"The function name specified for this node cannot be found in the library. Right-click the Call Library Function node and select Configure, then choose the correct function name."

 

The function I've created (I've pasted it below this post) has proper function but LabVIEW does not see it. Do you have any idea how to fix it? I couldn't find any tutorial for C# and LabVIEW, I saw some for C# and I it should work.

 

Best regards,

Piotr

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Xml.Linq;

namespace GetProcessDataLib
{
public class ProcessData
{

public static String GetProcessDataFunction(out string result)
{
String xmlOutput = "";
try
{
//sample code
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace + "\r\n" + ex.Source);


xmlOutput = "";

}
result = xmlOutput;
GetProcessDataFunction(out result);

return xmlOutput;


}

}
}

0 Kudos
Message 1 of 10
(9,473 Views)

Are you sure you built this as a standard DLL, and not a C# assembly? They both use the .dll extension, but you can't call a C# assembly the same way. Instead, you need to use the functions on the .NET palette - Constructor, Property Node, Invoke Node.

0 Kudos
Message 2 of 10
(9,460 Views)

Hi Nathan,

Thanks for replying. I'm new to C#... I'm not sure 🙂 I've tried to:

 

1/ create dll with Visual Studio Command Prompt (both 32 and 64). I used this command:

csc /target:library /out:GetProcessDataLib64.DLL GetProcessData.cs

 

2/ take dll that was automatically create during build.

0 Kudos
Message 3 of 10
(9,441 Views)
What functions do appear in the drop down list when you select your dll in the call library function node configuration dialog?
0 Kudos
Message 4 of 10
(9,422 Views)

Any functions appears. Only this default "funcName". I cannot see implemented functions. Maybe there's sth wrong with this:

 

-----

public static String GetProcessDataFunction(out string result)

GetProcessDataFunction(out result);

return xmlOutput;

-----

 

 

or I have to change way of creating this dll in Visual Studio.

0 Kudos
Message 5 of 10
(9,413 Views)
Have you tried using the .NET functions instead?

Does building the DLL also generate a header file (.h)?
0 Kudos
Message 6 of 10
(9,400 Views)
Solution
Accepted by topic author Piotr.Zawistowski

@Piotr.Zawistowski wrote:

Hi Nathan,

Thanks for replying. I'm new to C#... I'm not sure 🙂 I've tried to:

 

1/ create dll with Visual Studio Command Prompt (both 32 and 64). I used this command:

csc /target:library /out:GetProcessDataLib64.DLL GetProcessData.cs

 

2/ take dll that was automatically create during build.


csc is the C Sharp compiler and will create a .Net assembly by default, not a Windows function DLL. So you need to use the .Net functions in LabVIEW to access it. And anyhow from that source code you cannot directly create a Windows function DLL since there are no exportable functions in there, but only .Net objects.

 

And Nathan, C(++/#) compilers don't create header files for DLLs. Those header files have to be created by the programmer creating the DLL source code.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 7 of 10
(9,375 Views)
Thanks Rolf, about the header file - I knew that but was not really awake when I posted. I should probably not post to the forum just after being woken in the middle of the night.
0 Kudos
Message 8 of 10
(9,369 Views)

Or at least get a coffee first Smiley Very Happy

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 9 of 10
(9,365 Views)

Thanks all for help!

 

What I had to do, was follow this instruction:

 

If the DLL is a .NET assembly:

  1. In order to use a .NET assembly in LabVIEW, simply use the .NET palette (Connectivity».NET) to find all of the functions available.
  2. First use a constructor node in order to instantiate a class within the .NET assembly.
  3. Use property nodes and invoke nodes to access properties and methods of the class by simply wiring in the class reference from the constructor node to the property or invoke node.

http://digital.ni.com/public.nsf/allkb/DCB90714981A1F148625731E00797C33

 

And it works. Thx!

0 Kudos
Message 10 of 10
(9,349 Views)