Click here to Skip to main content
15,867,939 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have C# code that initializes a force feedback joystick and plays an effect file(vibrates the joystick). I have turn the console application into library code to make a dll so that I can use it in LabVIEW. I couldn't find anything about how to use that dll in LabVIEW. I just know that I need to use property, constructor, and invoke node. I know someone who can help me how to do it with a dll written with C.

Is it possible to convert C# code into C code? My friend said something about C wrapper. I saw that you can convert C to C++ but I haven't seen C# to C. If you can do this, is it hard to convert it?
Posted
Updated 15-Nov-22 20:13pm
v2

There is no such thing as "convert". Not only the platforms, but the types of platforms are very different, paradigms and many ideas, level, all is different. You can write C# code using C as reference, but the opposite… just forget it, write all from scratch.

—SA
 
Share this answer
 
May I suggest you this approach: "Integrating LabVIEW and C# 1"[^]?
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Mar-15 19:39pm    
Interesting, a 5. In my life, I never met a person who would respect LabVIEW, except non-software people who simply never knew anything else. And the design horrors were apparent immediately.
—SA
Sergey Alexandrovich Kryukov 19-Mar-15 20:30pm    
Please see some other solutions, including my Solution 4. It's very likely that your solution (I just never tried it) make it obsolete.
—SA
Please see my comment to Solution 1.

The idea itself is good, but the false claim (I explain) spoils everything. At the same time, you can create a C# class library and modify it (with outside tool you can build) to export some managed method to unmanaged. This is tricky but can work for you, too.

I found some articles in CodeProject myself, and tried it out. Please see my past reference and find those articles:
How can I use a dll created in Visual Basic 2008 in Visual Basic 6.0[^],
Call Managed DLL written in C# from Unmanged Code VC++[^],
API's in .Net: Managed or UnManaged Code[^].

[EDIT]

After I criticized Solution 1, let me explain what is the rational part of it. The idea is simple: instead of writing your DLL code for LabVIEW (I'm really sorry if you have to :-)) in C, but make it mixed-mode (managed+unmanaged) C++/CLI DLL. You can export unmanaged part and wrap you C# calls in it. As this is also a regular .NET assembly, you can use the assembly written in C# by normal referencing it.

Most likely, this approach would be the easiest for you. This is not counting Solution 3, which might be the very best, but I never tried it.

—SA
 
Share this answer
 
v5
You can call C# code direct from C, with a bit of work: Calling C# .NET methods from unmanaged C/C++ code[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Mar-15 20:08pm    
Sorry, but you bought the claim of the author of the article, which wasn't confirmed. I just down-voted the article and explained why the author is doing something different, not what is claimed. Don't get me wrong: the techniques the author and you suggest are useful, only you should not mislead the readers so badly: in this article, there is no a technique for calling "C# NET methods from unmanaged C/C++ code".

At the same time, it is possible to create C# (VB.NET, F#, not only C++/CLI) code and export some manager methods to unmanaged; there are CodeProject articles offering the technique.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900