03-18-2011 07:48 AM
Hi,
I've integrated C++ dlls into LabWindows projects before, but recently I've been given a C# project that I would like to use instead of deconstructing the source and reconstructing it in C++.
Is there any way of doing this and if so what are the differences between C++ and C# integration? Or am I looking at a minimum of a C++ wrapper?
Solved! Go to Solution.
03-18-2011 11:35 AM - edited 03-18-2011 11:35 AM
CVI can 'easily' interface to .NET assemblies created in C#. The .NET controller wizard (Tools|Create .NET Controller...) can be used to generate the necessary interface code for each assembly.
03-18-2011 04:39 PM
Thanks Martin.... that makes my life soooo much easier...
03-22-2011 06:20 AM
Okay, have made progress but I have a question regarding object destruction.
When I create a link to the C# dll I get a .fp, .c, and .h file which I naturally build into my project
At the top of the .h file are listed the following:
// Global Functions
int CVIFUNC Initialize_TB_USB_Comms(void);
int CVIFUNC Close_TB_USB_Comms(void);
// Type: DipoleRxUSB.USBInterfaceExternal
int CVIFUNC DipoleRxUSB_USBInterfaceExternal__Create(
DipoleRxUSB_USBInterfaceExternal * __instance,
CDotNetHandle * __exception);
I note that there is no Destructor type call to compliment the Create
In the required functionality I call the Initialise_TB_USB routine, then the Create routine - followed by all the other stuff I need to do, and finally the Close routine.
However I know from experiment that this doesnt destroy the object created by the Create routine, as if I come in again I can still access the previously created objects functions.
So how do I go about destroying the instance of the dll I assume I've created. I have put a default constructor and destructor in the C#, but this doesnt seem to have had any effect.
What am I missing?
03-22-2011 07:25 AM
Have you looked at the example CVI code on this page? You need to use CDotNetDiscardHandle() to discard object handles and the relevant Close_... function to close the assembly.
03-23-2011 09:40 AM
Cheers Martin.... Thanks for the input... Hopefully that everything I need
04-04-2011 06:21 AM
Okay, thought I'd finished but I'm not quite there... This is hopefully more straight forward.
The modifications all work really well - on my machine. However when I build my project and transfer it over to a machine that doesnt have the LabWindows environment installed they dont work.
Are there any specific addition dlls required to support the C# stuff, and what am I likely to be missing? The code either crashes or reports the following.
"Could not get CVI .NET error description. A .NET Framework version 1.1 or higher, of the CVI .NET modules may not be installed on your system. If not already present, install the required .NET Framework. Then repair the CVI Runtime Engine installer."
As far as I am aware the machine in question has at least this version and I believe it is probably running 3.5
04-04-2011 08:52 AM
Update...... although if someone can tell me the answer it might make things easier.
Okay a bit of a crude approach, but I've taken all of the CVI related dlls from System32 and copied them into the directory of the program I've written, and that has fixed it. However as I'm quite convinced that most of them probably arent required, I need to thin this down. By trial and error I'll work out what is required.
However if someone already knows what is likely to be missing I'd appreciate the input
10-10-2013 08:55 AM
Try to built the C# project on Release.
I had the same problem with another C++ DLL.
Everytime i tried to access it, a new system32 DLL was requested.
Hope it will help you.
05-29-2014 11:31 PM
but i have one question how can i use use c# (dll file ) in cvi tool