From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Call dll (a simple gui for user) from c#

Hi,

 

In order to feed my solvers (written in C#) with some data (string, int, double in array format), I wrote a simple VI where provide the user possibility to enter the data (simply by entering the values). (Tabcontrol with arrays filled in with default values, and connected to SV). Here is the catch: I am facing very difficulties to call the built dll correctly into c#. The flow should be like calling the dll, get the value, store in the SV and feed it into the c# code as vectors and matrices (the bridge in the middle is missing). I searched net for some codes, but could not find any simple sample to do so. Maybe, here is not a best place to post this question, but HAS anyone wrote a class in c# to call a dll file? Hint and tips are appreciated.

 

Rgds,

David

0 Kudos
Message 1 of 14
(10,318 Views)

Are you not sure how to call a DLL in C# in general, or are you having a problem with this specific DLL? If the latter, what specific difficulty are you having calling the DLL? Is your program crashing? Are you not sure what datatypes to use on the C# side? I'm assuming that by "SV" you are referring to a shared variable? If so, are you trying to use this to pass the data between LabVIEW and C#? I'm not understanding what the shared variable (if that's what it is) is being used for. 

0 Kudos
Message 2 of 14
(10,312 Views)

Sorry for not explaining the details.

I tried to use abstract classes and dllimport in c# without much successand too much error while building a solution. would be nice to have some general info 🙂

Also, I'm not sure what data type to use in c# ;), Regarding the shared variables (SV), yes, this was also one solution that hit my mind.

All the comments are appreciated.

0 Kudos
Message 3 of 14
(10,301 Views)

Any hints ??

0 Kudos
Message 4 of 14
(10,282 Views)

Well, I don't quite understand why you're trying to create an abstract class. You can't instantiate abstract classes. Have you looked at basic examples on calling DLLs from C#?

0 Kudos
Message 5 of 14
(10,276 Views)

Well i tired several solution that I could get from examples on the net including abastract classes. In addition, I used also DllImport with extern command, no go!, I guess I'm missing some important peice. As I said the goal is to pass the data (some matrices) provided by user in the LV app. to the c# app, however the c# app sould call and bring up the LV app first.

0 Kudos
Message 6 of 14
(10,263 Views)

I had posted an example of calling a LabVIEW DLL that displays a dialog a few weeks ago. I've made a modification to include an exported VI to get the waveform data. Unfortunately, the forum's attachment system is not working at the moment. It's been broken since yesterday. When it gets fixed I will upload the modified example.

0 Kudos
Message 7 of 14
(10,248 Views)

The problem with attachments is still going on, so I have no idea if this will work. If the attachments show up as 1K files then the system is still not handling attachments properly. Attached is a modification of an example I had posted a short time ago. The example calls a LabVIEW DLL that opens a dialog that generates a waveform. There are 3 functions in the DLL:

  1. Launch dialog
  2. Set parameters
  3. Get data <-- what I added for this example

Also attached is the C# project, written in Visual Studio 2010.

 

Note that this example is for demonstration to get you started.

Download All
Message 8 of 14
(10,240 Views)

This example worked fine for me - and helped a lot.
Thanks.

0 Kudos
Message 9 of 14
(9,994 Views)

While I haven't tried to create .Net assemblies in LabVIEW yet, and also don't know if they can show UIs themselves, it would seem like a try worth to check out. Creating DLLs in LabVIEW to be called as unmanaged code in .Net is certainly possible, but rather troublesome, if you can create .Net assemblies in LabVIEW too, which I know is possible. Calling them will be a lot easier as they do not require any unmanaged interfacing, since LabVIEW is doing all the .Net managed interface to LabVIEW managed interface for you.

Rolf Kalbermatter
My Blog
0 Kudos
Message 10 of 14
(9,970 Views)