LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can C# dll's be integrated with a LabWindows project?

Solved!
Go to solution

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?

0 Kudos
Message 1 of 16
(6,358 Views)
Solution
Accepted by topic author umquat

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.

--
Martin
Certified CVI Developer
0 Kudos
Message 2 of 16
(6,341 Views)

Thanks Martin.... that makes my life soooo much easier...

0 Kudos
Message 3 of 16
(6,328 Views)

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?

 

0 Kudos
Message 4 of 16
(6,282 Views)

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.

--
Martin
Certified CVI Developer
0 Kudos
Message 5 of 16
(6,278 Views)

Cheers Martin.... Thanks for the input... Hopefully that everything I need

0 Kudos
Message 6 of 16
(6,258 Views)

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

0 Kudos
Message 7 of 16
(6,227 Views)

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

0 Kudos
Message 8 of 16
(6,220 Views)

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.

0 Kudos
Message 9 of 16
(5,427 Views)

but i have one question how can i use use c# (dll file ) in cvi tool

0 Kudos
Message 10 of 16
(5,114 Views)