03-14-2012 11:45 AM
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
03-14-2012 12:09 PM
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.
03-14-2012 03:36 PM
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.
03-15-2012 11:01 AM
Any hints ??
03-15-2012 12:16 PM
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#?
03-16-2012 03:57 AM
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.
03-16-2012 10:01 AM
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.
03-17-2012 11:00 AM
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:
Also attached is the C# project, written in Visual Studio 2010.
Note that this example is for demonstration to get you started.
07-12-2012 07:08 PM
This example worked fine for me - and helped a lot.
Thanks.
07-16-2012 03:52 PM
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.